Skip to content

Commit 3fd6a83

Browse files
committed
feat: add a root frame for the callgraph generation
1 parent 6be5b89 commit 3fd6a83

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/benchmark.js-plugin/src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,21 @@ async function runBenchmarks({
177177
} else {
178178
benchPayload = bench.fn as CallableFunction;
179179
}
180+
180181
if (isAsync) {
181182
await optimizeFunction(benchPayload);
182-
measurement.startInstrumentation();
183-
await benchPayload();
184-
measurement.stopInstrumentation(uri);
183+
await (async function __codspeed_root_frame__() {
184+
measurement.startInstrumentation();
185+
await benchPayload();
186+
measurement.stopInstrumentation(uri);
187+
})();
185188
} else {
186189
optimizeFunctionSync(benchPayload);
187-
measurement.startInstrumentation();
188-
benchPayload();
189-
measurement.stopInstrumentation(uri);
190+
(function __codspeed_root_frame__() {
191+
measurement.startInstrumentation();
192+
benchPayload();
193+
measurement.stopInstrumentation(uri);
194+
})();
190195
}
191196
console.log(` ✔ Measured ${uri}`);
192197
benchmarkCompletedListeners.forEach((listener) => listener());

packages/tinybench-plugin/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ export function withCodSpeed(bench: Bench): Bench {
2525
for (const task of bench.tasks) {
2626
const uri = callingFile + "::" + task.name;
2727
await optimizeFunction(task.fn);
28-
measurement.startInstrumentation();
29-
await task.fn();
30-
measurement.stopInstrumentation(uri);
28+
await (async function __codspeed_root_frame__() {
29+
measurement.startInstrumentation();
30+
await task.fn();
31+
measurement.stopInstrumentation(uri);
32+
})();
3133
console.log(` ✔ Measured ${uri}`);
3234
}
3335
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);

0 commit comments

Comments
 (0)