From a244a359f89def5d971a5ca1926468e47573de3a Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Fri, 28 Nov 2025 18:54:56 +0100 Subject: [PATCH 1/3] Start using AsyncContextFrame already on Node.js 22.7.0 --- bindings/profilers/wall.cc | 24 ++++++++++++++---------- ts/test/test-time-profiler.ts | 6 ++++-- ts/test/worker.ts | 6 ++++-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/bindings/profilers/wall.cc b/bindings/profilers/wall.cc index 6c6e5db1..b06d3114 100644 --- a/bindings/profilers/wall.cc +++ b/bindings/profilers/wall.cc @@ -42,17 +42,25 @@ struct TimeTicks { static int64_t Now(); }; } // namespace base -#if NODE_MAJOR_VERSION >= 24 +#if NODE_MAJOR_VERSION >= 22 + +// Available from 22.7.0 +#define DD_WALL_USE_CPED true + namespace internal { -#if NODE_MAJOR_VERSION == 24 +#if NODE_MAJOR_VERSION < 25 struct HandleScopeData { v8::internal::Address* next; v8::internal::Address* limit; }; -#endif +#endif // NODE_MAJOR_VERSION < 25 +#if NODE_MAJOR_VERSION >= 24 constexpr int kHandleBlockSize = v8::internal::KB - 2; +#endif // NODE_MAJOR_VERSION >= 24 } // namespace internal -#endif +#else // NODE_MAJOR_VERSION >= 22 +#define DD_WALL_USE_CPED false +#endif // } // namespace v8 static int64_t Now() { @@ -61,18 +69,14 @@ static int64_t Now() { #else #define DD_WALL_USE_SIGPROF false +#define DD_WALL_USE_CPED false + static int64_t Now() { return 0; }; #endif -#if NODE_MAJOR_VERSION >= 23 -#define DD_WALL_USE_CPED true -#else -#define DD_WALL_USE_CPED false -#endif - using namespace v8; namespace dd { diff --git a/ts/test/test-time-profiler.ts b/ts/test/test-time-profiler.ts index 6c5b8e00..1c887525 100644 --- a/ts/test/test-time-profiler.ts +++ b/ts/test/test-time-profiler.ts @@ -29,8 +29,10 @@ import {satisfies} from 'semver'; import assert from 'assert'; const useCPED = - satisfies(process.versions.node, '>=24.0.0') && - !process.execArgv.includes('--no-async-context-frame'); + (satisfies(process.versions.node, '>=24.0.0') && + !process.execArgv.includes('--no-async-context-frame')) || + (satisfies(process.versions.node, '>=22.7.0') && + process.execArgv.includes('--experimental-async-context-frame')); const collectAsyncId = satisfies(process.versions.node, '>=24.0.0'); diff --git a/ts/test/worker.ts b/ts/test/worker.ts index eeffd3c3..718ffa61 100644 --- a/ts/test/worker.ts +++ b/ts/test/worker.ts @@ -13,8 +13,10 @@ const intervalMicros = 10000; const withContexts = process.platform === 'darwin' || process.platform === 'linux'; const useCPED = - satisfies(process.versions.node, '>=24.0.0') && - !process.execArgv.includes('--no-async-context-frame'); + (satisfies(process.versions.node, '>=24.0.0') && + !process.execArgv.includes('--no-async-context-frame')) || + (satisfies(process.versions.node, '>=22.7.0') && + process.execArgv.includes('--experimental-async-context-frame')); const collectAsyncId = withContexts && satisfies(process.versions.node, '>=24.0.0'); From aeecd95afa8726778b6e498933b3bafb3a90ba47 Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Mon, 1 Dec 2025 18:12:36 +0100 Subject: [PATCH 2/3] Revert "Missed adding getMetrics in one spot (#237)" This reverts commit e62349b3e124f71ebf786b9fbdddf606b9b51fb0. --- ts/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ts/src/index.ts b/ts/src/index.ts index 42454629..51cceddb 100644 --- a/ts/src/index.ts +++ b/ts/src/index.ts @@ -40,7 +40,6 @@ export const time = { v8ProfilerStuckEventLoopDetected: timeProfiler.v8ProfilerStuckEventLoopDetected, getState: timeProfiler.getState, - getMetrics: timeProfiler.getMetrics, constants: timeProfiler.constants, }; From d900d8c1fe4a7521cb50e46d0b2951376d1476c9 Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Tue, 9 Dec 2025 13:40:28 +0100 Subject: [PATCH 3/3] Fixes for CPED not working on Windows --- bindings/profilers/wall.cc | 7 ++++++- ts/test/worker.ts | 7 ++++--- ts/test/worker2.ts | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/bindings/profilers/wall.cc b/bindings/profilers/wall.cc index b06d3114..11564677 100644 --- a/bindings/profilers/wall.cc +++ b/bindings/profilers/wall.cc @@ -909,7 +909,12 @@ NAN_METHOD(WallProfiler::New) { #if !DD_WALL_USE_CPED if (useCPED) { return Nan::ThrowTypeError( - "useCPED is not supported on this Node.js version."); +#ifndef _WIN32 + "useCPED is not supported on this Node.js version." +#else + "useCPED is not supported on Windows." +#endif + ); } #endif diff --git a/ts/test/worker.ts b/ts/test/worker.ts index 718ffa61..bcc7d147 100644 --- a/ts/test/worker.ts +++ b/ts/test/worker.ts @@ -13,10 +13,11 @@ const intervalMicros = 10000; const withContexts = process.platform === 'darwin' || process.platform === 'linux'; const useCPED = - (satisfies(process.versions.node, '>=24.0.0') && + withContexts && + ((satisfies(process.versions.node, '>=24.0.0') && !process.execArgv.includes('--no-async-context-frame')) || - (satisfies(process.versions.node, '>=22.7.0') && - process.execArgv.includes('--experimental-async-context-frame')); + (satisfies(process.versions.node, '>=22.7.0') && + process.execArgv.includes('--experimental-async-context-frame'))); const collectAsyncId = withContexts && satisfies(process.versions.node, '>=24.0.0'); diff --git a/ts/test/worker2.ts b/ts/test/worker2.ts index e06f5578..eaacd07c 100644 --- a/ts/test/worker2.ts +++ b/ts/test/worker2.ts @@ -10,8 +10,11 @@ const withContexts = process.platform === 'darwin' || process.platform === 'linux'; const useCPED = - satisfies(process.versions.node, '>=24.0.0') && - !process.execArgv.includes('--no-async-context-frame'); + withContexts && + ((satisfies(process.versions.node, '>=24.0.0') && + !process.execArgv.includes('--no-async-context-frame')) || + (satisfies(process.versions.node, '>=22.7.0') && + process.execArgv.includes('--experimental-async-context-frame'))); const collectAsyncId = withContexts && satisfies(process.versions.node, '>=24.0.0');