@@ -50,18 +50,43 @@ if (common.isWindows) {
50
50
FIB = 40 ;
51
51
}
52
52
53
+ // We need to set --cpu-interval to a smaller value to make sure we can
54
+ // find our workload in the samples. 50us should be a small enough sampling
55
+ // interval for this.
56
+ const kCpuProfInterval = 50 ;
53
57
const env = {
54
58
...process . env ,
55
59
FIB ,
56
60
NODE_DEBUG_NATIVE : 'INSPECTOR_PROFILER'
57
61
} ;
58
62
63
+ // Test --cpu-prof without --cpu-prof-interval. Here we just verify that
64
+ // we manage to generate a profile.
65
+ {
66
+ tmpdir . refresh ( ) ;
67
+ const output = spawnSync ( process . execPath , [
68
+ '--cpu-prof' ,
69
+ fixtures . path ( 'workload' , 'fibonacci.js' ) ,
70
+ ] , {
71
+ cwd : tmpdir . path ,
72
+ env
73
+ } ) ;
74
+ if ( output . status !== 0 ) {
75
+ console . log ( output . stderr . toString ( ) ) ;
76
+ }
77
+ assert . strictEqual ( output . status , 0 ) ;
78
+ const profiles = getCpuProfiles ( tmpdir . path ) ;
79
+ assert . strictEqual ( profiles . length , 1 ) ;
80
+ }
81
+
59
82
// Outputs CPU profile when event loop is drained.
60
83
// TODO(joyeecheung): share the fixutres with v8 coverage tests
61
84
{
62
85
tmpdir . refresh ( ) ;
63
86
const output = spawnSync ( process . execPath , [
64
87
'--cpu-prof' ,
88
+ '--cpu-prof-interval' ,
89
+ kCpuProfInterval ,
65
90
fixtures . path ( 'workload' , 'fibonacci.js' ) ,
66
91
] , {
67
92
cwd : tmpdir . path ,
@@ -81,6 +106,8 @@ const env = {
81
106
tmpdir . refresh ( ) ;
82
107
const output = spawnSync ( process . execPath , [
83
108
'--cpu-prof' ,
109
+ '--cpu-prof-interval' ,
110
+ kCpuProfInterval ,
84
111
fixtures . path ( 'workload' , 'fibonacci-exit.js' ) ,
85
112
] , {
86
113
cwd : tmpdir . path ,
@@ -100,6 +127,8 @@ const env = {
100
127
tmpdir . refresh ( ) ;
101
128
const output = spawnSync ( process . execPath , [
102
129
'--cpu-prof' ,
130
+ '--cpu-prof-interval' ,
131
+ kCpuProfInterval ,
103
132
fixtures . path ( 'workload' , 'fibonacci-sigint.js' ) ,
104
133
] , {
105
134
cwd : tmpdir . path ,
@@ -123,7 +152,10 @@ const env = {
123
152
fixtures . path ( 'workload' , 'fibonacci-worker-argv.js' ) ,
124
153
] , {
125
154
cwd : tmpdir . path ,
126
- env
155
+ env : {
156
+ ...process . env ,
157
+ CPU_PROF_INTERVAL : kCpuProfInterval
158
+ }
127
159
} ) ;
128
160
if ( output . status !== 0 ) {
129
161
console . log ( output . stderr . toString ( ) ) ;
@@ -176,12 +208,35 @@ const env = {
176
208
`${ process . execPath } : --cpu-prof-dir must be used with --cpu-prof` ) ;
177
209
}
178
210
211
+ // --cpu-prof-interval without --cpu-prof
212
+ {
213
+ tmpdir . refresh ( ) ;
214
+ const output = spawnSync ( process . execPath , [
215
+ '--cpu-prof-interval' ,
216
+ kCpuProfInterval ,
217
+ fixtures . path ( 'workload' , 'fibonacci.js' ) ,
218
+ ] , {
219
+ cwd : tmpdir . path ,
220
+ env
221
+ } ) ;
222
+ const stderr = output . stderr . toString ( ) . trim ( ) ;
223
+ if ( output . status !== 9 ) {
224
+ console . log ( stderr ) ;
225
+ }
226
+ assert . strictEqual ( output . status , 9 ) ;
227
+ assert . strictEqual (
228
+ stderr ,
229
+ `${ process . execPath } : --cpu-prof-interval must be used with --cpu-prof` ) ;
230
+ }
231
+
179
232
// --cpu-prof-name
180
233
{
181
234
tmpdir . refresh ( ) ;
182
235
const file = path . join ( tmpdir . path , 'test.cpuprofile' ) ;
183
236
const output = spawnSync ( process . execPath , [
184
237
'--cpu-prof' ,
238
+ '--cpu-prof-interval' ,
239
+ kCpuProfInterval ,
185
240
'--cpu-prof-name' ,
186
241
'test.cpuprofile' ,
187
242
fixtures . path ( 'workload' , 'fibonacci.js' ) ,
@@ -203,6 +258,8 @@ const env = {
203
258
tmpdir . refresh ( ) ;
204
259
const output = spawnSync ( process . execPath , [
205
260
'--cpu-prof' ,
261
+ '--cpu-prof-interval' ,
262
+ kCpuProfInterval ,
206
263
'--cpu-prof-dir' ,
207
264
'prof' ,
208
265
fixtures . path ( 'workload' , 'fibonacci.js' ) ,
@@ -227,6 +284,8 @@ const env = {
227
284
const dir = path . join ( tmpdir . path , 'prof' ) ;
228
285
const output = spawnSync ( process . execPath , [
229
286
'--cpu-prof' ,
287
+ '--cpu-prof-interval' ,
288
+ kCpuProfInterval ,
230
289
'--cpu-prof-dir' ,
231
290
dir ,
232
291
fixtures . path ( 'workload' , 'fibonacci.js' ) ,
@@ -251,6 +310,8 @@ const env = {
251
310
const file = path . join ( dir , 'test.cpuprofile' ) ;
252
311
const output = spawnSync ( process . execPath , [
253
312
'--cpu-prof' ,
313
+ '--cpu-prof-interval' ,
314
+ kCpuProfInterval ,
254
315
'--cpu-prof-name' ,
255
316
'test.cpuprofile' ,
256
317
'--cpu-prof-dir' ,
@@ -274,6 +335,8 @@ const env = {
274
335
{
275
336
tmpdir . refresh ( ) ;
276
337
const output = spawnSync ( process . execPath , [
338
+ '--cpu-prof-interval' ,
339
+ kCpuProfInterval ,
277
340
'--cpu-prof-dir' ,
278
341
'prof' ,
279
342
'--cpu-prof' ,
0 commit comments