@@ -22,16 +22,53 @@ tmpdir.refresh();
22
22
if ( process . config . variables . node_shared )
23
23
common . skip ( "can't test Linux perf with shared libraries yet" ) ;
24
24
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 = [
26
37
'record' ,
27
- '-F999' ,
38
+ `-F ${ frequency } ` ,
28
39
'-g' ,
29
- '--' ,
30
- process . execPath ,
40
+ ] ;
41
+
42
+ const nodeCommonFlags = [
31
43
'--perf-basic-prof' ,
32
44
'--interpreted-frames-native-stack' ,
33
45
'--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' ,
34
54
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
35
72
] ;
36
73
37
74
const perfScriptArgs = [
@@ -43,33 +80,27 @@ const options = {
43
80
encoding : 'utf-8' ,
44
81
} ;
45
82
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 = '' ;
57
84
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 } ` ) ;
59
90
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 } ` ) ;
62
95
63
- if ( perfScript . status !== 0 ) {
64
- common . skip ( `Failed to execute perf script: ${ perfScript . stderr } ` ) ;
96
+ output += perfScript . stdout ;
65
97
}
66
98
67
99
const 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 / ;
68
100
const compiledFunctionOneRe = / L a z y C o m p i l e : \* f u n c t i o n O n e / ;
69
101
const 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 / ;
70
102
const compiledFunctionTwoRe = / L a z y C o m p i l e : \* f u n c t i o n T w o / ;
71
103
72
- const output = perfScript . stdout ;
73
104
74
105
assert . ok ( output . match ( interpretedFunctionOneRe ) ,
75
106
"Couldn't find interpreted functionOne()" ) ;
0 commit comments