-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reduces the runtime significantly and fixes the tests to run on the CI. It is significantly more robust by accepting some fallbacks. Therefore they are moved out of pummel to sequential.
- Loading branch information
Showing
12 changed files
with
185 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
'use strict'; | ||
|
||
const { | ||
isWindows, | ||
isSunOS, | ||
isAIX, | ||
isLinuxPPCBE, | ||
isFreeBSD, | ||
skip | ||
} = require('../common'); | ||
|
||
const fs = require('fs'); | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
|
||
const tmpdir = require('./tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log'); | ||
const START_PROF_PROCESS_TIMEOUT = 400; | ||
|
||
let running = 0; | ||
let ran = 0; | ||
|
||
// The tick processor is not supported on all platforms. | ||
function isCPPSymbolsNotMapped() { | ||
if (isWindows || isSunOS || isAIX || isLinuxPPCBE || isFreeBSD) { | ||
skip('C++ symbols are not mapped for this OS.'); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function runTest(test) { | ||
if (isCPPSymbolsNotMapped()) { | ||
return; | ||
} | ||
|
||
ran++; | ||
running = 0; | ||
const proc = cp.spawn(process.execPath, [ | ||
'--no_logfile_per_isolate', | ||
'--logfile=-', | ||
'--prof', | ||
'-pe', test.code | ||
], { | ||
stdio: [ 'ignore', 'pipe', 'inherit' ] | ||
}); | ||
|
||
let ticks = ''; | ||
proc.stdout.on('data', (chunk) => ticks += chunk); | ||
|
||
// Check if the pattern is already there or not. | ||
setTimeout(() => { | ||
if (running === 0) { | ||
match(test, proc, () => ticks); | ||
} | ||
}, START_PROF_PROCESS_TIMEOUT); | ||
|
||
proc.on('exit', () => { | ||
running++; | ||
if (running === 1) { | ||
match(test, proc, () => ticks); | ||
} | ||
}); | ||
} | ||
|
||
function match(test, parent, ticks) { | ||
running++; | ||
|
||
const { pattern, profProcessFlags: flags = [] } = test; | ||
// Store current ticks log | ||
fs.writeFileSync(LOG_FILE, ticks()); | ||
|
||
const proc = cp.spawn(process.execPath, [ | ||
'--prof-process', | ||
'--call-graph-size=10', | ||
...flags, | ||
LOG_FILE | ||
], { | ||
stdio: [ 'ignore', 'pipe', 'inherit' ] | ||
}); | ||
|
||
let out = ''; | ||
|
||
proc.stdout.on('data', (chunk) => out += chunk); | ||
proc.stdout.once('end', () => { | ||
proc.once('exit', () => { | ||
fs.unlinkSync(LOG_FILE); | ||
|
||
// Retry after timeout | ||
if (!pattern.test(out)) { | ||
running--; | ||
// If the profiling is done without match, try up to ten times again | ||
// and then fail. | ||
if (running === 1) { | ||
if (ran < 10) { | ||
return runTest(test); | ||
} | ||
console.error(out); | ||
throw new Error(`${pattern} Failed`); | ||
} | ||
return; | ||
} | ||
|
||
parent.stdout.removeAllListeners(); | ||
parent.kill(); | ||
}); | ||
|
||
proc.stdout.removeAllListeners(); | ||
proc.kill(); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
runTest, | ||
isCPPSymbolsNotMapped | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
const base = require('../common/tick-processor'); | ||
|
||
base.runTest({ | ||
// If the C++ symbols are not detected by the OS, no JS is going to be | ||
// executed. | ||
pattern: /Builtin: ObjectKeys| \d [0-6]\.\d% [0-6]\.\d% JavaScript/, | ||
code: `let add = 0; | ||
const obj = { a: 5 }; | ||
function f() { | ||
for (var i = 0; i < 4e6; i++) { | ||
obj.a = i; | ||
add += Object.keys(obj).length; | ||
} | ||
return add; | ||
}; | ||
f();` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
const base = require('../common/tick-processor'); | ||
|
||
base.runTest({ | ||
// If the C++ symbols are not mapped to the OS they can end up as `UNKNOWN` or | ||
// no JS is executed at all. | ||
pattern: /MakeContext|\d\d\.\d% UNKNOWN|0 0\.0% 0\.0% JavaScript|[7-9]\d\.\d% [7-9]\d\.\d% write/, | ||
code: `function f() { | ||
for (var i = 0; i < 5e2; i++) { | ||
require('vm').createContext({}); | ||
} | ||
}; | ||
f();` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
const base = require('../common/tick-processor'); | ||
|
||
base.runTest({ | ||
pattern: /^{/, | ||
code: `function f() { | ||
for (var i = 0; i < 5e2; i++) { | ||
require('vm').createContext({}); | ||
} | ||
}; | ||
f();`, | ||
profProcessFlags: ['--preprocess'] | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
test/tick-processor/test-tick-processor-preprocess-flag.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.