History

Clean up perf run dirs and cover collector reset

- Persist and remove the seeded run parent directory after perf runs - Add regression coverage for seed cleanup, percentile clamping, and RAF reset

Julius Marminge committed 7 months ago

Commit 062c8091 parent b8fba1810 files · +260 −436Browse files

Showing the changes to scripts (1 of 10 files). Show all

Unified · Split

scripts/open-perf-app.ts+23−10
@@ -1,6 +1,6 @@
11 import { spawn, type ChildProcess } from "node:child_process";
22 import { once } from "node:events";
3−import { access } from "node:fs/promises";
3+import { access, rm } from "node:fs/promises";
44 import { createServer } from "node:net";
55 import { resolve } from "node:path";
66 import { fileURLToPath } from "node:url";
@@ -27,6 +27,7 @@ interface PerfSeedThreadSummary { · 20 unmodified lines
2727
2828 interface PerfSeededState {
2929 readonly scenarioId: PerfSeedScenarioId;
30+ readonly runParentDir: string;
3031 readonly baseDir: string;
3132 readonly workspaceRoot: string;
3233 readonly projectTitle: string | null;
@@ -252,6 +253,10 @@ async function stopChildProcess(process: ChildProcess): Promise<void> { · 219 unmodified lines
252253 }
253254 }
254255
256+async function cleanupPerfRunDir(runParentDir: string): Promise<void> {
257+ await rm(runParentDir, { recursive: true, force: true });
258+}
259+
255260 function openUrl(url: string): void {
256261 const command: [string, ...string[]] =
257262 process.platform === "darwin"
@@ -339,6 +344,7 @@ async function main(): Promise<void> { · 81 unmodified lines
339344 shuttingDown = true;
340345 process.stdout.write(`\nReceived ${signal}. Stopping perf app...\n`);
341346 await stopChildProcess(serverProcess);
347+ await cleanupPerfRunDir(seededState.runParentDir);
342348 process.exit(0);
343349 };
344350
@@ -349,17 +355,24 @@ async function main(): Promise<void> { · 4 unmodified lines
349355 void shutdown("SIGTERM");
350356 });
351357
352− const url = `http://${options.host}:${port.toString()}`;
353− await waitForServerReady(url, serverProcess);
354− printSeedSummary(seededState, url, options.providerScenarioId);
358+ try {
359+ const url = `http://${options.host}:${port.toString()}`;
360+ await waitForServerReady(url, serverProcess);
361+ printSeedSummary(seededState, url, options.providerScenarioId);
355362
356− if (options.openBrowser) {
357− openUrl(url);
358− }
363+ if (options.openBrowser) {
364+ openUrl(url);
365+ }
359366
360− const [exitCode] = (await once(serverProcess, "exit")) as [number | null];
361− if (!shuttingDown) {
362− process.exit(exitCode ?? 0);
367+ const [exitCode] = (await once(serverProcess, "exit")) as [number | null];
368+ if (!shuttingDown) {
369+ await cleanupPerfRunDir(seededState.runParentDir);
370+ process.exit(exitCode ?? 0);
371+ }
372+ } catch (error) {
373+ await stopChildProcess(serverProcess);
374+ await cleanupPerfRunDir(seededState.runParentDir);
375+ throw error;
363376 }
364377 }
365378