mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:20:42 +00:00
perf: improve gateway startup diagnostics
This commit is contained in:
@@ -480,6 +480,10 @@ function collectStartupTrace(line: string, startupTrace: Record<string, number>)
|
||||
}
|
||||
}
|
||||
|
||||
function hasGatewayReadyLog(line: string): boolean {
|
||||
return /\[gateway\] (?:http server listening|ready \()/.test(line);
|
||||
}
|
||||
|
||||
function parseStartupTraceMetrics(raw: string): Array<{ key: string; value: number }> {
|
||||
const metrics: Array<{ key: string; value: number }> = [];
|
||||
for (const part of raw.trim().split(/\s+/u)) {
|
||||
@@ -576,7 +580,7 @@ async function runGatewaySample(options: {
|
||||
output.splice(0, output.length - 20);
|
||||
}
|
||||
for (const line of text.split(/\r?\n/u)) {
|
||||
if (line.includes("ready (") && readyLogMs == null) {
|
||||
if (hasGatewayReadyLog(line) && readyLogMs == null) {
|
||||
readyLogMs = performance.now() - startAt;
|
||||
}
|
||||
collectStartupTrace(line, startupTrace);
|
||||
|
||||
@@ -352,10 +352,14 @@ function readProcessTreeCpuMs(rootPid) {
|
||||
return totalCpuMs;
|
||||
}
|
||||
|
||||
export function hasGatewayReadyLog(text) {
|
||||
return /\[gateway\] (?:http server listening|ready \()/.test(text);
|
||||
}
|
||||
|
||||
async function waitForGatewayReady(readText, timeoutMs) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
while (Date.now() < deadline) {
|
||||
if (/\[gateway\] ready \(/.test(readText())) {
|
||||
if (hasGatewayReadyLog(readText())) {
|
||||
return true;
|
||||
}
|
||||
await sleep(100);
|
||||
|
||||
Reference in New Issue
Block a user