Browse Source

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>
canary-base
davidmarkclements 7 years ago
committed by James M Snell
parent
commit
7c948ce233
  1. 1
      lib/internal/v8_prof_processor.js
  2. 24
      test/tick-processor/test-tick-processor-preprocess-flag.js
  3. 6
      test/tick-processor/tick-processor-base.js

1
lib/internal/v8_prof_processor.js

@ -32,6 +32,7 @@ if (process.platform === 'darwin') {
tickArguments.push.apply(tickArguments, process.argv.slice(1)); tickArguments.push.apply(tickArguments, process.argv.slice(1));
script = `(function() { script = `(function() {
arguments = ${JSON.stringify(tickArguments)}; arguments = ${JSON.stringify(tickArguments)};
function write (s) { process.stdout.write(s) }
${script} ${script}
})()`; })()`;
eval(script); eval(script);

24
test/tick-processor/test-tick-processor-preprocess-flag.js

@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
if (!common.enoughTestCpu)
common.skip('test is CPU-intensive');
if (common.isWindows ||
common.isSunOS ||
common.isAIX ||
common.isLinuxPPCBE ||
common.isFreeBSD)
common.skip('C++ symbols are not mapped for this os.');
const base = require('./tick-processor-base.js');
base.runTest({
pattern: /^{/,
code: `function f() {
require('vm').runInDebugContext('Debug');
setImmediate(function() { f(); });
};
f();`,
profProcessFlags: ['--preprocess']
});

6
test/tick-processor/tick-processor-base.js

@ -24,23 +24,25 @@ function runTest(test) {
// Try to match after timeout // Try to match after timeout
setTimeout(() => { setTimeout(() => {
match(test.pattern, proc, () => ticks); match(test.pattern, proc, () => ticks, test.profProcessFlags);
}, RETRY_TIMEOUT); }, RETRY_TIMEOUT);
} }
function match(pattern, parent, ticks) { function match(pattern, parent, ticks, flags = []) {
// Store current ticks log // Store current ticks log
fs.writeFileSync(LOG_FILE, ticks()); fs.writeFileSync(LOG_FILE, ticks());
const proc = cp.spawn(process.execPath, [ const proc = cp.spawn(process.execPath, [
'--prof-process', '--prof-process',
'--call-graph-size=10', '--call-graph-size=10',
...flags,
LOG_FILE LOG_FILE
], { ], {
stdio: [ 'ignore', 'pipe', 'inherit' ] stdio: [ 'ignore', 'pipe', 'inherit' ]
}); });
let out = ''; let out = '';
proc.stdout.on('data', (chunk) => out += chunk); proc.stdout.on('data', (chunk) => out += chunk);
proc.stdout.once('end', () => { proc.stdout.once('end', () => {
proc.once('exit', () => { proc.once('exit', () => {

Loading…
Cancel
Save