|
1 | | -import { InstrumentHooks, setupCore, teardownCore } from "@codspeed/core"; |
| 1 | +import { |
| 2 | + getInstrumentMode, |
| 3 | + InstrumentHooks, |
| 4 | + MARKER_TYPE_BENCHMARK_END, |
| 5 | + MARKER_TYPE_BENCHMARK_START, |
| 6 | + setupCore, |
| 7 | + teardownCore, |
| 8 | +} from "@codspeed/core"; |
2 | 9 | import { Bench, Fn, Task } from "tinybench"; |
3 | 10 | import { getTaskUri } from "./uri"; |
4 | 11 |
|
@@ -63,25 +70,43 @@ export abstract class BaseBenchRunner { |
63 | 70 | protected abstract finalizeAsyncRun(): Task[]; |
64 | 71 | protected abstract finalizeSyncRun(): Task[]; |
65 | 72 |
|
| 73 | + private sendRunMarkers(runStart: bigint, runEnd: bigint): void { |
| 74 | + if (getInstrumentMode() !== "walltime") { |
| 75 | + return; |
| 76 | + } |
| 77 | + InstrumentHooks.addMarker( |
| 78 | + process.pid, |
| 79 | + MARKER_TYPE_BENCHMARK_START, |
| 80 | + runStart, |
| 81 | + ); |
| 82 | + InstrumentHooks.addMarker(process.pid, MARKER_TYPE_BENCHMARK_END, runEnd); |
| 83 | + } |
| 84 | + |
66 | 85 | public setupBenchMethods(): void { |
67 | 86 | this.bench.run = async () => { |
68 | 87 | this.setupBenchRun(); |
69 | 88 |
|
| 89 | + const runStart = InstrumentHooks.currentTimestamp(); |
70 | 90 | for (const task of this.bench.tasks) { |
71 | 91 | const uri = this.getTaskUri(task); |
72 | 92 | await this.runTaskAsync(task, uri); |
73 | 93 | } |
| 94 | + const runEnd = InstrumentHooks.currentTimestamp(); |
| 95 | + this.sendRunMarkers(runStart, runEnd); |
74 | 96 |
|
75 | 97 | return this.finalizeAsyncRun(); |
76 | 98 | }; |
77 | 99 |
|
78 | 100 | this.bench.runSync = () => { |
79 | 101 | this.setupBenchRun(); |
80 | 102 |
|
| 103 | + const runStart = InstrumentHooks.currentTimestamp(); |
81 | 104 | for (const task of this.bench.tasks) { |
82 | 105 | const uri = this.getTaskUri(task); |
83 | 106 | this.runTaskSync(task, uri); |
84 | 107 | } |
| 108 | + const runEnd = InstrumentHooks.currentTimestamp(); |
| 109 | + this.sendRunMarkers(runStart, runEnd); |
85 | 110 |
|
86 | 111 | return this.finalizeSyncRun(); |
87 | 112 | }; |
|
0 commit comments