@@ -6,52 +6,33 @@ namespace codspeed_native {
66namespace instruments {
77namespace hooks_wrapper {
88
9- // Global instance to maintain state across calls
10- static std::unique_ptr<InstrumentHooks, decltype (&instrument_hooks_deinit)>
11- g_hooks{nullptr , &instrument_hooks_deinit};
12-
13- // Initialize instrument hooks if not already done
14- static InstrumentHooks *ensureInitialized () {
15- if (!g_hooks) {
16- InstrumentHooks *hooks = instrument_hooks_init ();
17- if (hooks) {
18- g_hooks.reset (hooks);
19- }
9+ static InstrumentHooks *hooks = nullptr ;
10+
11+ void InitializeGlobal () {
12+ printf (" In InitializeGlobal\n " );
13+ if (!hooks) {
14+ printf (" Foo\n " );
15+ hooks = instrument_hooks_init ();
16+ printf (" Bar\n " );
2017 }
21- return g_hooks.get ();
2218}
2319
2420Napi::Boolean IsInstrumented (const Napi::CallbackInfo &info) {
2521 Napi::Env env = info.Env ();
26- InstrumentHooks *hooks = ensureInitialized ();
27-
28- if (!hooks) {
29- return Napi::Boolean::New (env, false );
30- }
3122
3223 bool instrumented = instrument_hooks_is_instrumented (hooks);
3324 return Napi::Boolean::New (env, instrumented);
3425}
3526
3627Napi::Number StartBenchmark (const Napi::CallbackInfo &info) {
3728 Napi::Env env = info.Env ();
38- InstrumentHooks *hooks = ensureInitialized ();
39-
40- if (!hooks) {
41- return Napi::Number::New (env, 1 ); // Return error code
42- }
4329
4430 uint8_t result = instrument_hooks_start_benchmark (hooks);
4531 return Napi::Number::New (env, result);
4632}
4733
4834Napi::Number StopBenchmark (const Napi::CallbackInfo &info) {
4935 Napi::Env env = info.Env ();
50- InstrumentHooks *hooks = ensureInitialized ();
51-
52- if (!hooks) {
53- return Napi::Number::New (env, 1 ); // Return error code
54- }
5536
5637 uint8_t result = instrument_hooks_stop_benchmark (hooks);
5738 return Napi::Number::New (env, result);
@@ -72,11 +53,6 @@ Napi::Number SetExecutedBenchmark(const Napi::CallbackInfo &info) {
7253 return Napi::Number::New (env, 1 );
7354 }
7455
75- InstrumentHooks *hooks = ensureInitialized ();
76- if (!hooks) {
77- return Napi::Number::New (env, 1 );
78- }
79-
8056 uint32_t pid = info[0 ].As <Napi::Number>().Uint32Value ();
8157 std::string uri = info[1 ].As <Napi::String>().Utf8Value ();
8258
@@ -100,11 +76,6 @@ Napi::Number SetIntegration(const Napi::CallbackInfo &info) {
10076 return Napi::Number::New (env, 1 );
10177 }
10278
103- InstrumentHooks *hooks = ensureInitialized ();
104- if (!hooks) {
105- return Napi::Number::New (env, 1 );
106- }
107-
10879 std::string name = info[0 ].As <Napi::String>().Utf8Value ();
10980 std::string version = info[1 ].As <Napi::String>().Utf8Value ();
11081
@@ -116,6 +87,10 @@ Napi::Number SetIntegration(const Napi::CallbackInfo &info) {
11687Napi::Object Initialize (Napi::Env env, Napi::Object exports) {
11788 Napi::Object instrumentHooksObj = Napi::Object::New (env);
11889
90+ printf (" In instrument hooks init\n " );
91+ InitializeGlobal ();
92+ printf (" 1\n " );
93+
11994 instrumentHooksObj.Set (Napi::String::New (env, " isInstrumented" ),
12095 Napi::Function::New (env, IsInstrumented));
12196 instrumentHooksObj.Set (Napi::String::New (env, " startBenchmark" ),
@@ -127,8 +102,11 @@ Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
127102 instrumentHooksObj.Set (Napi::String::New (env, " setIntegration" ),
128103 Napi::Function::New (env, SetIntegration));
129104
105+ printf (" 2\n " );
106+
130107 exports.Set (Napi::String::New (env, " InstrumentHooks" ), instrumentHooksObj);
131108
109+ printf (" 3\n " );
132110 return exports;
133111}
134112
0 commit comments