Skip to content

Commit 1d75a61

Browse files
committed
chore(tinybench): emit benchmark markers
1 parent 71416d0 commit 1d75a61

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

packages/tinybench-plugin/src/walltime.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import {
22
calculateQuantiles,
3+
InstrumentHooks,
4+
MARKER_TYPE_BENCHMARK_END,
5+
MARKER_TYPE_BENCHMARK_START,
36
mongoMeasurement,
47
msToNs,
58
msToS,
@@ -64,17 +67,31 @@ class WalltimeBenchRunner extends BaseBenchRunner {
6467

6568
private wrapTaskFunction(task: Task, isAsync: boolean): void {
6669
const { fn } = task as unknown as { fn: Fn };
70+
const pid = process.pid;
71+
72+
// Emit per-round markers so the walltime instrument can bracket the actual
73+
// benchmark body (excluding the harness) when attributing perf samples.
74+
const finishRound = (roundStart: bigint): void => {
75+
const roundEnd = InstrumentHooks.currentTimestamp();
76+
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_START, roundStart);
77+
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_END, roundEnd);
78+
};
79+
6780
if (isAsync) {
6881
// eslint-disable-next-line no-inner-declarations
6982
async function __codspeed_root_frame__() {
83+
const roundStart = InstrumentHooks.currentTimestamp();
7084
await fn();
85+
finishRound(roundStart);
7186
}
7287
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7388
(task as any).fn = __codspeed_root_frame__;
7489
} else {
7590
// eslint-disable-next-line no-inner-declarations
7691
function __codspeed_root_frame__() {
92+
const roundStart = InstrumentHooks.currentTimestamp();
7793
fn();
94+
finishRound(roundStart);
7895
}
7996
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8097
(task as any).fn = __codspeed_root_frame__;

0 commit comments

Comments
 (0)