Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b6bdf75

Browse filesBrowse 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
Copy full SHA for b6bdf75

File tree

Expand file treeCollapse file tree

2 files changed

+61
-39
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+61
-39
lines changed
Open diff view settings
Collapse file

‎test/fixtures/linux-perf.js‎

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

3-
const crypto = require('crypto');
3+
const { spawnSync } = require("child_process");
4+
const sleepTime = new Number(process.argv[2] || "0.1");
5+
const repeat = new Number(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-
function functionOne(i) {
10-
for (let j=i; j > 0; j--) {
11-
crypto.createHash('md5').update(functionTwo(i, j)).digest("hex");
12-
}
7+
function functionOne() {
8+
functionTwo();
139
}
1410

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

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

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

Copy file name to clipboardExpand all lines: test/v8-updates/test-linux-perf.js
+52-21Lines 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-
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

3774
const 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

6799
const interpretedFunctionOneRe = /InterpretedFunction:functionOne/;
68100
const compiledFunctionOneRe = /LazyCompile:\*functionOne/;
69101
const interpretedFunctionTwoRe = /InterpretedFunction:functionTwo/;
70102
const compiledFunctionTwoRe = /LazyCompile:\*functionTwo/;
71103

72-
const output = perfScript.stdout;
73104

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.