Skip to content

Commit 0919894

Browse files
Merge pull request #21060 from emberjs/nvp/cleanup/benchmark-runner
Cleanup benchmark code
2 parents 1dedd55 + 93dbeb1 commit 0919894

2 files changed

Lines changed: 21 additions & 46 deletions

File tree

bin/benchmark.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ const FORCE = hasFlag(process.argv, '--force');
2929
const REUSE = hasFlag(process.argv, '--reuse');
3030

3131
try {
32-
const result = await runBenchmark({
32+
await runBenchmark({
3333
force: FORCE,
3434
reuse: REUSE,
3535
});
36-
37-
console.log(`\nWrote report: ${result.msgFile}`);
3836
} catch (error) {
3937
console.error(error);
4038
process.exit(1);

bin/benchmark/run.mjs

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getOrBuildControlTarball } from './control.mjs';
88
import { buildExperimentTarball } from './experiment.mjs';
99
import { run, prepareApp, sleep, startVitePreview, lsof } from './utils.mjs';
1010

11-
const { ensureDir, remove, writeFile } = fs;
11+
const { ensureDir, remove } = fs;
1212

1313
function buildMarkersString(markers) {
1414
return markers
@@ -57,24 +57,18 @@ const DEFAULT_MARKERS = [
5757

5858
import { REPO_ROOT, BENCH_ROOT } from './utils.mjs';
5959

60-
export async function runBenchmark({ force = false, reuse = false } = {}) {
61-
// Use config constants directly; no local re-assignment
60+
const CONTROL_DIRS = {
61+
repo: join(BENCH_ROOT, 'ember-source-control'),
62+
app: join(BENCH_ROOT, 'control'),
63+
};
64+
const EXPERIMENT_DIRS = {
65+
app: join(BENCH_ROOT, 'experiment'),
66+
repo: REPO_ROOT,
67+
};
6268

69+
export async function runBenchmark({ force = false, reuse = false } = {}) {
6370
await ensureDir(BENCH_ROOT);
6471

65-
const CONTROL_DIRS = {
66-
repo: join(BENCH_ROOT, 'ember-source-control'),
67-
app: join(BENCH_ROOT, 'control'),
68-
};
69-
const EXPERIMENT_DIRS = {
70-
app: join(BENCH_ROOT, 'experiment'),
71-
repo: REPO_ROOT,
72-
};
73-
74-
const controlUrl = `http://127.0.0.1:${DEFAULT_CONTROL_PORT}`;
75-
const experimentUrl = `http://127.0.0.1:${DEFAULT_EXPERIMENT_PORT}`;
76-
const markersString = buildMarkersString(DEFAULT_MARKERS);
77-
7872
if (force) {
7973
await killPortProcess([DEFAULT_CONTROL_PORT, DEFAULT_EXPERIMENT_PORT]);
8074
await remove(CONTROL_DIRS.repo);
@@ -124,18 +118,19 @@ export async function runBenchmark({ force = false, reuse = false } = {}) {
124118
port: DEFAULT_EXPERIMENT_PORT,
125119
});
126120

127-
async function cleanup() {
128-
console.log(`\n\tCleaning up servers...`);
121+
try {
122+
await bootAndRun();
123+
} finally {
124+
console.log(`\n\tCleaning up servers with SIGKILL...`);
129125

130126
await killPortProcess([DEFAULT_CONTROL_PORT, DEFAULT_EXPERIMENT_PORT]);
131127
}
128+
}
132129

133-
process.on('exit', cleanup);
134-
process.on('SIGINT', () => {
135-
cleanup();
136-
// eslint-disable-next-line n/no-process-exit
137-
process.exit(1);
138-
});
130+
async function bootAndRun() {
131+
const controlUrl = `http://127.0.0.1:${DEFAULT_CONTROL_PORT}`;
132+
const experimentUrl = `http://127.0.0.1:${DEFAULT_EXPERIMENT_PORT}`;
133+
const markersString = buildMarkersString(DEFAULT_MARKERS);
139134

140135
// give servers a moment to start
141136
await sleep(5000);
@@ -179,23 +174,5 @@ export async function runBenchmark({ force = false, reuse = false } = {}) {
179174
`"--incognito,--disable-gpu,--mute-audio,--log-level=3,--headless=new"`,
180175
];
181176

182-
const output = await run('node', args, { cwd: EXPERIMENT_DIRS.app });
183-
const msgFile = join(BENCH_ROOT, 'msg.txt');
184-
185-
if (!process.env.CI) {
186-
await writeFile(
187-
msgFile,
188-
output.stdout.split('Benchmark Results Summary').pop() ?? output.stdout,
189-
'utf8'
190-
);
191-
}
192-
193-
await cleanup();
194-
195-
return {
196-
benchRoot: BENCH_ROOT,
197-
msgFile,
198-
controlUrl,
199-
experimentUrl,
200-
};
177+
await run('node', args, { cwd: EXPERIMENT_DIRS.app });
201178
}

0 commit comments

Comments
 (0)