@@ -129,6 +129,48 @@ Napi::Number WriteEnvironment(const Napi::CallbackInfo &info) {
129129 return Napi::Number::New (env, result);
130130}
131131
132+ Napi::BigInt CurrentTimestamp (const Napi::CallbackInfo &info) {
133+ Napi::Env env = info.Env ();
134+ uint64_t ts = instrument_hooks_current_timestamp ();
135+ return Napi::BigInt::New (env, ts);
136+ }
137+
138+ Napi::Number AddMarker (const Napi::CallbackInfo &info) {
139+ Napi::Env env = info.Env ();
140+
141+ if (info.Length () != 3 ) {
142+ Napi::TypeError::New (env,
143+ " Expected 3 arguments: pid, markerType, timestamp" )
144+ .ThrowAsJavaScriptException ();
145+ return Napi::Number::New (env, 1 );
146+ }
147+
148+ if (!info[0 ].IsNumber () || !info[1 ].IsNumber () ||
149+ !(info[2 ].IsBigInt () || info[2 ].IsNumber ())) {
150+ Napi::TypeError::New (
151+ env,
152+ " Expected number (pid), number (markerType), bigint|number (timestamp)" )
153+ .ThrowAsJavaScriptException ();
154+ return Napi::Number::New (env, 1 );
155+ }
156+
157+ int32_t pid = info[0 ].As <Napi::Number>().Int32Value ();
158+ uint8_t marker_type =
159+ static_cast <uint8_t >(info[1 ].As <Napi::Number>().Uint32Value ());
160+ uint64_t timestamp;
161+ if (info[2 ].IsBigInt ()) {
162+ bool lossless = false ;
163+ timestamp = info[2 ].As <Napi::BigInt>().Uint64Value (&lossless);
164+ } else {
165+ timestamp =
166+ static_cast <uint64_t >(info[2 ].As <Napi::Number>().DoubleValue ());
167+ }
168+
169+ uint8_t result =
170+ instrument_hooks_add_marker (hooks, pid, marker_type, timestamp);
171+ return Napi::Number::New (env, result);
172+ }
173+
132174Napi::Value __attribute__ ((noinline)) __codspeed_root_frame__(const Napi::CallbackInfo &info) {
133175 Napi::Env env = info.Env ();
134176
@@ -169,6 +211,10 @@ Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
169211 Napi::Function::New (env, SetEnvironment));
170212 instrumentHooksObj.Set (Napi::String::New (env, " writeEnvironment" ),
171213 Napi::Function::New (env, WriteEnvironment));
214+ instrumentHooksObj.Set (Napi::String::New (env, " currentTimestamp" ),
215+ Napi::Function::New (env, CurrentTimestamp));
216+ instrumentHooksObj.Set (Napi::String::New (env, " addMarker" ),
217+ Napi::Function::New (env, AddMarker));
172218 instrumentHooksObj.Set (Napi::String::New (env, " __codspeed_root_frame__" ),
173219 Napi::Function::New (env, __codspeed_root_frame__));
174220
0 commit comments