|
1 | 1 | import { |
2 | 2 | calculateQuantiles, |
| 3 | + InstrumentHooks, |
| 4 | + MARKER_TYPE_BENCHMARK_END, |
| 5 | + MARKER_TYPE_BENCHMARK_START, |
3 | 6 | mongoMeasurement, |
4 | 7 | msToNs, |
5 | 8 | msToS, |
@@ -64,17 +67,31 @@ class WalltimeBenchRunner extends BaseBenchRunner { |
64 | 67 |
|
65 | 68 | private wrapTaskFunction(task: Task, isAsync: boolean): void { |
66 | 69 | 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 | + |
67 | 80 | if (isAsync) { |
68 | 81 | // eslint-disable-next-line no-inner-declarations |
69 | 82 | async function __codspeed_root_frame__() { |
| 83 | + const roundStart = InstrumentHooks.currentTimestamp(); |
70 | 84 | await fn(); |
| 85 | + finishRound(roundStart); |
71 | 86 | } |
72 | 87 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
73 | 88 | (task as any).fn = __codspeed_root_frame__; |
74 | 89 | } else { |
75 | 90 | // eslint-disable-next-line no-inner-declarations |
76 | 91 | function __codspeed_root_frame__() { |
| 92 | + const roundStart = InstrumentHooks.currentTimestamp(); |
77 | 93 | fn(); |
| 94 | + finishRound(roundStart); |
78 | 95 | } |
79 | 96 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
80 | 97 | (task as any).fn = __codspeed_root_frame__; |
|
0 commit comments