Skip to content

Commit 6b5d447

Browse files
committed
CPED features need at least Node 23
1 parent e014add commit 6b5d447

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
@@ -524,6 +524,11 @@ WallProfiler::WallProfiler(std::chrono::microseconds samplingPeriod,
524524
workaroundV8Bug_ = workaroundV8Bug && DD_WALL_USE_SIGPROF && detectV8Bug_;
525525
collectCpuTime_ = collectCpuTime && withContexts;
526526
collectAsyncId_ = collectAsyncId && withContexts;
527+
#if NODE_MAJOR_VERSION >= 23
528+
useCPED_ = useCPED && withContexts;
529+
#else
530+
useCPED_ = false;
531+
#endif
527532

528533
if (withContexts_) {
529534
contexts_.reserve(duration * 2 / samplingPeriod);
@@ -629,6 +634,13 @@ NAN_METHOD(WallProfiler::New) {
629634
DD_WALL_PROFILER_GET_BOOLEAN_CONFIG(isMainThread);
630635
DD_WALL_PROFILER_GET_BOOLEAN_CONFIG(useCPED);
631636

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

10181030
void WallProfiler::SetContext(Isolate* isolate, Local<Value> value) {
1031+
#if NODE_MAJOR_VERSION >= 23
10191032
if (!useCPED_) {
10201033
curContext_.Set(isolate, value);
10211034
return;
@@ -1049,6 +1062,9 @@ void WallProfiler::SetContext(Isolate* isolate, Local<Value> value) {
10491062
}
10501063

10511064
contextPtr->Set(isolate, value);
1065+
#else
1066+
curContext_.Set(isolate, value);
1067+
#endif
10521068
}
10531069

10541070
ContextPtr WallProfiler::GetContextPtrSignalSafe(Isolate* isolate) {
@@ -1071,6 +1087,7 @@ ContextPtr WallProfiler::GetContextPtrSignalSafe(Isolate* isolate) {
10711087
}
10721088

10731089
ContextPtr WallProfiler::GetContextPtr(Isolate* isolate) {
1090+
#if NODE_MAJOR_VERSION >= 23
10741091
if (!useCPED_) {
10751092
return curContext_.Get();
10761093
}
@@ -1088,6 +1105,9 @@ ContextPtr WallProfiler::GetContextPtr(Isolate* isolate) {
10881105

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

10931113
NAN_GETTER(WallProfiler::GetContext) {
@@ -1142,7 +1162,7 @@ void WallProfiler::OnGCStart(v8::Isolate* isolate) {
11421162
if (useCPED_) {
11431163
gcContext = GetContextPtrSignalSafe(isolate);
11441164
}
1145-
}
1165+
}
11461166
gcCount.store(curCount + 1, std::memory_order_relaxed);
11471167
std::atomic_signal_fence(std::memory_order_release);
11481168
}

0 commit comments

Comments
 (0)