Skip to content

Commit b6bdf75

Browse files
refackBridgeAR
authored andcommitted
test,v8: skip less and stabilize test-linux-perf.js
Co-authored-by: Matheus Marchini <mat@mmarchini.me> PR-URL: #27364 Refs: nodejs/build#1774 Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 95ee3b5 commit b6bdf75

2 files changed

Lines changed: 61 additions & 39 deletions

File tree

‎test/fixtures/linux-perf.js‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
'use strict';
22

3-
constcrypto=require('crypto');
3+
const{ spawnSync }=require("child_process");
4+
constsleepTime=newNumber(process.argv[2]||"0.1");
5+
constrepeat=newNumber(process.argv[3])||5;
46

5-
// Functions should be complex enough for V8 to run them a few times before
6-
// compiling, but not complex enough to always stay in interpreted mode. They
7-
// should also take some time to run, otherwise Linux perf might miss them
8-
// entirely even when sampling at a high frequency.
9-
functionfunctionOne(i){
10-
for(letj=i;j>0;j--){
11-
crypto.createHash('md5').update(functionTwo(i,j)).digest("hex");
12-
}
7+
functionfunctionOne(){
8+
functionTwo();
139
}
1410

15-
functionfunctionTwo(x,y){
16-
letdata=((((x*y)+(x/y))*y)**(x+1)).toString();
17-
if(x%2==0){
18-
returncrypto.createHash('md5').update(data.repeat((x%100)+1)).digest("hex");
19-
}else{
20-
returncrypto.createHash('md5').update(data.repeat((y%100)+1)).digest("hex");
21-
}
11+
functionfunctionTwo(){
12+
spawnSync('sleep',[`${sleepTime}`]);
2213
}
2314

24-
for(leti=0;i<1000;i++){
25-
functionOne(i);
15+
for(leti=0;i<repeat;i++){
16+
functionOne();
2617
}

‎test/v8-updates/test-linux-perf.js‎

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,53 @@ tmpdir.refresh();
2222
if(process.config.variables.node_shared)
2323
common.skip("can't test Linux perf with shared libraries yet");
2424

25-
constperfArgs=[
25+
if(!common.isLinux)
26+
common.skip('only testing Linux for now');
27+
28+
constfrequency=99;
29+
30+
constrepeat=5;
31+
32+
// Expected number of samples we'll capture per repeat
33+
constsampleCount=10;
34+
constsleepTime=sampleCount*(1.0/frequency);
35+
36+
constperfFlags=[
2637
'record',
27-
'-F999',
38+
`-F${frequency}`,
2839
'-g',
29-
'--',
30-
process.execPath,
40+
];
41+
42+
constnodeCommonFlags=[
3143
'--perf-basic-prof',
3244
'--interpreted-frames-native-stack',
3345
'--no-turbo-inlining',// Otherwise simple functions might get inlined.
46+
];
47+
48+
constperfInterpretedFramesArgs=[
49+
...perfFlags,
50+
'--',
51+
process.execPath,
52+
...nodeCommonFlags,
53+
'--no-opt',
3454
fixtures.path('linux-perf.js'),
55+
`${sleepTime}`,
56+
`${repeat}`,
57+
];
58+
59+
constperfCompiledFramesArgs=[
60+
...perfFlags,
61+
'--',
62+
process.execPath,
63+
...nodeCommonFlags,
64+
'--always-opt',
65+
fixtures.path('linux-perf.js'),
66+
`${sleepTime}`,
67+
`${repeat}`,
68+
];
69+
70+
constperfArgsList=[
71+
perfInterpretedFramesArgs,perfCompiledFramesArgs
3572
];
3673

3774
constperfScriptArgs=[
@@ -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-
constperf=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+
letoutput='';
5784

58-
constperfScript=spawnSync('perf',perfScriptArgs,options);
85+
for(constperfArgsofperfArgsList){
86+
constperf=spawnSync('perf',perfArgs,options);
87+
assert.ifError(perf.error);
88+
if(perf.status!==0)
89+
thrownewError(`Failed to execute 'perf': ${perf.stderr}`);
5990

60-
if(perf.error)
61-
common.skip(`perf script aborted: ${perf.error.errno}`);
91+
constperfScript=spawnSync('perf',perfScriptArgs,options);
92+
assert.ifError(perfScript.error);
93+
if(perfScript.status!==0)
94+
thrownewError(`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

6799
constinterpretedFunctionOneRe=/InterpretedFunction:functionOne/;
68100
constcompiledFunctionOneRe=/LazyCompile:\*functionOne/;
69101
constinterpretedFunctionTwoRe=/InterpretedFunction:functionTwo/;
70102
constcompiledFunctionTwoRe=/LazyCompile:\*functionTwo/;
71103

72-
constoutput=perfScript.stdout;
73104

74105
assert.ok(output.match(interpretedFunctionOneRe),
75106
"Couldn't find interpreted functionOne()");

0 commit comments

Comments
 (0)