2016-09-15 01:26:52 +02:00
|
|
|
'use strict';
|
2017-12-24 22:38:11 -08:00
|
|
|
require('../common');
|
2016-09-15 01:26:52 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const cp = require('child_process');
|
|
|
|
|
2017-12-24 22:38:11 -08:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2016-09-15 01:26:52 +02:00
|
|
|
|
2023-08-22 01:41:53 +09:00
|
|
|
const LOG_FILE = tmpdir.resolve('tick-processor.log');
|
2016-09-29 10:56:15 -05:00
|
|
|
const RETRY_TIMEOUT = 150;
|
2016-09-15 01:26:52 +02:00
|
|
|
|
|
|
|
function runTest(test) {
|
|
|
|
const proc = cp.spawn(process.execPath, [
|
|
|
|
'--no_logfile_per_isolate',
|
|
|
|
'--logfile=-',
|
|
|
|
'--prof',
|
2021-03-26 08:51:08 -07:00
|
|
|
'-pe', test.code,
|
2016-09-15 01:26:52 +02:00
|
|
|
], {
|
2022-11-17 08:02:11 -05:00
|
|
|
stdio: [ 'ignore', 'pipe', 'inherit' ],
|
2016-09-15 01:26:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let ticks = '';
|
2016-10-10 23:23:18 -07:00
|
|
|
proc.stdout.on('data', (chunk) => ticks += chunk);
|
2016-09-15 01:26:52 +02:00
|
|
|
|
|
|
|
// Try to match after timeout
|
|
|
|
setTimeout(() => {
|
2017-08-21 19:01:06 +01:00
|
|
|
match(test.pattern, proc, () => ticks, test.profProcessFlags);
|
2016-09-15 01:26:52 +02:00
|
|
|
}, RETRY_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2017-08-21 19:01:06 +01:00
|
|
|
function match(pattern, parent, ticks, flags = []) {
|
2016-09-15 01:26:52 +02:00
|
|
|
// Store current ticks log
|
|
|
|
fs.writeFileSync(LOG_FILE, ticks());
|
|
|
|
|
|
|
|
const proc = cp.spawn(process.execPath, [
|
|
|
|
'--prof-process',
|
|
|
|
'--call-graph-size=10',
|
2017-08-21 19:01:06 +01:00
|
|
|
...flags,
|
2021-03-26 08:51:08 -07:00
|
|
|
LOG_FILE,
|
2016-09-15 01:26:52 +02:00
|
|
|
], {
|
2022-11-17 08:02:11 -05:00
|
|
|
stdio: [ 'ignore', 'pipe', 'inherit' ],
|
2016-09-15 01:26:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let out = '';
|
2017-08-21 19:01:06 +01:00
|
|
|
|
2016-10-10 23:23:18 -07:00
|
|
|
proc.stdout.on('data', (chunk) => out += chunk);
|
2016-09-29 10:56:15 -05:00
|
|
|
proc.stdout.once('end', () => {
|
|
|
|
proc.once('exit', () => {
|
|
|
|
fs.unlinkSync(LOG_FILE);
|
2016-09-15 01:26:52 +02:00
|
|
|
|
2016-09-29 10:56:15 -05:00
|
|
|
// Retry after timeout
|
|
|
|
if (!pattern.test(out))
|
|
|
|
return setTimeout(() => match(pattern, parent, ticks), RETRY_TIMEOUT);
|
2016-09-15 01:26:52 +02:00
|
|
|
|
2016-09-29 10:56:15 -05:00
|
|
|
parent.stdout.removeAllListeners();
|
|
|
|
parent.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
proc.stdout.removeAllListeners();
|
|
|
|
proc.kill();
|
2016-09-15 01:26:52 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.runTest = runTest;
|