node/test/parallel/test-tick-processor.js
Matt Loring 7bdf7da867 tools: run the tick processor without building v8
Currently, v8 native deps must be built in order to run the log
processor on node profiling output. These scripts use node instead
of d8 to remove this dependency.

This change was originally proposed to the v8 team but since the
changes are not v8 specific, we have moved the proposal here. See:
https://codereview.chromium.org/1179173009/

PR-URL: https://github.com/nodejs/node/pull/2090
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-08-18 02:33:41 +02:00

46 lines
1.3 KiB
JavaScript

'use strict';
var fs = require('fs');
var assert = require('assert');
var path = require('path');
var cp = require('child_process');
var common = require('../common');
common.refreshTmpDir();
process.chdir(common.tmpDir);
cp.execFileSync(process.execPath, ['-prof', '-pe',
'function foo(n) {' +
'require(\'vm\').runInDebugContext(\'Debug\');' +
'return n < 2 ? n : setImmediate(function() { foo(n-1) + foo(n-2);}); };' +
'setTimeout(function() { process.exit(0); }, 2000);' +
'foo(40);']);
var matches = fs.readdirSync(common.tmpDir).filter(function(file) {
return /^isolate-/.test(file);
});
if (matches.length != 1) {
assert.fail('There should be a single log file.');
}
var log = matches[0];
var processor =
path.join(common.testDir, '..', 'tools', 'v8-prof', getScriptName());
var out = cp.execSync(processor + ' ' + log, {encoding: 'utf8'});
assert(out.match(/LazyCompile.*foo/));
if (process.platform === 'win32' ||
process.platform === 'sunos' ||
process.platform === 'freebsd') {
console.log('1..0 # Skipped: C++ symbols are not mapped for this os.');
return;
}
assert(out.match(/RunInDebugContext/));
function getScriptName() {
switch (process.platform) {
case 'darwin':
return 'mac-tick-processor';
case 'win32':
return 'windows-tick-processor.bat';
default:
return 'linux-tick-processor';
}
}