File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import {
22 Measurement ,
3+ mongoMeasurement ,
34 optimizeFunction ,
45 optimizeFunctionSync ,
56 setupCore ,
@@ -183,6 +184,7 @@ async function runBenchmarks({
183184 benchPayload = bench . fn as CallableFunction ;
184185 }
185186
187+ await mongoMeasurement . start ( uri ) ;
186188 if ( isAsync ) {
187189 await optimizeFunction ( benchPayload ) ;
188190 await ( async function __codspeed_root_frame__ ( ) {
@@ -198,6 +200,8 @@ async function runBenchmarks({
198200 Measurement . stopInstrumentation ( uri ) ;
199201 } ) ( ) ;
200202 }
203+ await mongoMeasurement . stop ( uri ) ;
204+
201205 console . log ( ` ✔ Measured ${ uri } ` ) ;
202206 benchmarkCompletedListeners . forEach ( ( listener ) => listener ( ) ) ;
203207 teardownCore ( ) ;
Original file line number Diff line number Diff line change 11build
2- prebuilds
2+ prebuilds
3+ generated
Original file line number Diff line number Diff line change 22 clean :
33 args :
44 - build
5+ - generated/openapi
56 build :
67 deps :
78 - " build-native-addon"
@@ -14,3 +15,10 @@ tasks:
1415 - " binding.gyp"
1516 outputs :
1617 - " prebuilds"
18+
19+ build-tracer-client :
20+ inputs :
21+ - " ./tracer.spec.json"
22+ outputs :
23+ - " src/generated/openapi"
24+ command : openapi --client axios --input ./tracer.spec.json --name MongoTracer --output ./src/generated/openapi
Original file line number Diff line number Diff line change 2222 "devDependencies" : {
2323 "node-addon-api" : " ^5.1.0" ,
2424 "node-gyp" : " ^9.3.1" ,
25+ "openapi-typescript-codegen" : " ^0.23.0" ,
2526 "prebuildify" : " ^5.0.1"
2627 },
2728 "dependencies" : {
29+ "axios" : " ^1.4.0" ,
2830 "node-gyp-build" : " ^4.6.0"
2931 }
3032}
Original file line number Diff line number Diff line change 11import { tryIntrospect } from "./introspection" ;
2+ import { MongoMeasurement } from "./mongoMeasurement" ;
23tryIntrospect ( ) ;
34
45import native_core from "./native_core" ;
@@ -10,12 +11,15 @@ const linuxPerf = new native_core.LinuxPerf();
1011
1112export const isBound = native_core . isBound ;
1213
14+ export let mongoMeasurement : MongoMeasurement ;
15+
1316export const setupCore = ( ) => {
1417 initOptimization ( ) ;
1518 native_core . Measurement . stopInstrumentation (
1619 `Metadata: codspeed-node ${ __VERSION__ } `
1720 ) ;
1821 linuxPerf . start ( ) ;
22+ mongoMeasurement = new MongoMeasurement ( ) ;
1923} ;
2024
2125export const teardownCore = ( ) => {
Original file line number Diff line number Diff line change 1+ import { MongoTracer } from "./generated/openapi" ;
2+
3+ export class MongoMeasurement {
4+ private tracerClient : MongoTracer | undefined ;
5+
6+ constructor ( ) {
7+ const serverUrl = process . env . CODSPEED_MONGO_INSTR_SERVER_ADDRESS ;
8+ // TODO
9+ const mongoUriEnvName = process . env . CODSPEED_MONGO_INSTR_URI_ENV_NAME ;
10+ if ( mongoUriEnvName === undefined ) {
11+ throw new Error ( "CODSPEED_MONGO_INSTR_URI_ENV_NAME is not defined" ) ;
12+ }
13+ const mongoUri = process . env [ mongoUriEnvName ] ;
14+ if ( mongoUri === undefined ) {
15+ throw new Error ( `Environment variable ${ mongoUriEnvName } is not defined` ) ;
16+ }
17+ process . env [ mongoUriEnvName ] =
18+ "mongodb://localhost:27018?directConnection=true" ;
19+
20+ if ( serverUrl !== undefined ) {
21+ this . tracerClient = new MongoTracer ( {
22+ BASE : serverUrl ,
23+ } ) ;
24+ }
25+ }
26+
27+ public async start ( uri : string ) {
28+ if ( this . tracerClient !== undefined ) {
29+ await this . tracerClient . instrumentation . start ( {
30+ uri,
31+ } ) ;
32+ }
33+ }
34+
35+ public async stop ( uri : string ) {
36+ if ( this . tracerClient !== undefined ) {
37+ await this . tracerClient . instrumentation . stop ( {
38+ uri,
39+ } ) ;
40+ }
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments