Skip to content

Commit fb0f5d7

Browse files
Matt LoringFishrock123
Matt Loring
authored andcommitted
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: #2090 Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 605f6ee commit fb0f5d7

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

test/parallel/test-tick-processor.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
var fs = require('fs');
3+
var assert = require('assert');
4+
var path = require('path');
5+
var cp = require('child_process');
6+
var common = require('../common');
7+
8+
common.refreshTmpDir();
9+
10+
process.chdir(common.tmpDir);
11+
cp.execFileSync(process.execPath, ['-prof', '-pe',
12+
'function foo(n) {' +
13+
'require(\'vm\').runInDebugContext(\'Debug\');' +
14+
'return n < 2 ? n : setImmediate(function() { foo(n-1) + foo(n-2);}); };' +
15+
'setTimeout(function() { process.exit(0); }, 2000);' +
16+
'foo(40);']);
17+
var matches = fs.readdirSync(common.tmpDir).filter(function(file) {
18+
return /^isolate-/.test(file);
19+
});
20+
if (matches.length != 1) {
21+
assert.fail('There should be a single log file.');
22+
}
23+
var log = matches[0];
24+
var processor =
25+
path.join(common.testDir, '..', 'tools', 'v8-prof', getScriptName());
26+
var out = cp.execSync(processor + ' ' + log, {encoding: 'utf8'});
27+
assert(out.match(/LazyCompile.*foo/));
28+
if (process.platform === 'win32' ||
29+
process.platform === 'sunos' ||
30+
process.platform === 'freebsd') {
31+
console.log('1..0 # Skipped: C++ symbols are not mapped for this os.');
32+
return;
33+
}
34+
assert(out.match(/RunInDebugContext/));
35+
36+
function getScriptName() {
37+
switch (process.platform) {
38+
case 'darwin':
39+
return 'mac-tick-processor';
40+
case 'win32':
41+
return 'windows-tick-processor.bat';
42+
default:
43+
return 'linux-tick-processor';
44+
}
45+
}

tools/v8-prof/linux-tick-processor

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
umask 077
4+
TEMP_SCRIPT_FILE="/tmp/node-tick-processor-input-script-$$"
5+
tools_path=`cd $(dirname "$0");pwd`
6+
v8_tools="$tools_path/../../deps/v8/tools"
7+
8+
cat "$tools_path/polyfill.js" "$v8_tools/splaytree.js" "$v8_tools/codemap.js" \
9+
"$v8_tools/csvparser.js" "$v8_tools/consarray.js" \
10+
"$v8_tools/profile.js" "$v8_tools/profile_view.js" \
11+
"$v8_tools/logreader.js" "$v8_tools/tickprocessor.js" \
12+
"$v8_tools/SourceMap.js" \
13+
"$v8_tools/tickprocessor-driver.js" >> "$TEMP_SCRIPT_FILE"
14+
15+
NODE=${NODE:-node}
16+
17+
if [ ! -x "$NODE" ] && [ -x "$(dirname "$0")/../../iojs" ]; then
18+
NODE="$(dirname "$0")/../../iojs"
19+
fi
20+
21+
"$NODE" "$TEMP_SCRIPT_FILE" $@
22+
23+
rm -f "$TEMP_SCRIPT_FILE"

tools/v8-prof/mac-tick-processor

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# A wrapper script to call 'linux-tick-processor' with Mac-specific settings.
4+
5+
tools_path=`cd $(dirname "$0");pwd`
6+
v8_tools="$tools_path/../../deps/v8/tools"
7+
"$tools_path/linux-tick-processor" --mac --nm="$v8_tools/mac-nm" $@

tools/v8-prof/polyfill.js

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright 2012 the V8 project authors. All rights reserved.
2+
// Redistribution and use in source and binary forms, with or without
3+
// modification, are permitted provided that the following conditions are
4+
// met:
5+
//
6+
// * Redistributions of source code must retain the above copyright
7+
// notice, this list of conditions and the following disclaimer.
8+
// * Redistributions in binary form must reproduce the above
9+
// copyright notice, this list of conditions and the following
10+
// disclaimer in the documentation and/or other materials provided
11+
// with the distribution.
12+
// * Neither the name of Google Inc. nor the names of its
13+
// contributors may be used to endorse or promote products derived
14+
// from this software without specific prior written permission.
15+
//
16+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
// Node polyfill
29+
var fs = require('fs');
30+
var os = {
31+
system: function(name, args) {
32+
if (process.platform === 'linux' && name === 'nm') {
33+
// Filter out vdso and vsyscall entries.
34+
var arg = args[args.length - 1];
35+
if (arg === '[vdso]' ||
36+
arg == '[vsyscall]' ||
37+
/^[0-9a-f]+-[0-9a-f]+$/.test(arg)) {
38+
return '';
39+
}
40+
}
41+
return require('child_process').execFileSync(
42+
name, args, {encoding: 'utf8'});
43+
}
44+
};
45+
var print = console.log;
46+
function read(fileName) {
47+
return fs.readFileSync(fileName, 'utf8');
48+
}
49+
arguments = process.argv.slice(2);
50+
51+
// Polyfill "readline()".
52+
var fd = fs.openSync(arguments[arguments.length - 1], 'r');
53+
var buf = new Buffer(4096);
54+
var dec = new (require('string_decoder').StringDecoder)('utf-8');
55+
var line = '';
56+
versionCheck();
57+
function readline() {
58+
while (true) {
59+
var lineBreak = line.indexOf('\n');
60+
if (lineBreak !== -1) {
61+
var res = line.slice(0, lineBreak);
62+
line = line.slice(lineBreak + 1);
63+
return res;
64+
}
65+
var bytes = fs.readSync(fd, buf, 0, buf.length);
66+
line += dec.write(buf.slice(0, bytes));
67+
if (line.length === 0) {
68+
return false;
69+
}
70+
}
71+
}
72+
73+
function versionCheck() {
74+
// v8-version looks like "v8-version,$major,$minor,$build,$patch,$candidate"
75+
// whereas process.versions.v8 is either "$major.$minor.$build" or
76+
// "$major.$minor.$build.$patch".
77+
var firstLine = readline();
78+
line = firstLine + '\n' + line;
79+
firstLine = firstLine.split(',');
80+
var curVer = process.versions.v8.split('.');
81+
if (firstLine.length !== 6 && firstLine[0] !== 'v8-version') {
82+
console.log('Unable to read v8-version from log file.');
83+
return;
84+
}
85+
// Compare major, minor and build; ignore the patch and candidate fields.
86+
for (var i = 0; i < 3; i++) {
87+
if (curVer[i] !== firstLine[i + 1]) {
88+
console.log('Testing v8 version different from logging version');
89+
return;
90+
}
91+
}
92+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@echo off
2+
setlocal
3+
4+
SET tools_dir=%~dp0
5+
SET v8_tools=%tools_dir%..\..\deps\v8\tools\
6+
7+
SET temp_script=%TEMP%\node-tick-processor-input-script
8+
9+
IF NOT DEFINED NODE (SET NODE=node.exe)
10+
%NODE% --version 2> NUL
11+
if %ERRORLEVEL%==9009 (SET NODE=%~dp0\..\..\Release\iojs.exe)
12+
13+
14+
type %tools_dir%polyfill.js %v8_tools%splaytree.js %v8_tools%codemap.js^
15+
%v8_tools%csvparser.js %v8_tools%consarray.js %v8_tools%profile.js^
16+
%v8_tools%profile_view.js %v8_tools%logreader.js %v8_tools%SourceMap.js^
17+
%v8_tools%tickprocessor.js %v8_tools%tickprocessor-driver.js >> %temp_script%
18+
%NODE% %temp_script% --windows %*
19+
del %temp_script%

0 commit comments

Comments
 (0)