@@ -23,9 +23,15 @@ import {hrtime} from 'process';
23
23
import { Label , Profile } from 'pprof-format' ;
24
24
import { AssertionError } from 'assert' ;
25
25
import { GenerateTimeLabelsArgs , LabelSet } from '../src/v8-types' ;
26
+ import { satisfies } from 'semver' ;
27
+ import { AsyncLocalStorage } from 'async_hooks' ;
26
28
27
29
const assert = require ( 'assert' ) ;
28
30
31
+ const useCPED =
32
+ satisfies ( process . versions . node , '>=24.0.0' ) &&
33
+ ! process . execArgv . includes ( '--no-async-context-frame' ) ;
34
+
29
35
const PROFILE_OPTIONS = {
30
36
durationMillis : 500 ,
31
37
intervalMicros : 1000 ,
@@ -49,7 +55,14 @@ describe('Time Profiler', () => {
49
55
durationMillis : PROFILE_OPTIONS . durationMillis ,
50
56
withContexts : true ,
51
57
lineNumbers : false ,
58
+ useCPED,
52
59
} ) ;
60
+ let als ;
61
+ if ( useCPED ) {
62
+ // Ensure an async context frame is created to hold the profiler context.
63
+ als = new AsyncLocalStorage ( ) ;
64
+ als . enterWith ( 1 ) ;
65
+ }
53
66
const initialContext : { [ key : string ] : string } = { } ;
54
67
time . setContext ( initialContext ) ;
55
68
const kSampleCount = time . constants . kSampleCount ;
@@ -102,7 +115,14 @@ describe('Time Profiler', () => {
102
115
durationMillis : PROFILE_OPTIONS . durationMillis ,
103
116
withContexts : true ,
104
117
lineNumbers : false ,
118
+ useCPED,
105
119
} ) ;
120
+ let als ;
121
+ if ( useCPED ) {
122
+ // Ensure an async context frame is created to hold the profiler context.
123
+ als = new AsyncLocalStorage ( ) ;
124
+ als . enterWith ( 1 ) ;
125
+ }
106
126
// By repeating the test few times, we also exercise the profiler
107
127
// start-stop overlap behavior.
108
128
const repeats = 3 ;
0 commit comments