Skip to content

Commit c475e2f

Browse files
committed
CPED features need at least Node 23
1 parent cc2e8da commit c475e2f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

bindings/profilers/wall.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ WallProfiler::WallProfiler(std::chrono::microseconds samplingPeriod,
531531
workaroundV8Bug_ = workaroundV8Bug && DD_WALL_USE_SIGPROF && detectV8Bug_;
532532
collectCpuTime_ = collectCpuTime && withContexts;
533533
collectAsyncId_ = collectAsyncId && withContexts;
534+
#if NODE_MAJOR_VERSION >= 23
535+
useCPED_ = useCPED && withContexts;
536+
#else
537+
useCPED_ = false;
538+
#endif
534539

535540
if (withContexts_) {
536541
contexts_.reserve(duration * 2 / samplingPeriod);
@@ -628,6 +633,13 @@ NAN_METHOD(WallProfiler::New) {
628633
DD_WALL_PROFILER_GET_BOOLEAN_CONFIG(isMainThread);
629634
DD_WALL_PROFILER_GET_BOOLEAN_CONFIG(useCPED);
630635

636+
#if NODE_MAJOR_VERSION < 23
637+
if (useCPED) {
638+
return Nan::ThrowTypeError(
639+
"useCPED is not supported on this Node.js version.");
640+
}
641+
#endif
642+
631643
if (withContexts && !DD_WALL_USE_SIGPROF) {
632644
return Nan::ThrowTypeError("Contexts are not supported.");
633645
}
@@ -1015,6 +1027,7 @@ class PersistentContextPtr : AtomicContextPtr {
10151027
};
10161028

10171029
void WallProfiler::SetContext(Isolate* isolate, Local<Value> value) {
1030+
#if NODE_MAJOR_VERSION >= 23
10181031
if (!useCPED_) {
10191032
curContext_.Set(isolate, value);
10201033
return;
@@ -1048,6 +1061,9 @@ void WallProfiler::SetContext(Isolate* isolate, Local<Value> value) {
10481061
}
10491062

10501063
contextPtr->Set(isolate, value);
1064+
#else
1065+
curContext_.Set(isolate, value);
1066+
#endif
10511067
}
10521068

10531069
ContextPtr WallProfiler::GetContextPtrSignalSafe(Isolate* isolate) {
@@ -1070,6 +1086,7 @@ ContextPtr WallProfiler::GetContextPtrSignalSafe(Isolate* isolate) {
10701086
}
10711087

10721088
ContextPtr WallProfiler::GetContextPtr(Isolate* isolate) {
1089+
#if NODE_MAJOR_VERSION >= 23
10731090
if (!useCPED_) {
10741091
return curContext_.Get();
10751092
}
@@ -1087,6 +1104,9 @@ ContextPtr WallProfiler::GetContextPtr(Isolate* isolate) {
10871104

10881105
return static_cast<PersistentContextPtr*>(profData.As<External>()->Value())
10891106
->Get();
1107+
#else
1108+
return curContext_.Get();
1109+
#endif
10901110
}
10911111

10921112
NAN_GETTER(WallProfiler::GetContext) {
@@ -1143,7 +1163,7 @@ void WallProfiler::OnGCStart(v8::Isolate* isolate) {
11431163
if (useCPED_) {
11441164
gcContext = GetContextPtrSignalSafe(isolate);
11451165
}
1146-
}
1166+
}
11471167
gcCount.store(curCount + 1, std::memory_order_relaxed);
11481168
std::atomic_signal_fence(std::memory_order_release);
11491169
}

0 commit comments

Comments
 (0)