2016-09-15 01:26:52 +02:00
|
|
|
'use strict';
|
2017-12-25 07:38:11 +01:00
|
|
|
require('../common');
|
2016-09-15 01:26:52 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const cp = require('child_process');
|
|
|
|
const path = require('path');
|
|
|
|
|
2017-12-25 07:38:11 +01:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2016-09-15 01:26:52 +02:00
|
|
|
|
2017-12-25 07:38:11 +01:00
|
|
|
const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log');
|
2016-09-29 17:56:15 +02: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',
|
|
|
|
'-pe', test.code
|
|
|
|
], {
|
2016-09-29 17:56:15 +02:00
|
|
|
stdio: [ 'ignore', 'pipe', 'inherit' ]
|
2016-09-15 01:26:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let ticks = '';
|
2016-10-11 08:23:18 +02: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 20:01:06 +02:00
|
|
|
match(test.pattern, proc, () => ticks, test.profProcessFlags);
|
2016-09-15 01:26:52 +02:00
|
|
|
}, RETRY_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2017-08-21 20:01:06 +02: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 20:01:06 +02:00
|
|
|
...flags,
|
2016-09-15 01:26:52 +02:00
|
|
|
LOG_FILE
|
|
|
|
], {
|
2016-09-29 17:56:15 +02:00
|
|
|
stdio: [ 'ignore', 'pipe', 'inherit' ]
|
2016-09-15 01:26:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let out = '';
|
2017-08-21 20:01:06 +02:00
|
|
|
|
2016-10-11 08:23:18 +02:00
|
|
|
proc.stdout.on('data', (chunk) => out += chunk);
|
2016-09-29 17:56:15 +02:00
|
|
|
proc.stdout.once('end', () => {
|
|
|
|
proc.once('exit', () => {
|
|
|
|
fs.unlinkSync(LOG_FILE);
|
2016-09-15 01:26:52 +02:00
|
|
|
|
2016-09-29 17:56:15 +02: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 17:56:15 +02:00
|
|
|
parent.stdout.removeAllListeners();
|
|
|
|
parent.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
proc.stdout.removeAllListeners();
|
|
|
|
proc.kill();
|
2016-09-15 01:26:52 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.runTest = runTest;
|