11import {
2- getInstrumentMode ,
32 InstrumentHooks ,
43 MARKER_TYPE_BENCHMARK_END ,
54 MARKER_TYPE_BENCHMARK_START ,
65 setupCore ,
76 teardownCore ,
87} from "@codspeed/core" ;
9- import { Bench , Fn , Task } from "tinybench" ;
8+ import { Bench , Task } from "tinybench" ;
109import { CapturedTaskData , getTaskData } from "./taskData" ;
1110import { getTaskUri } from "./uri" ;
1211
@@ -56,57 +55,12 @@ export abstract class BaseBenchRunner {
5655 return this . bench . tasks ;
5756 }
5857
59- protected wrapWithInstrumentHooks < T > ( fn : ( ) => T , uri : string ) : T {
60- const runStart = this . openInstrumentWindow ( ) ;
61- try {
62- return fn ( ) ;
63- } finally {
64- this . closeInstrumentWindow ( uri , runStart ) ;
65- }
66- }
67-
68- protected async wrapWithInstrumentHooksAsync (
69- fn : Fn ,
70- uri : string ,
71- ) : Promise < unknown > {
72- const runStart = this . openInstrumentWindow ( ) ;
73- try {
74- return await fn ( ) ;
75- } finally {
76- this . closeInstrumentWindow ( uri , runStart ) ;
77- }
78- }
79-
80- protected openInstrumentWindow ( ) : bigint {
81- InstrumentHooks . startBenchmark ( ) ;
82- return InstrumentHooks . currentTimestamp ( ) ;
83- }
84-
85- protected closeInstrumentWindow ( uri : string , runStart : bigint ) : void {
86- const runEnd = InstrumentHooks . currentTimestamp ( ) ;
87- InstrumentHooks . stopBenchmark ( ) ;
88- InstrumentHooks . setExecutedBenchmark ( process . pid , uri ) ;
89- this . sendBenchmarkMarkers ( runStart , runEnd ) ;
90- }
91-
9258 protected abstract getModeName ( ) : string ;
9359 protected abstract runTaskAsync ( task : Task , uri : string ) : Promise < void > ;
9460 protected abstract runTaskSync ( task : Task , uri : string ) : void ;
9561 protected abstract finalizeAsyncRun ( ) : Task [ ] ;
9662 protected abstract finalizeSyncRun ( ) : Task [ ] ;
9763
98- private sendBenchmarkMarkers ( runStart : bigint , runEnd : bigint ) : void {
99- if ( getInstrumentMode ( ) !== "walltime" ) {
100- return ;
101- }
102- InstrumentHooks . addMarker (
103- process . pid ,
104- MARKER_TYPE_BENCHMARK_START ,
105- runStart ,
106- ) ;
107- InstrumentHooks . addMarker ( process . pid , MARKER_TYPE_BENCHMARK_END , runEnd ) ;
108- }
109-
11064 public setupBenchMethods ( ) : void {
11165 this . bench . run = async ( ) => {
11266 this . setupBenchRun ( ) ;
@@ -130,4 +84,13 @@ export abstract class BaseBenchRunner {
13084 return this . finalizeSyncRun ( ) ;
13185 } ;
13286 }
87+
88+ protected sendBenchmarkMarkers ( runStart : bigint , runEnd : bigint ) : void {
89+ InstrumentHooks . addMarker (
90+ process . pid ,
91+ MARKER_TYPE_BENCHMARK_START ,
92+ runStart ,
93+ ) ;
94+ InstrumentHooks . addMarker ( process . pid , MARKER_TYPE_BENCHMARK_END , runEnd ) ;
95+ }
13396}
0 commit comments