@@ -50,18 +50,43 @@ if (common.isWindows) {
5050 FIB = 40 ;
5151}
5252
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 ;
5357const env = {
5458 ...process . env ,
5559 FIB ,
5660 NODE_DEBUG_NATIVE : 'INSPECTOR_PROFILER'
5761} ;
5862
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+
5982// Outputs CPU profile when event loop is drained.
6083// TODO(joyeecheung): share the fixutres with v8 coverage tests
6184{
6285 tmpdir . refresh ( ) ;
6386 const output = spawnSync ( process . execPath , [
6487 '--cpu-prof' ,
88+ '--cpu-prof-interval' ,
89+ kCpuProfInterval ,
6590 fixtures . path ( 'workload' , 'fibonacci.js' ) ,
6691 ] , {
6792 cwd : tmpdir . path ,
@@ -81,6 +106,8 @@ const env = {
81106 tmpdir . refresh ( ) ;
82107 const output = spawnSync ( process . execPath , [
83108 '--cpu-prof' ,
109+ '--cpu-prof-interval' ,
110+ kCpuProfInterval ,
84111 fixtures . path ( 'workload' , 'fibonacci-exit.js' ) ,
85112 ] , {
86113 cwd : tmpdir . path ,
@@ -100,6 +127,8 @@ const env = {
100127 tmpdir . refresh ( ) ;
101128 const output = spawnSync ( process . execPath , [
102129 '--cpu-prof' ,
130+ '--cpu-prof-interval' ,
131+ kCpuProfInterval ,
103132 fixtures . path ( 'workload' , 'fibonacci-sigint.js' ) ,
104133 ] , {
105134 cwd : tmpdir . path ,
@@ -123,7 +152,10 @@ const env = {
123152 fixtures . path ( 'workload' , 'fibonacci-worker-argv.js' ) ,
124153 ] , {
125154 cwd : tmpdir . path ,
126- env
155+ env : {
156+ ...process . env ,
157+ CPU_PROF_INTERVAL : kCpuProfInterval
158+ }
127159 } ) ;
128160 if ( output . status !== 0 ) {
129161 console . log ( output . stderr . toString ( ) ) ;
@@ -176,12 +208,35 @@ const env = {
176208 `${ process . execPath } : --cpu-prof-dir must be used with --cpu-prof` ) ;
177209}
178210
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+
179232// --cpu-prof-name
180233{
181234 tmpdir . refresh ( ) ;
182235 const file = path . join ( tmpdir . path , 'test.cpuprofile' ) ;
183236 const output = spawnSync ( process . execPath , [
184237 '--cpu-prof' ,
238+ '--cpu-prof-interval' ,
239+ kCpuProfInterval ,
185240 '--cpu-prof-name' ,
186241 'test.cpuprofile' ,
187242 fixtures . path ( 'workload' , 'fibonacci.js' ) ,
@@ -203,6 +258,8 @@ const env = {
203258 tmpdir . refresh ( ) ;
204259 const output = spawnSync ( process . execPath , [
205260 '--cpu-prof' ,
261+ '--cpu-prof-interval' ,
262+ kCpuProfInterval ,
206263 '--cpu-prof-dir' ,
207264 'prof' ,
208265 fixtures . path ( 'workload' , 'fibonacci.js' ) ,
@@ -227,6 +284,8 @@ const env = {
227284 const dir = path . join ( tmpdir . path , 'prof' ) ;
228285 const output = spawnSync ( process . execPath , [
229286 '--cpu-prof' ,
287+ '--cpu-prof-interval' ,
288+ kCpuProfInterval ,
230289 '--cpu-prof-dir' ,
231290 dir ,
232291 fixtures . path ( 'workload' , 'fibonacci.js' ) ,
@@ -251,6 +310,8 @@ const env = {
251310 const file = path . join ( dir , 'test.cpuprofile' ) ;
252311 const output = spawnSync ( process . execPath , [
253312 '--cpu-prof' ,
313+ '--cpu-prof-interval' ,
314+ kCpuProfInterval ,
254315 '--cpu-prof-name' ,
255316 'test.cpuprofile' ,
256317 '--cpu-prof-dir' ,
@@ -274,6 +335,8 @@ const env = {
274335{
275336 tmpdir . refresh ( ) ;
276337 const output = spawnSync ( process . execPath , [
338+ '--cpu-prof-interval' ,
339+ kCpuProfInterval ,
277340 '--cpu-prof-dir' ,
278341 'prof' ,
279342 '--cpu-prof' ,
0 commit comments