Skip to content

Commit 94674d4

Browse files
committed
fix(vitest): balance profiler in walltime runner on benchmark error
Move stopBenchmark() and marker emissions into the finally block so a throwing benchmark cannot leave the profiler started-but-never-stopped, which would corrupt instrumentation state for subsequent benchmarks.
1 parent 48a2b46 commit 94674d4

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • packages/vitest-plugin/src/walltime

packages/vitest-plugin/src/walltime/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
9090
try {
9191
await originalRun.call(this);
9292
} finally {
93+
const runEnd = InstrumentHooks.currentTimestamp();
94+
InstrumentHooks.stopBenchmark();
9395
task.fn = originalFn;
94-
}
95-
const runEnd = InstrumentHooks.currentTimestamp();
96-
InstrumentHooks.stopBenchmark();
9796

98-
// Emit a single marker pair covering the whole measurement run
99-
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_START, runStart);
100-
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_END, runEnd);
97+
// Emit a single marker pair covering the whole measurement run
98+
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_START, runStart);
99+
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_END, runEnd);
101100

102-
// Look up the URI by task name
103-
const uri = `${suiteUri}::${this.name}`;
104-
InstrumentHooks.setExecutedBenchmark(pid, uri);
101+
// Look up the URI by task name
102+
const uri = `${suiteUri}::${this.name}`;
103+
InstrumentHooks.setExecutedBenchmark(pid, uri);
104+
}
105105

106106
return this;
107107
};

0 commit comments

Comments
 (0)