Skip to content

Commit

Permalink
fixup! feat: add a root frame for the callgraph generation
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Jun 23, 2023
1 parent d24465b commit 2574459
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 11 additions & 6 deletions packages/benchmark.js-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,21 @@ async function runBenchmarks({
} else {
benchPayload = bench.fn as CallableFunction;
}

if (isAsync) {
await optimizeFunction(benchPayload);
measurement.startInstrumentation();
await benchPayload();
measurement.stopInstrumentation(uri);
await (async function __codspeed_root_frame__() {
measurement.startInstrumentation();
await benchPayload();
measurement.stopInstrumentation(uri);
})();
} else {
optimizeFunctionSync(benchPayload);
measurement.startInstrumentation();
benchPayload();
measurement.stopInstrumentation(uri);
(function __codspeed_root_frame__() {
measurement.startInstrumentation();
benchPayload();
measurement.stopInstrumentation(uri);
})();
}
console.log(` ✔ Measured ${uri}`);
benchmarkCompletedListeners.forEach((listener) => listener());
Expand Down
12 changes: 5 additions & 7 deletions packages/tinybench-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ export function withCodSpeed(bench: Bench): Bench {
console.log(`[CodSpeed] running with @codspeed/tinybench v${__VERSION__}`);
for (const task of bench.tasks) {
const uri = callingFile + "::" + task.name;
// eslint-disable-next-line no-inner-declarations
async function __codspeed_root_frame__() {
await optimizeFunction(task.fn());
await (async function __codspeed_root_frame__() {
measurement.startInstrumentation();
await task.fn();
}
await optimizeFunction(__codspeed_root_frame__);
measurement.startInstrumentation();
await __codspeed_root_frame__();
measurement.stopInstrumentation(uri);
measurement.stopInstrumentation(uri);
})();
console.log(` ✔ Measured ${uri}`);
}
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
Expand Down

0 comments on commit 2574459

Please sign in to comment.