0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/tick-processor/tick-processor-base.js
davidmarkclements 7c948ce233 fix --prof-process --preprocess flag
This is a one-line fix to prevent the --preprocess
option (used with --prof-process to output JSON)
to cause an isolate log file profiling process to crash.

PR-URL: https://github.com/nodejs/node/pull/14966
Reviewed-By: Luca Maraschi <luca.maraschi@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-08-23 08:19:14 -07:00

65 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
const cp = require('child_process');
const path = require('path');
common.refreshTmpDir();
const LOG_FILE = path.join(common.tmpDir, 'tick-processor.log');
const RETRY_TIMEOUT = 150;
function runTest(test) {
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);
// Try to match after timeout
setTimeout(() => {
match(test.pattern, proc, () => ticks, test.profProcessFlags);
}, RETRY_TIMEOUT);
}
function match(pattern, parent, ticks, flags = []) {
// 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))
return setTimeout(() => match(pattern, parent, ticks), RETRY_TIMEOUT);
parent.stdout.removeAllListeners();
parent.kill();
});
proc.stdout.removeAllListeners();
proc.kill();
});
}
exports.runTest = runTest;