@@ -6,52 +6,33 @@ namespace codspeed_native {
6
6
namespace instruments {
7
7
namespace hooks_wrapper {
8
8
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 " );
20
17
}
21
- return g_hooks.get ();
22
18
}
23
19
24
20
Napi::Boolean IsInstrumented (const Napi::CallbackInfo &info) {
25
21
Napi::Env env = info.Env ();
26
- InstrumentHooks *hooks = ensureInitialized ();
27
-
28
- if (!hooks) {
29
- return Napi::Boolean::New (env, false );
30
- }
31
22
32
23
bool instrumented = instrument_hooks_is_instrumented (hooks);
33
24
return Napi::Boolean::New (env, instrumented);
34
25
}
35
26
36
27
Napi::Number StartBenchmark (const Napi::CallbackInfo &info) {
37
28
Napi::Env env = info.Env ();
38
- InstrumentHooks *hooks = ensureInitialized ();
39
-
40
- if (!hooks) {
41
- return Napi::Number::New (env, 1 ); // Return error code
42
- }
43
29
44
30
uint8_t result = instrument_hooks_start_benchmark (hooks);
45
31
return Napi::Number::New (env, result);
46
32
}
47
33
48
34
Napi::Number StopBenchmark (const Napi::CallbackInfo &info) {
49
35
Napi::Env env = info.Env ();
50
- InstrumentHooks *hooks = ensureInitialized ();
51
-
52
- if (!hooks) {
53
- return Napi::Number::New (env, 1 ); // Return error code
54
- }
55
36
56
37
uint8_t result = instrument_hooks_stop_benchmark (hooks);
57
38
return Napi::Number::New (env, result);
@@ -72,11 +53,6 @@ Napi::Number SetExecutedBenchmark(const Napi::CallbackInfo &info) {
72
53
return Napi::Number::New (env, 1 );
73
54
}
74
55
75
- InstrumentHooks *hooks = ensureInitialized ();
76
- if (!hooks) {
77
- return Napi::Number::New (env, 1 );
78
- }
79
-
80
56
uint32_t pid = info[0 ].As <Napi::Number>().Uint32Value ();
81
57
std::string uri = info[1 ].As <Napi::String>().Utf8Value ();
82
58
@@ -100,11 +76,6 @@ Napi::Number SetIntegration(const Napi::CallbackInfo &info) {
100
76
return Napi::Number::New (env, 1 );
101
77
}
102
78
103
- InstrumentHooks *hooks = ensureInitialized ();
104
- if (!hooks) {
105
- return Napi::Number::New (env, 1 );
106
- }
107
-
108
79
std::string name = info[0 ].As <Napi::String>().Utf8Value ();
109
80
std::string version = info[1 ].As <Napi::String>().Utf8Value ();
110
81
@@ -116,6 +87,10 @@ Napi::Number SetIntegration(const Napi::CallbackInfo &info) {
116
87
Napi::Object Initialize (Napi::Env env, Napi::Object exports) {
117
88
Napi::Object instrumentHooksObj = Napi::Object::New (env);
118
89
90
+ printf (" In instrument hooks init\n " );
91
+ InitializeGlobal ();
92
+ printf (" 1\n " );
93
+
119
94
instrumentHooksObj.Set (Napi::String::New (env, " isInstrumented" ),
120
95
Napi::Function::New (env, IsInstrumented));
121
96
instrumentHooksObj.Set (Napi::String::New (env, " startBenchmark" ),
@@ -127,8 +102,11 @@ Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
127
102
instrumentHooksObj.Set (Napi::String::New (env, " setIntegration" ),
128
103
Napi::Function::New (env, SetIntegration));
129
104
105
+ printf (" 2\n " );
106
+
130
107
exports.Set (Napi::String::New (env, " InstrumentHooks" ), instrumentHooksObj);
131
108
109
+ printf (" 3\n " );
132
110
return exports;
133
111
}
134
112
0 commit comments