Skip to content

Commit 10c0858

Browse files
committed
Add logging to explore startup delays
1 parent f4f11e5 commit 10c0858

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ if (!amMainInstance) {
139139
app.quit();
140140
} else {
141141
const logStream = createWriteStream(LAST_RUN_LOG_PATH);
142-
logStream.write(`--- Launching HTTP Toolkit desktop v${DESKTOP_VERSION} ---\n`);
142+
logStream.write(`--- Launching HTTP Toolkit desktop v${DESKTOP_VERSION} at ${new Date().toISOString()} ---\n`);
143143

144144
const args = yargs
145145
.option('with-forwarding', {
@@ -361,6 +361,8 @@ if (!amMainInstance) {
361361
console.log('All server versions installed are outdated, deleting');
362362
await rmRF(serverUpdatesPath);
363363
}
364+
365+
logStream.write('Server cleanup check completed\n');
364366
}
365367

366368
// When run *before* the server starts, this allows us to check whether the port is already in use,
@@ -381,11 +383,13 @@ if (!amMainInstance) {
381383
delay(100)
382384
])
383385
.finally(() => {
386+
logStream.write('Port check completed\n');
384387
conn.destroy();
385388
});
386389
}
387390

388391
async function startServer(retries = 2) {
392+
logStream.write('Starting server\n');
389393
const binName = isWindows ? 'httptoolkit-server.cmd' : 'httptoolkit-server';
390394
const serverBinPath = path.join(RESOURCES_PATH, 'httptoolkit-server', 'bin', binName);
391395
const serverBinCommand = isWindows ? `"${serverBinPath}"` : serverBinPath;
@@ -423,7 +427,15 @@ if (!amMainInstance) {
423427
serverStdout.pipe(logStream);
424428
serverStderr.pipe(logStream);
425429

430+
const startTime = Date.now();
431+
let seenOutput = false;
426432
server.stdout!.on('data', (data) => {
433+
// Server always produces output immediately, which works nicely to detect actual start time (and
434+
// any issues due to AV scans or similar).
435+
if (!seenOutput) {
436+
seenOutput = true;
437+
console.log(`Server took ${Date.now() - startTime}ms to begin startup`);
438+
}
427439
addBreadcrumb({ category: 'server-stdout', message: data.toString('utf8'), level: <any>'info' });
428440
});
429441

0 commit comments

Comments
 (0)