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
This commit is contained in:
1 parent
b8fba18575
commit
062c809aa0
10 files changed
+256
-432
No files matched your search
@@ -7,20 +7,23 @@ import { PERF_CATALOG_IDS } from "@t3tools/shared/perf/scenarioCatalog";
|
||||
import { seedPerfState } from "./seedPerfState.ts";
|
||||
|
||||
describe("seedPerfState", () => {
|
||||
const baseDirsToCleanup: string[] = [];
|
||||
const runParentDirsToCleanup: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
baseDirsToCleanup.splice(0).map((baseDir) => rm(baseDir, { recursive: true, force: true })),
|
||||
runParentDirsToCleanup
|
||||
.splice(0)
|
||||
.map((runParentDir) => rm(runParentDir, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
it("seeds large thread fixtures through the real event store and projection pipeline", async () => {
|
||||
const seeded = await seedPerfState("large_threads");
|
||||
baseDirsToCleanup.push(seeded.baseDir);
|
||||
runParentDirsToCleanup.push(seeded.runParentDir);
|
||||
|
||||
expect(seeded.snapshot.projects).toHaveLength(1);
|
||||
expect(seeded.snapshot.threads).toHaveLength(12);
|
||||
expect(seeded.baseDir).toBe(join(seeded.runParentDir, "base"));
|
||||
|
||||
const heavyThread = seeded.snapshot.threads.find(
|
||||
(thread) => thread.id === PERF_CATALOG_IDS.largeThreads.heavyAThreadId,
|
||||
@@ -34,7 +37,7 @@ describe("seedPerfState", () => {
|
||||
|
||||
it("enables assistant streaming in the burst base seed for websocket perf runs", async () => {
|
||||
const seeded = await seedPerfState("burst_base");
|
||||
baseDirsToCleanup.push(seeded.baseDir);
|
||||
runParentDirsToCleanup.push(seeded.runParentDir);
|
||||
|
||||
const rawSettings = await readFile(join(seeded.baseDir, "userdata/settings.json"), "utf8");
|
||||
expect(JSON.parse(rawSettings)).toMatchObject({
|
||||
|
||||
@@ -34,6 +34,7 @@ import { ServerSettingsService, ServerSettingsLive } from "../../src/serverSetti
|
||||
|
||||
export interface PerfSeededState {
|
||||
readonly scenarioId: PerfSeedScenarioId;
|
||||
readonly runParentDir: string;
|
||||
readonly baseDir: string;
|
||||
readonly workspaceRoot: string;
|
||||
readonly snapshot: OrchestrationReadModel;
|
||||
@@ -489,6 +490,7 @@ export async function seedPerfState(scenarioId: PerfSeedScenarioId): Promise<Per
|
||||
|
||||
return {
|
||||
scenarioId,
|
||||
runParentDir,
|
||||
baseDir,
|
||||
workspaceRoot,
|
||||
snapshot,
|
||||
|
||||
@@ -13,6 +13,7 @@ const seeded = await seedPerfState(scenarioId);
|
||||
const payload = JSON.stringify(
|
||||
{
|
||||
scenarioId: seeded.scenarioId,
|
||||
runParentDir: seeded.runParentDir,
|
||||
baseDir: seeded.baseDir,
|
||||
workspaceRoot: seeded.workspaceRoot,
|
||||
projectTitle: seeded.snapshot.projects[0]?.title ?? null,
|
||||
|
||||
+162
-134
@@ -1,11 +1,11 @@
|
||||
import { spawn, type ChildProcess } from "node:child_process";
|
||||
import { access, mkdir, writeFile } from "node:fs/promises";
|
||||
import { access, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { createServer } from "node:net";
|
||||
import { join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { once } from "node:events";
|
||||
|
||||
import { chromium, type Page } from "playwright";
|
||||
import { chromium, type Browser, type BrowserContext, type Page } from "playwright";
|
||||
|
||||
import {
|
||||
type BrowserPerfMetrics,
|
||||
@@ -50,6 +50,7 @@ interface PerfSeedThreadSummary {
|
||||
|
||||
export interface PerfSeededState {
|
||||
readonly scenarioId: PerfSeedScenarioId;
|
||||
readonly runParentDir: string;
|
||||
readonly baseDir: string;
|
||||
readonly workspaceRoot: string;
|
||||
readonly projectTitle: string | null;
|
||||
@@ -181,6 +182,10 @@ async function ensureArtifactDir(suite: string, scenarioId: string): Promise<str
|
||||
return artifactDir;
|
||||
}
|
||||
|
||||
async function cleanupPerfRunDir(runParentDir: string): Promise<void> {
|
||||
await rm(runParentDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
async function writeServerLogs(
|
||||
artifactDir: string,
|
||||
stdout: string,
|
||||
@@ -295,151 +300,174 @@ export async function startPerfAppHarness(
|
||||
serverProcess.stderr?.on("data", (chunk) => {
|
||||
stderrBuffer += chunk.toString();
|
||||
});
|
||||
let browser: Browser | null = null;
|
||||
let context: BrowserContext | null = null;
|
||||
let page: Page | null = null;
|
||||
|
||||
await waitForServerReady(url, serverProcess);
|
||||
try {
|
||||
await waitForServerReady(url, serverProcess);
|
||||
|
||||
const browser = await chromium.launch({
|
||||
headless: process.env[PERF_HEADFUL_ENV] !== "1",
|
||||
});
|
||||
const context = await browser.newContext({
|
||||
viewport: { width: 1440, height: 960 },
|
||||
});
|
||||
await context.addInitScript(installBrowserPerfCollector, "[data-timeline-row-kind]");
|
||||
const page = await context.newPage();
|
||||
await page.goto(url, { waitUntil: "domcontentloaded" });
|
||||
browser = await chromium.launch({
|
||||
headless: process.env[PERF_HEADFUL_ENV] !== "1",
|
||||
});
|
||||
context = await browser.newContext({
|
||||
viewport: { width: 1440, height: 960 },
|
||||
});
|
||||
await context.addInitScript(installBrowserPerfCollector, "[data-timeline-row-kind]");
|
||||
page = await context.newPage();
|
||||
await page.goto(url, { waitUntil: "domcontentloaded" });
|
||||
|
||||
const firstProjectTitle =
|
||||
seededState.projectTitle ?? getPerfSeedScenario(options.seedScenarioId).project.title;
|
||||
if (!firstProjectTitle) {
|
||||
throw new Error(`Seed scenario '${options.seedScenarioId}' produced no projects.`);
|
||||
}
|
||||
await page.getByText(firstProjectTitle, { exact: true }).first().waitFor({ timeout: 45_000 });
|
||||
const firstProjectTitle =
|
||||
seededState.projectTitle ?? getPerfSeedScenario(options.seedScenarioId).project.title;
|
||||
if (!firstProjectTitle) {
|
||||
throw new Error(`Seed scenario '${options.seedScenarioId}' produced no projects.`);
|
||||
}
|
||||
await page.getByText(firstProjectTitle, { exact: true }).first().waitFor({ timeout: 45_000 });
|
||||
|
||||
const sampler = options.serverSampler ?? new NoopServerSampler();
|
||||
if (serverProcess.pid) {
|
||||
await sampler.start({ pid: serverProcess.pid });
|
||||
}
|
||||
const runStartedAt = new Date().toISOString();
|
||||
const sampler = options.serverSampler ?? new NoopServerSampler();
|
||||
if (serverProcess.pid) {
|
||||
await sampler.start({ pid: serverProcess.pid });
|
||||
}
|
||||
const runStartedAt = new Date().toISOString();
|
||||
const readyPage = page;
|
||||
if (!readyPage) {
|
||||
throw new Error("Perf app harness did not initialize a browser page.");
|
||||
}
|
||||
|
||||
let finishPromise: Promise<{
|
||||
readonly artifactPath: string;
|
||||
readonly artifact: PerfRunArtifact;
|
||||
readonly browserMetrics: BrowserPerfMetrics;
|
||||
readonly serverMetrics: ReadonlyArray<PerfServerMetricSample> | null;
|
||||
}> | null = null;
|
||||
let finishPromise:
|
||||
| Promise<{
|
||||
readonly artifactPath: string;
|
||||
readonly artifact: PerfRunArtifact;
|
||||
readonly browserMetrics: BrowserPerfMetrics;
|
||||
readonly serverMetrics: ReadonlyArray<PerfServerMetricSample> | null;
|
||||
}>
|
||||
| undefined;
|
||||
|
||||
const teardown = async () => {
|
||||
await Promise.allSettled([context.close(), browser.close()]);
|
||||
await stopChildProcess(serverProcess);
|
||||
};
|
||||
const teardown = async () => {
|
||||
await Promise.allSettled([
|
||||
context ? context.close() : Promise.resolve(),
|
||||
browser ? browser.close() : Promise.resolve(),
|
||||
]);
|
||||
await stopChildProcess(serverProcess);
|
||||
await cleanupPerfRunDir(seededState.runParentDir);
|
||||
};
|
||||
|
||||
return {
|
||||
seededState,
|
||||
page,
|
||||
url,
|
||||
artifactDir,
|
||||
startAction: (name) =>
|
||||
invokeBrowserCollector(
|
||||
page,
|
||||
(collectorName, actionName) => {
|
||||
(window as Window & Record<string, any>)[collectorName]?.startAction(
|
||||
actionName as string,
|
||||
);
|
||||
},
|
||||
name,
|
||||
),
|
||||
endAction: (name) =>
|
||||
invokeBrowserCollector(
|
||||
page,
|
||||
(collectorName, actionName) => {
|
||||
return (
|
||||
(window as Window & Record<string, any>)[collectorName]?.endAction(
|
||||
return {
|
||||
seededState,
|
||||
page: readyPage,
|
||||
url,
|
||||
artifactDir,
|
||||
startAction: (name) =>
|
||||
invokeBrowserCollector(
|
||||
readyPage,
|
||||
(collectorName, actionName) => {
|
||||
(window as Window & Record<string, any>)[collectorName]?.startAction(
|
||||
actionName as string,
|
||||
) ?? null
|
||||
);
|
||||
},
|
||||
name,
|
||||
),
|
||||
resetBrowserMetrics: () =>
|
||||
invokeBrowserCollector(page, (collectorName) => {
|
||||
(window as Window & Record<string, any>)[collectorName]?.reset();
|
||||
}),
|
||||
sampleMountedRows: (label) =>
|
||||
invokeBrowserCollector(
|
||||
page,
|
||||
(collectorName, sampleLabel) => {
|
||||
return (
|
||||
(window as Window & Record<string, any>)[collectorName]?.sampleMountedRows(
|
||||
sampleLabel as string,
|
||||
) ?? 0
|
||||
);
|
||||
},
|
||||
label,
|
||||
),
|
||||
snapshotBrowserMetrics: () =>
|
||||
invokeBrowserCollector(page, (collectorName) => {
|
||||
return ((window as Window & Record<string, any>)[collectorName]?.snapshot() ?? {
|
||||
actions: [],
|
||||
longTasks: [],
|
||||
rafGapsMs: [],
|
||||
mountedRowSamples: [],
|
||||
}) as BrowserPerfMetrics;
|
||||
}),
|
||||
finishRun: async (finishOptions) => {
|
||||
if (finishPromise) {
|
||||
return await finishPromise;
|
||||
}
|
||||
);
|
||||
},
|
||||
name,
|
||||
),
|
||||
endAction: (name) =>
|
||||
invokeBrowserCollector(
|
||||
readyPage,
|
||||
(collectorName, actionName) => {
|
||||
return (
|
||||
(window as Window & Record<string, any>)[collectorName]?.endAction(
|
||||
actionName as string,
|
||||
) ?? null
|
||||
);
|
||||
},
|
||||
name,
|
||||
),
|
||||
resetBrowserMetrics: () =>
|
||||
invokeBrowserCollector(readyPage, (collectorName) => {
|
||||
(window as Window & Record<string, any>)[collectorName]?.reset();
|
||||
}),
|
||||
sampleMountedRows: (label) =>
|
||||
invokeBrowserCollector(
|
||||
readyPage,
|
||||
(collectorName, sampleLabel) => {
|
||||
return (
|
||||
(window as Window & Record<string, any>)[collectorName]?.sampleMountedRows(
|
||||
sampleLabel as string,
|
||||
) ?? 0
|
||||
);
|
||||
},
|
||||
label,
|
||||
),
|
||||
snapshotBrowserMetrics: () =>
|
||||
invokeBrowserCollector(readyPage, (collectorName) => {
|
||||
return ((window as Window & Record<string, any>)[collectorName]?.snapshot() ?? {
|
||||
actions: [],
|
||||
longTasks: [],
|
||||
rafGapsMs: [],
|
||||
mountedRowSamples: [],
|
||||
}) as BrowserPerfMetrics;
|
||||
}),
|
||||
finishRun: async (finishOptions) => {
|
||||
if (finishPromise) {
|
||||
return await finishPromise;
|
||||
}
|
||||
|
||||
finishPromise = (async () => {
|
||||
const completedAt = new Date().toISOString();
|
||||
const browserMetrics = await (async () => {
|
||||
try {
|
||||
return await invokeBrowserCollector(page, (collectorName) => {
|
||||
return ((window as Window & Record<string, any>)[collectorName]?.snapshot() ?? {
|
||||
finishPromise = (async () => {
|
||||
const completedAt = new Date().toISOString();
|
||||
const browserMetrics: BrowserPerfMetrics = await (async () => {
|
||||
try {
|
||||
return await invokeBrowserCollector(readyPage, (collectorName) => {
|
||||
return ((window as Window & Record<string, any>)[collectorName]?.snapshot() ?? {
|
||||
actions: [],
|
||||
longTasks: [],
|
||||
rafGapsMs: [],
|
||||
mountedRowSamples: [],
|
||||
}) as BrowserPerfMetrics;
|
||||
});
|
||||
} catch {
|
||||
return {
|
||||
actions: [],
|
||||
longTasks: [],
|
||||
rafGapsMs: [],
|
||||
mountedRowSamples: [],
|
||||
}) as BrowserPerfMetrics;
|
||||
});
|
||||
} catch {
|
||||
return {
|
||||
actions: [],
|
||||
longTasks: [],
|
||||
rafGapsMs: [],
|
||||
mountedRowSamples: [],
|
||||
} satisfies BrowserPerfMetrics;
|
||||
}
|
||||
} satisfies BrowserPerfMetrics;
|
||||
}
|
||||
})();
|
||||
const serverMetrics = await sampler.stop();
|
||||
await teardown();
|
||||
|
||||
const basename =
|
||||
finishOptions.artifactBasename ?? `${finishOptions.suite}-${finishOptions.scenarioId}`;
|
||||
await writeServerLogs(artifactDir, stdoutBuffer, stderrBuffer, basename);
|
||||
const artifact: PerfRunArtifact = {
|
||||
suite: finishOptions.suite,
|
||||
scenarioId: finishOptions.scenarioId,
|
||||
startedAt: runStartedAt,
|
||||
completedAt,
|
||||
thresholds: finishOptions.thresholds,
|
||||
summary: summarizeBrowserPerfMetrics(browserMetrics, finishOptions.actionSummary),
|
||||
browserMetrics,
|
||||
serverMetrics,
|
||||
...(finishOptions.metadata ? { metadata: finishOptions.metadata } : {}),
|
||||
};
|
||||
const artifactPath = join(artifactDir, `${basename}.json`);
|
||||
await writePerfArtifact(artifactPath, artifact);
|
||||
|
||||
return {
|
||||
artifactPath,
|
||||
artifact,
|
||||
browserMetrics,
|
||||
serverMetrics,
|
||||
};
|
||||
})();
|
||||
const serverMetrics = await sampler.stop();
|
||||
await teardown();
|
||||
|
||||
const basename =
|
||||
finishOptions.artifactBasename ?? `${finishOptions.suite}-${finishOptions.scenarioId}`;
|
||||
await writeServerLogs(artifactDir, stdoutBuffer, stderrBuffer, basename);
|
||||
const artifact: PerfRunArtifact = {
|
||||
suite: finishOptions.suite,
|
||||
scenarioId: finishOptions.scenarioId,
|
||||
startedAt: runStartedAt,
|
||||
completedAt,
|
||||
thresholds: finishOptions.thresholds,
|
||||
summary: summarizeBrowserPerfMetrics(browserMetrics, finishOptions.actionSummary),
|
||||
browserMetrics,
|
||||
serverMetrics,
|
||||
...(finishOptions.metadata ? { metadata: finishOptions.metadata } : {}),
|
||||
};
|
||||
const artifactPath = join(artifactDir, `${basename}.json`);
|
||||
await writePerfArtifact(artifactPath, artifact);
|
||||
|
||||
return {
|
||||
artifactPath,
|
||||
artifact,
|
||||
browserMetrics,
|
||||
serverMetrics,
|
||||
};
|
||||
})();
|
||||
|
||||
return await finishPromise;
|
||||
},
|
||||
};
|
||||
return await finishPromise;
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
await Promise.allSettled([
|
||||
context ? context.close() : Promise.resolve(),
|
||||
browser ? browser.close() : Promise.resolve(),
|
||||
]);
|
||||
await stopChildProcess(serverProcess);
|
||||
await cleanupPerfRunDir(seededState.runParentDir);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { percentile } from "../../../../test/perf/support/artifact";
|
||||
import { installBrowserPerfCollector } from "../../../../test/perf/support/browserMetrics";
|
||||
|
||||
describe("percentile", () => {
|
||||
it("returns the minimum value for the zero percentile", () => {
|
||||
expect(percentile([9, 3, 6], 0)).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("installBrowserPerfCollector", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("cancels the previous animation frame loop before reset starts a new one", () => {
|
||||
let nextHandle = 1;
|
||||
const callbacks = new Map<number, FrameRequestCallback>();
|
||||
const requestAnimationFrame = vi.fn((callback: FrameRequestCallback) => {
|
||||
const handle = nextHandle++;
|
||||
callbacks.set(handle, callback);
|
||||
return handle;
|
||||
});
|
||||
const cancelAnimationFrame = vi.fn((handle: number) => {
|
||||
callbacks.delete(handle);
|
||||
});
|
||||
|
||||
vi.stubGlobal("window", {
|
||||
requestAnimationFrame,
|
||||
cancelAnimationFrame,
|
||||
} as unknown as Window & typeof globalThis);
|
||||
vi.stubGlobal("document", {
|
||||
querySelectorAll: vi.fn(() => []),
|
||||
} as unknown as Document);
|
||||
vi.stubGlobal("PerformanceObserver", undefined);
|
||||
|
||||
installBrowserPerfCollector();
|
||||
|
||||
const collector = window.__t3PerfCollector;
|
||||
expect(collector).toBeDefined();
|
||||
expect(requestAnimationFrame).toHaveBeenCalledTimes(1);
|
||||
|
||||
collector?.reset();
|
||||
expect(cancelAnimationFrame).toHaveBeenCalledWith(1);
|
||||
expect(requestAnimationFrame).toHaveBeenCalledTimes(2);
|
||||
|
||||
collector?.reset();
|
||||
expect(cancelAnimationFrame).toHaveBeenLastCalledWith(2);
|
||||
expect(requestAnimationFrame).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
-141
@@ -1,141 +0,0 @@
|
||||
{
|
||||
"suite": "virtualization",
|
||||
"scenarioId": "large_threads",
|
||||
"startedAt": "2026-04-01T20:57:00.745Z",
|
||||
"completedAt": "2026-04-01T20:57:01.524Z",
|
||||
"thresholds": {
|
||||
"maxMountedTimelineRows": 140,
|
||||
"threadSwitchP50Ms": 250,
|
||||
"threadSwitchP95Ms": 500,
|
||||
"maxLongTaskMs": 120,
|
||||
"maxRafGapMs": 120,
|
||||
"burstCompletionMs": 5000,
|
||||
"longTasksOver50MsMax": 2
|
||||
},
|
||||
"summary": {
|
||||
"maxMountedTimelineRows": 23,
|
||||
"threadSwitchP50Ms": 49.5,
|
||||
"threadSwitchP95Ms": 117,
|
||||
"maxLongTaskMs": 0,
|
||||
"longTasksOver50Ms": 0,
|
||||
"maxRafGapMs": 25,
|
||||
"burstCompletionMs": null
|
||||
},
|
||||
"browserMetrics": {
|
||||
"actions": [
|
||||
{
|
||||
"name": "thread-switch-warmup-a",
|
||||
"durationMs": 117,
|
||||
"startedAtMs": 591,
|
||||
"endedAtMs": 708
|
||||
},
|
||||
{
|
||||
"name": "thread-switch-1",
|
||||
"durationMs": 46.5,
|
||||
"startedAtMs": 709.7999999523163,
|
||||
"endedAtMs": 756.2999999523163
|
||||
},
|
||||
{
|
||||
"name": "thread-switch-2",
|
||||
"durationMs": 49.5,
|
||||
"startedAtMs": 787.6000000238419,
|
||||
"endedAtMs": 837.1000000238419
|
||||
},
|
||||
{
|
||||
"name": "thread-switch-3",
|
||||
"durationMs": 70.69999992847443,
|
||||
"startedAtMs": 840.7000000476837,
|
||||
"endedAtMs": 911.3999999761581
|
||||
},
|
||||
{
|
||||
"name": "thread-switch-4",
|
||||
"durationMs": 45.89999997615814,
|
||||
"startedAtMs": 916,
|
||||
"endedAtMs": 961.8999999761581
|
||||
},
|
||||
{
|
||||
"name": "thread-switch-5",
|
||||
"durationMs": 46.699999928474426,
|
||||
"startedAtMs": 964.6000000238419,
|
||||
"endedAtMs": 1011.2999999523163
|
||||
},
|
||||
{
|
||||
"name": "thread-switch-6",
|
||||
"durationMs": 49.89999997615814,
|
||||
"startedAtMs": 1047.8999999761581,
|
||||
"endedAtMs": 1097.7999999523163
|
||||
}
|
||||
],
|
||||
"longTasks": [],
|
||||
"rafGapsMs": [
|
||||
0, 8, 0, 17, 0, 7.300000000000068, 0, 8.799999999999955, 0, 8.200000000000045, 0,
|
||||
9.099999999999909, 0, 7.7000000000000455, 0, 8.399999999999977, 0, 8.800000000000068, 0, 16,
|
||||
0, 8.399999999999977, 0, 9, 0, 8.299999999999955, 0, 7.600000000000023, 0, 17.100000000000023,
|
||||
0, 8.600000000000023, 0, 8.299999999999955, 0, 16.200000000000045, 0, 7.899999999999977, 0,
|
||||
9.299999999999955, 0, 7.399999999999977, 0, 9.200000000000045, 0, 16.700000000000045, 0, 8, 0,
|
||||
8.299999999999955, 0, 7.899999999999977, 0, 8.700000000000045, 0, 17.100000000000023, 0,
|
||||
8.199999999999932, 0, 16, 0, 16.600000000000023, 0, 8.399999999999977, 0, 8.899999999999977,
|
||||
0, 7.800000000000068, 0, 17.399999999999977, 0, 8.299999999999955, 0, 8.300000000000068, 0,
|
||||
7.699999999999932, 0, 16.700000000000045, 0, 8.100000000000023, 0, 17.399999999999977, 0,
|
||||
7.7999999999999545, 0, 8.600000000000136, 0, 8.199999999999818, 0, 8.900000000000091, 0,
|
||||
8.099999999999909, 0, 16.200000000000045, 0, 9.100000000000136, 0, 7.399999999999864, 0, 8.5,
|
||||
0, 9, 0, 25, 0, 7.600000000000136, 0, 9.199999999999818, 0
|
||||
],
|
||||
"mountedRowSamples": [
|
||||
{
|
||||
"label": "heavy-a-open",
|
||||
"count": 17,
|
||||
"capturedAtMs": 708.5
|
||||
},
|
||||
{
|
||||
"label": "thread-switch-1-rows",
|
||||
"count": 17,
|
||||
"capturedAtMs": 782
|
||||
},
|
||||
{
|
||||
"label": "thread-switch-2-rows",
|
||||
"count": 17,
|
||||
"capturedAtMs": 837.7000000476837
|
||||
},
|
||||
{
|
||||
"label": "thread-switch-3-rows",
|
||||
"count": 17,
|
||||
"capturedAtMs": 914.2000000476837
|
||||
},
|
||||
{
|
||||
"label": "thread-switch-4-rows",
|
||||
"count": 17,
|
||||
"capturedAtMs": 962.5
|
||||
},
|
||||
{
|
||||
"label": "thread-switch-5-rows",
|
||||
"count": 17,
|
||||
"capturedAtMs": 1034.1000000238419
|
||||
},
|
||||
{
|
||||
"label": "thread-switch-6-rows",
|
||||
"count": 17,
|
||||
"capturedAtMs": 1098.3999999761581
|
||||
},
|
||||
{
|
||||
"label": "scroll-start",
|
||||
"count": 17,
|
||||
"capturedAtMs": 1113.3999999761581
|
||||
},
|
||||
{
|
||||
"label": "scroll-top",
|
||||
"count": 23,
|
||||
"capturedAtMs": 1148.3999999761581
|
||||
},
|
||||
{
|
||||
"label": "scroll-bottom",
|
||||
"count": 17,
|
||||
"capturedAtMs": 1164.2000000476837
|
||||
}
|
||||
]
|
||||
},
|
||||
"serverMetrics": null,
|
||||
"metadata": {
|
||||
"heavyThreadMessageCount": 2000
|
||||
}
|
||||
}
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
{
|
||||
"suite": "websocket-application",
|
||||
"scenarioId": "dense_assistant_stream",
|
||||
"startedAt": "2026-04-01T20:57:03.910Z",
|
||||
"completedAt": "2026-04-01T20:57:07.151Z",
|
||||
"thresholds": {
|
||||
"maxMountedTimelineRows": 140,
|
||||
"threadSwitchP50Ms": 250,
|
||||
"threadSwitchP95Ms": 500,
|
||||
"maxLongTaskMs": 120,
|
||||
"maxRafGapMs": 120,
|
||||
"burstCompletionMs": 5000,
|
||||
"longTasksOver50MsMax": 2
|
||||
},
|
||||
"summary": {
|
||||
"maxMountedTimelineRows": 0,
|
||||
"threadSwitchP50Ms": 51.199999928474426,
|
||||
"threadSwitchP95Ms": 52.39999997615814,
|
||||
"maxLongTaskMs": 0,
|
||||
"longTasksOver50Ms": 0,
|
||||
"maxRafGapMs": 16.200000000000045,
|
||||
"burstCompletionMs": 3135
|
||||
},
|
||||
"browserMetrics": {
|
||||
"actions": [
|
||||
{
|
||||
"name": "thread-switch-burst-nav",
|
||||
"durationMs": 51.199999928474426,
|
||||
"startedAtMs": 1348.3999999761581,
|
||||
"endedAtMs": 1399.5999999046326
|
||||
},
|
||||
{
|
||||
"name": "thread-switch-burst-return",
|
||||
"durationMs": 52.39999997615814,
|
||||
"startedAtMs": 1401.1999999284744,
|
||||
"endedAtMs": 1453.5999999046326
|
||||
},
|
||||
{
|
||||
"name": "burst-completion",
|
||||
"durationMs": 3135,
|
||||
"startedAtMs": 332.2999999523163,
|
||||
"endedAtMs": 3467.2999999523163
|
||||
}
|
||||
],
|
||||
"longTasks": [],
|
||||
"rafGapsMs": [
|
||||
0, 7.899999999999977, 0, 9, 0, 7.300000000000011, 0, 8.899999999999977, 0, 7.800000000000011,
|
||||
0, 9.300000000000011, 0, 8.100000000000023, 0, 7.699999999999989, 0, 9.199999999999989, 0,
|
||||
7.800000000000011, 0, 7.899999999999977, 0, 9.300000000000011, 0, 7.300000000000011, 0,
|
||||
9.099999999999966, 0, 7.7000000000000455, 0, 8.199999999999989, 0, 8.399999999999977, 0,
|
||||
8.300000000000011, 0, 8.399999999999977, 0, 8.5, 0, 9.100000000000023, 0, 7.7000000000000455,
|
||||
0, 8.199999999999932, 0, 8.600000000000023, 0, 8.799999999999955, 0, 7.7000000000000455, 0,
|
||||
8.200000000000045, 0, 8.399999999999977, 0, 9.100000000000023, 0, 7.5, 0, 8.199999999999932,
|
||||
0, 9.300000000000068, 0, 7.399999999999977, 0, 8.600000000000023, 0, 8.399999999999977, 0,
|
||||
8.899999999999977, 0, 8.299999999999955, 0, 7.800000000000068, 0, 8, 0, 8.399999999999977, 0,
|
||||
8.799999999999955, 0, 7.7000000000000455, 0, 9.299999999999955, 0, 7.400000000000091, 0,
|
||||
9.299999999999955, 0, 8.299999999999955, 0, 7.7000000000000455, 0, 8.100000000000023, 0,
|
||||
8.899999999999977, 0, 8.700000000000045, 0, 7.2999999999999545, 0, 9.399999999999977, 0,
|
||||
8.200000000000045, 0, 8.100000000000023, 0, 7.699999999999932, 0, 9.300000000000068, 0,
|
||||
8.199999999999932, 0, 8.300000000000068, 0, 7.699999999999932, 0, 8.700000000000045, 0,
|
||||
8.699999999999932, 0, 7.600000000000023, 0, 8.100000000000023, 0, 8.399999999999977, 0,
|
||||
8.700000000000045, 0, 8, 0, 8.699999999999932, 0, 8.200000000000045, 0, 8.799999999999955, 0,
|
||||
8.5, 0, 7.800000000000068, 0, 8.5, 0, 8.600000000000023, 0, 8.399999999999977, 0,
|
||||
7.899999999999977, 0, 8.100000000000023, 0, 8.100000000000023, 0, 8.399999999999977, 0,
|
||||
9.299999999999955, 0, 8.100000000000023, 0, 7.5, 0, 9.200000000000045, 0, 8.5, 0,
|
||||
7.899999999999864, 0, 8.800000000000182, 0, 8.199999999999818, 0, 7.800000000000182, 0, 8.5,
|
||||
0, 8.199999999999818, 0, 8.900000000000091, 0, 8.299999999999955, 0, 7.900000000000091, 0,
|
||||
7.899999999999864, 0, 9.300000000000182, 0, 7.599999999999909, 0, 8.400000000000091, 0, 8, 0,
|
||||
8.399999999999864, 0, 9.200000000000045, 0, 7.400000000000091, 0, 9.299999999999955, 0,
|
||||
8.200000000000045, 0, 7.5, 0, 9.299999999999955, 0, 8.099999999999909, 0, 7.600000000000136,
|
||||
0, 9.299999999999955, 0, 8.200000000000045, 0, 8.399999999999864, 0, 7.5, 0,
|
||||
8.400000000000091, 0, 8.599999999999909, 0, 7.7999999999999545, 0, 8.5, 0, 9.300000000000182,
|
||||
0, 7.2999999999999545, 0, 9.399999999999864, 0, 7.5, 0, 8.100000000000136, 0, 8.5, 0,
|
||||
8.099999999999909, 0, 9.100000000000136, 0, 8.599999999999909, 0, 7.5, 0, 9.099999999999909,
|
||||
0, 7.600000000000136, 0, 8.399999999999864, 0, 8.100000000000136, 0, 8.399999999999864, 0,
|
||||
8.200000000000045, 0, 9.299999999999955, 0, 8, 0, 16.200000000000045, 0, 9.200000000000045, 0,
|
||||
8.299999999999955, 0, 8.299999999999955, 0, 8.400000000000091, 0, 7.900000000000091, 0,
|
||||
8.599999999999909, 0, 8.5, 0, 8.099999999999909, 0, 7.7000000000000455, 0, 8.700000000000045,
|
||||
0, 8.5, 0, 8.5, 0, 7.599999999999909, 0, 8.900000000000091, 0, 8.599999999999909, 0,
|
||||
8.400000000000091, 0, 8.299999999999955, 0, 7.7999999999999545, 0, 8.600000000000136, 0,
|
||||
8.200000000000045, 0, 8.799999999999955, 0, 7.599999999999909, 0, 8.100000000000136, 0,
|
||||
8.599999999999909, 0, 8.299999999999955, 0, 8.100000000000136, 0, 8.599999999999909, 0,
|
||||
9.099999999999909, 0, 8.200000000000045, 0, 7.400000000000091, 0, 8.899999999999864, 0, 8.5,
|
||||
0, 8.5, 0, 7.900000000000091, 0, 8.799999999999955, 0, 7.400000000000091, 0,
|
||||
9.299999999999955, 0, 7.400000000000091, 0, 9.299999999999955, 0, 8.299999999999955, 0,
|
||||
8.299999999999955, 0, 7.400000000000091, 0, 8.899999999999864, 0, 8.800000000000182, 0,
|
||||
7.599999999999909, 0, 8.099999999999909, 0, 8.200000000000045, 0, 9.400000000000091, 0,
|
||||
7.7000000000000455, 0, 8.899999999999864, 0, 7.400000000000091, 0, 8.399999999999864, 0,
|
||||
8.900000000000091, 0, 8, 0, 8.5, 0, 8.799999999999955, 0, 7.7000000000000455, 0,
|
||||
8.200000000000045, 0, 8.700000000000045, 0, 7.899999999999864, 0, 8.799999999999955, 0,
|
||||
8.400000000000091, 0, 8.099999999999909, 0, 8.200000000000045, 0, 8.200000000000045, 0,
|
||||
8.200000000000045, 0, 8.799999999999955, 0, 7.7999999999999545, 0, 8.600000000000136, 0,
|
||||
8.199999999999818, 0, 9.200000000000045, 0, 7.500000000000227, 0, 8.199999999999818, 0,
|
||||
9.099999999999909, 0, 7.700000000000273, 0, 8.899999999999636, 0, 7.600000000000364, 0,
|
||||
8.399999999999636, 0, 9.300000000000182, 0, 7.400000000000091, 0, 8.299999999999727, 0,
|
||||
9.300000000000182, 0, 8.300000000000182, 0, 7.799999999999727, 0, 8.900000000000091, 0,
|
||||
7.699999999999818, 0, 8.800000000000182, 0, 8.300000000000182, 0, 7.599999999999909, 0,
|
||||
8.799999999999727, 0, 7.900000000000091, 0, 9.099999999999909, 0, 8.200000000000273, 0, 8, 0,
|
||||
8.799999999999727, 0, 7.600000000000364, 0, 9.299999999999727, 0, 8.200000000000273, 0,
|
||||
7.699999999999818, 0, 8, 0, 8.599999999999909, 0, 9.099999999999909, 0, 7.300000000000182, 0,
|
||||
8.900000000000091, 0, 8.799999999999727, 0, 8.100000000000364, 0, 7.899999999999636, 0, 8, 0,
|
||||
8.400000000000091, 0, 9.099999999999909, 0, 7.5, 0, 8.800000000000182, 0, 7.900000000000091,
|
||||
0, 9.299999999999727, 0, 7.5, 0, 9.100000000000364, 0, 8.099999999999909, 0,
|
||||
7.799999999999727, 0, 8.700000000000273, 0, 7.799999999999727, 0, 9.300000000000182, 0,
|
||||
8.300000000000182, 0, 8, 0, 8.699999999999818, 0, 7.599999999999909, 0, 9.099999999999909, 0,
|
||||
8.200000000000273, 0, 7.599999999999909, 0, 9.199999999999818, 0, 8.200000000000273, 0,
|
||||
8.400000000000091, 0, 8.299999999999727, 0, 8.200000000000273, 0, 8.5, 0, 8.299999999999727,
|
||||
0, 8.400000000000091, 0, 8.300000000000182, 0, 7.5, 0, 8.5, 0, 8.099999999999909, 0,
|
||||
9.299999999999727, 0, 7.400000000000091, 0, 9, 0, 8, 0, 8.900000000000091, 0,
|
||||
8.300000000000182, 0, 8.299999999999727, 0, 7.5, 0, 8.599999999999909, 0, 8, 0,
|
||||
9.300000000000182, 0, 7.400000000000091, 0, 9.299999999999727, 0, 8.300000000000182, 0,
|
||||
7.599999999999909, 0, 8.800000000000182, 0, 8.099999999999909, 0, 8, 0, 8.800000000000182, 0,
|
||||
8.5, 0, 8.5, 0, 8.099999999999909, 0, 8.5, 0, 8, 0, 8.199999999999818, 0, 7.900000000000091,
|
||||
0, 8.599999999999909, 0, 8.599999999999909, 0, 8, 0, 9.100000000000364, 0, 8.199999999999818,
|
||||
0, 8.5, 0, 8, 0, 7.800000000000182, 0, 8.899999999999636, 0, 7.800000000000182, 0,
|
||||
9.099999999999909, 0, 8.300000000000182, 0, 7.799999999999727, 0, 9, 0, 8.300000000000182, 0,
|
||||
7.5, 0, 9.199999999999818, 0, 7.400000000000091, 0, 9.300000000000182, 0, 8, 0,
|
||||
7.799999999999727, 0, 9.200000000000273, 0, 8, 0, 7.599999999999909, 0, 8.400000000000091, 0,
|
||||
9.299999999999727, 0, 7.300000000000182, 0, 8.5, 0, 9.199999999999818, 0, 8.200000000000273,
|
||||
0, 8.400000000000091, 0, 7.5, 0, 9.199999999999818, 0, 8.300000000000182, 0,
|
||||
7.399999999999636, 0, 8.400000000000091, 0, 9, 0, 8.599999999999909, 0, 8.200000000000273, 0,
|
||||
7.5, 0, 9.299999999999727, 0, 8.200000000000273, 0, 8.400000000000091, 0, 7.399999999999636,
|
||||
0, 8.300000000000182, 0, 9.400000000000091, 0, 8, 0, 8.5, 0, 8.099999999999909, 0, 8, 0, 8, 0,
|
||||
8.900000000000091, 0, 7.900000000000091, 0, 8.299999999999727, 0, 8.300000000000182, 0, 8.5,
|
||||
0, 8.699999999999818, 0, 8.099999999999909, 0, 9, 0, 8.300000000000182, 0, 7.400000000000091,
|
||||
0, 9.099999999999909, 0, 7.800000000000182, 0, 9.099999999999909, 0, 8.199999999999818, 0,
|
||||
8.400000000000091, 0, 8.300000000000182, 0, 7.899999999999636, 0, 8.700000000000273, 0, 8.5,
|
||||
0, 7.400000000000091, 0, 8.299999999999727, 0, 8.300000000000182, 0, 9.299999999999727, 0,
|
||||
8.300000000000182, 0, 8.199999999999818, 0
|
||||
],
|
||||
"mountedRowSamples": []
|
||||
},
|
||||
"serverMetrics": null,
|
||||
"metadata": {
|
||||
"burstSeedThreadId": "perf-thread-burst",
|
||||
"navigationThreadId": "perf-thread-light-01",
|
||||
"sentinelText": "PERF_STREAM_SENTINEL:dense_assistant_stream:completed"
|
||||
}
|
||||
}
|
||||
+23
-10
@@ -1,6 +1,6 @@
|
||||
import { spawn, type ChildProcess } from "node:child_process";
|
||||
import { once } from "node:events";
|
||||
import { access } from "node:fs/promises";
|
||||
import { access, rm } from "node:fs/promises";
|
||||
import { createServer } from "node:net";
|
||||
import { resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -27,6 +27,7 @@ interface PerfSeedThreadSummary {
|
||||
|
||||
interface PerfSeededState {
|
||||
readonly scenarioId: PerfSeedScenarioId;
|
||||
readonly runParentDir: string;
|
||||
readonly baseDir: string;
|
||||
readonly workspaceRoot: string;
|
||||
readonly projectTitle: string | null;
|
||||
@@ -252,6 +253,10 @@ async function stopChildProcess(process: ChildProcess): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanupPerfRunDir(runParentDir: string): Promise<void> {
|
||||
await rm(runParentDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
function openUrl(url: string): void {
|
||||
const command: [string, ...string[]] =
|
||||
process.platform === "darwin"
|
||||
@@ -339,6 +344,7 @@ async function main(): Promise<void> {
|
||||
shuttingDown = true;
|
||||
process.stdout.write(`\nReceived ${signal}. Stopping perf app...\n`);
|
||||
await stopChildProcess(serverProcess);
|
||||
await cleanupPerfRunDir(seededState.runParentDir);
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
@@ -349,17 +355,24 @@ async function main(): Promise<void> {
|
||||
void shutdown("SIGTERM");
|
||||
});
|
||||
|
||||
const url = `http://${options.host}:${port.toString()}`;
|
||||
await waitForServerReady(url, serverProcess);
|
||||
printSeedSummary(seededState, url, options.providerScenarioId);
|
||||
try {
|
||||
const url = `http://${options.host}:${port.toString()}`;
|
||||
await waitForServerReady(url, serverProcess);
|
||||
printSeedSummary(seededState, url, options.providerScenarioId);
|
||||
|
||||
if (options.openBrowser) {
|
||||
openUrl(url);
|
||||
}
|
||||
if (options.openBrowser) {
|
||||
openUrl(url);
|
||||
}
|
||||
|
||||
const [exitCode] = (await once(serverProcess, "exit")) as [number | null];
|
||||
if (!shuttingDown) {
|
||||
process.exit(exitCode ?? 0);
|
||||
const [exitCode] = (await once(serverProcess, "exit")) as [number | null];
|
||||
if (!shuttingDown) {
|
||||
await cleanupPerfRunDir(seededState.runParentDir);
|
||||
process.exit(exitCode ?? 0);
|
||||
}
|
||||
} catch (error) {
|
||||
await stopChildProcess(serverProcess);
|
||||
await cleanupPerfRunDir(seededState.runParentDir);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,10 @@ export function percentile(values: ReadonlyArray<number>, target: number): numbe
|
||||
}
|
||||
const sorted = values.toSorted((left, right) => left - right);
|
||||
const clampedTarget = Math.min(Math.max(target, 0), 1);
|
||||
const index = Math.min(sorted.length - 1, Math.ceil(sorted.length * clampedTarget) - 1);
|
||||
const index = Math.min(
|
||||
sorted.length - 1,
|
||||
Math.max(0, Math.ceil(sorted.length * clampedTarget) - 1),
|
||||
);
|
||||
return sorted[index] ?? null;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,15 +30,16 @@ export function installBrowserPerfCollector(
|
||||
const rafGapsMs: number[] = [];
|
||||
const mountedRowSamples: Array<BrowserPerfMetrics["mountedRowSamples"][number]> = [];
|
||||
let previousAnimationFrameTs = 0;
|
||||
let rafHandle = 0;
|
||||
|
||||
const animationFrameLoop = (timestampMs: number) => {
|
||||
if (previousAnimationFrameTs > 0) {
|
||||
rafGapsMs.push(timestampMs - previousAnimationFrameTs);
|
||||
}
|
||||
previousAnimationFrameTs = timestampMs;
|
||||
window.requestAnimationFrame(animationFrameLoop);
|
||||
rafHandle = window.requestAnimationFrame(animationFrameLoop);
|
||||
};
|
||||
window.requestAnimationFrame(animationFrameLoop);
|
||||
rafHandle = window.requestAnimationFrame(animationFrameLoop);
|
||||
|
||||
if (typeof PerformanceObserver !== "undefined") {
|
||||
try {
|
||||
@@ -103,7 +104,8 @@ export function installBrowserPerfCollector(
|
||||
rafGapsMs.length = 0;
|
||||
mountedRowSamples.length = 0;
|
||||
previousAnimationFrameTs = 0;
|
||||
window.requestAnimationFrame(animationFrameLoop);
|
||||
window.cancelAnimationFrame(rafHandle);
|
||||
rafHandle = window.requestAnimationFrame(animationFrameLoop);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user