1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-07-25 20:14:55 +02:00

refactor(gh): unify heap snapshot output paths

This commit is contained in:
syuilo
2026-07-16 23:19:25 +09:00
parent 0272ee73eb
commit 88c6cd1766
2 changed files with 14 additions and 10 deletions

View File

@@ -11,7 +11,7 @@ import { HeadlessChromeController, summarizeBrowserDiagnostics, summarizeNetwork
import type { BrowserMeasurement, NetworkRequest, NetworkSummary } from './chrome.mts';
import { closeUserSetupDialog, postNote, signupThroughUi, visitHome } from '../../packages/frontend/test/e2e/shared.ts';
const [baseDirArg, headDirArg, baseOutputArg, headOutputArg, baseHeapSnapshotOutputArg, headHeapSnapshotOutputArg] = process.argv.slice(2);
const [baseDirArg, headDirArg, baseOutputArg, headOutputArg] = process.argv.slice(2);
const baseUrl = process.env.FRONTEND_BROWSER_METRICS_URL ?? 'http://127.0.0.1:61812';
const sampleCount = util.readIntegerEnv('FRONTEND_BROWSER_METRICS_SAMPLE_COUNT', 5, 1);
@@ -20,6 +20,10 @@ const heapSnapshotWorkDirs = {
base: resolve('frontend-browser-base-heap-snapshots'),
head: resolve('frontend-browser-head-heap-snapshots'),
} as const;
const heapSnapshotOutputPaths = {
base: resolve('base-heap-snapshot.heapsnapshot'),
head: resolve('head-heap-snapshot.heapsnapshot'),
} as const;
type BrowserMeasurementSample = BrowserMeasurement & {
round: number;
@@ -230,14 +234,14 @@ function heapSnapshotPath(label: 'base' | 'head', round: number) {
return join(heapSnapshotWorkDirs[label], `round-${round}.heapsnapshot`);
}
async function saveRepresentativeHeapSnapshot(label: 'base' | 'head', report: BrowserMetricsReport, outputPath: string) {
async function saveRepresentativeHeapSnapshot(label: 'base' | 'head', report: BrowserMetricsReport) {
const representative = selectRepresentativeSample(report.samples, sample => sample.heapSnapshot.categories.total);
await copyFile(heapSnapshotPath(label, representative.round), outputPath);
await copyFile(heapSnapshotPath(label, representative.round), heapSnapshotOutputPaths[label]);
process.stderr.write(`[${label}] Selected round ${representative.round} heap snapshot for artifact\n`);
await rm(heapSnapshotWorkDirs[label], { recursive: true, force: true });
}
async function genReport(label: 'base' | 'head', repoDir: string, outputPath: string, heapSnapshotSavePath: string) {
async function genReport(label: 'base' | 'head', repoDir: string, outputPath: string) {
let server: ReturnType<typeof util.startServer> | null = null;
try {
@@ -261,15 +265,15 @@ async function genReport(label: 'base' | 'head', repoDir: string, outputPath: st
await writeFile(outputPath, JSON.stringify(report, null, '\t'));
process.stderr.write(`[${label}] Wrote browser metrics report to ${outputPath}\n`);
await saveRepresentativeHeapSnapshot(label, report, heapSnapshotSavePath);
await saveRepresentativeHeapSnapshot(label, report);
} finally {
if (server != null) await util.stopServer(server);
}
}
async function main() {
await genReport('base', resolve(baseDirArg), resolve(baseOutputArg), resolve(baseHeapSnapshotOutputArg));
await genReport('head', resolve(headDirArg), resolve(headOutputArg), resolve(headHeapSnapshotOutputArg));
await genReport('base', resolve(baseDirArg), resolve(baseOutputArg));
await genReport('head', resolve(headDirArg), resolve(headOutputArg));
}
await main();