perf: improve gateway startup diagnostics

This commit is contained in:
Peter Steinberger
2026-04-28 01:47:52 +01:00
parent 13d3777cf3
commit 75e126ef6a
7 changed files with 144 additions and 44 deletions

View File

@@ -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);

View File

@@ -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);