@@ -22,16 +22,53 @@ tmpdir.refresh();
2222if ( process . config . variables . node_shared )
2323 common . skip ( "can't test Linux perf with shared libraries yet" ) ;
2424
25- const perfArgs = [
25+ if ( ! common . isLinux )
26+ common . skip ( 'only testing Linux for now' ) ;
27+
28+ const frequency = 99 ;
29+
30+ const repeat = 5 ;
31+
32+ // Expected number of samples we'll capture per repeat
33+ const sampleCount = 10 ;
34+ const sleepTime = sampleCount * ( 1.0 / frequency ) ;
35+
36+ const perfFlags = [
2637 'record' ,
27- '-F999' ,
38+ `-F ${ frequency } ` ,
2839 '-g' ,
29- '--' ,
30- process . execPath ,
40+ ] ;
41+
42+ const nodeCommonFlags = [
3143 '--perf-basic-prof' ,
3244 '--interpreted-frames-native-stack' ,
3345 '--no-turbo-inlining' , // Otherwise simple functions might get inlined.
46+ ] ;
47+
48+ const perfInterpretedFramesArgs = [
49+ ...perfFlags ,
50+ '--' ,
51+ process . execPath ,
52+ ...nodeCommonFlags ,
53+ '--no-opt' ,
3454 fixtures . path ( 'linux-perf.js' ) ,
55+ `${ sleepTime } ` ,
56+ `${ repeat } ` ,
57+ ] ;
58+
59+ const perfCompiledFramesArgs = [
60+ ...perfFlags ,
61+ '--' ,
62+ process . execPath ,
63+ ...nodeCommonFlags ,
64+ '--always-opt' ,
65+ fixtures . path ( 'linux-perf.js' ) ,
66+ `${ sleepTime } ` ,
67+ `${ repeat } ` ,
68+ ] ;
69+
70+ const perfArgsList = [
71+ perfInterpretedFramesArgs , perfCompiledFramesArgs
3572] ;
3673
3774const perfScriptArgs = [
@@ -43,33 +80,27 @@ const options = {
4380 encoding : 'utf-8' ,
4481} ;
4582
46- if ( ! common . isLinux )
47- common . skip ( 'only testing Linux for now' ) ;
48-
49- const perf = spawnSync ( 'perf' , perfArgs , options ) ;
50-
51- if ( perf . error && perf . error . errno === 'ENOENT' )
52- common . skip ( 'perf not found on system' ) ;
53-
54- if ( perf . status !== 0 ) {
55- common . skip ( `Failed to execute perf: ${ perf . stderr } ` ) ;
56- }
83+ let output = '' ;
5784
58- const perfScript = spawnSync ( 'perf' , perfScriptArgs , options ) ;
85+ for ( const perfArgs of perfArgsList ) {
86+ const perf = spawnSync ( 'perf' , perfArgs , options ) ;
87+ assert . ifError ( perf . error ) ;
88+ if ( perf . status !== 0 )
89+ throw new Error ( `Failed to execute 'perf': ${ perf . stderr } ` ) ;
5990
60- if ( perf . error )
61- common . skip ( `perf script aborted: ${ perf . error . errno } ` ) ;
91+ const perfScript = spawnSync ( 'perf' , perfScriptArgs , options ) ;
92+ assert . ifError ( perfScript . error ) ;
93+ if ( perfScript . status !== 0 )
94+ throw new Error ( `Failed to execute perf script: ${ perfScript . stderr } ` ) ;
6295
63- if ( perfScript . status !== 0 ) {
64- common . skip ( `Failed to execute perf script: ${ perfScript . stderr } ` ) ;
96+ output += perfScript . stdout ;
6597}
6698
6799const interpretedFunctionOneRe = / I n t e r p r e t e d F u n c t i o n : f u n c t i o n O n e / ;
68100const compiledFunctionOneRe = / L a z y C o m p i l e : \* f u n c t i o n O n e / ;
69101const interpretedFunctionTwoRe = / I n t e r p r e t e d F u n c t i o n : f u n c t i o n T w o / ;
70102const compiledFunctionTwoRe = / L a z y C o m p i l e : \* f u n c t i o n T w o / ;
71103
72- const output = perfScript . stdout ;
73104
74105assert . ok ( output . match ( interpretedFunctionOneRe ) ,
75106 "Couldn't find interpreted functionOne()" ) ;
0 commit comments