Profiler tick processor: exploit d8's readline to avoid reading

entire file prior to parsing it. This allows processing of huge
log files (over 200 MB.)

Review URL: http://codereview.chromium.org/574015

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3811 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2f0f6fac
...@@ -16,8 +16,17 @@ else ...@@ -16,8 +16,17 @@ else
[ -x $d8_exec ] || scons -j4 -C $D8_PATH -Y $tools_path/.. d8 [ -x $d8_exec ] || scons -j4 -C $D8_PATH -Y $tools_path/.. d8
fi fi
# find the name of the log file to process, it must not start with a dash.
log_file="v8.log"
for arg in "$@"
do
if [[ "${arg}" != -* ]]; then
log_file=${arg}
fi
done
# nm spits out 'no symbols found' messages to stderr. # nm spits out 'no symbols found' messages to stderr.
$d8_exec $tools_path/splaytree.js $tools_path/codemap.js \ cat $log_file | $d8_exec $tools_path/splaytree.js $tools_path/codemap.js \
$tools_path/csvparser.js $tools_path/consarray.js \ $tools_path/csvparser.js $tools_path/consarray.js \
$tools_path/profile.js $tools_path/profile_view.js \ $tools_path/profile.js $tools_path/profile_view.js \
$tools_path/logreader.js $tools_path/tickprocessor.js \ $tools_path/logreader.js $tools_path/tickprocessor.js \
......
...@@ -76,6 +76,18 @@ devtools.profiler.LogReader = function(dispatchTable) { ...@@ -76,6 +76,18 @@ devtools.profiler.LogReader = function(dispatchTable) {
* @type {Array.<string>} * @type {Array.<string>}
*/ */
this.backRefs_ = []; this.backRefs_ = [];
/**
* Current line.
* @type {number}
*/
this.lineNum_ = 0;
/**
* CSV lines parser.
* @type {devtools.profiler.CsvParser}
*/
this.csvParser_ = new devtools.profiler.CsvParser();
}; };
...@@ -135,6 +147,16 @@ devtools.profiler.LogReader.prototype.processLogChunk = function(chunk) { ...@@ -135,6 +147,16 @@ devtools.profiler.LogReader.prototype.processLogChunk = function(chunk) {
}; };
/**
* Processes a line of V8 profiler event log.
*
* @param {string} line A line of log.
*/
devtools.profiler.LogReader.prototype.processLogLine = function(line) {
this.processLog_([line]);
};
/** /**
* Processes stack record. * Processes stack record.
* *
...@@ -280,25 +302,20 @@ devtools.profiler.LogReader.prototype.processAlias_ = function( ...@@ -280,25 +302,20 @@ devtools.profiler.LogReader.prototype.processAlias_ = function(
* @private * @private
*/ */
devtools.profiler.LogReader.prototype.processLog_ = function(lines) { devtools.profiler.LogReader.prototype.processLog_ = function(lines) {
var csvParser = new devtools.profiler.CsvParser(); for (var i = 0, n = lines.length; i < n; ++i, ++this.lineNum_) {
try {
for (var i = 0, n = lines.length; i < n; ++i) {
var line = lines[i]; var line = lines[i];
if (!line) { if (!line) {
continue; continue;
} }
try {
if (line.charAt(0) == '#' || if (line.charAt(0) == '#' ||
line.substr(0, line.indexOf(',')) in this.backRefsCommands_) { line.substr(0, line.indexOf(',')) in this.backRefsCommands_) {
line = this.expandBackRef_(line); line = this.expandBackRef_(line);
} }
var fields = csvParser.parseLine(line); var fields = this.csvParser_.parseLine(line);
this.dispatchLogRow_(fields); this.dispatchLogRow_(fields);
}
} catch (e) { } catch (e) {
// An error on the last line is acceptable since log file can be truncated. this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e));
if (i < n - 1) {
this.printError('line ' + (i + 1) + ': ' + (e.message || e));
throw e;
} }
} }
}; };
......
...@@ -262,8 +262,10 @@ TickProcessor.prototype.isJsCode = function(name) { ...@@ -262,8 +262,10 @@ TickProcessor.prototype.isJsCode = function(name) {
TickProcessor.prototype.processLogFile = function(fileName) { TickProcessor.prototype.processLogFile = function(fileName) {
this.lastLogFileName_ = fileName; this.lastLogFileName_ = fileName;
var contents = readFile(fileName); var line;
this.processLogChunk(contents); while (line = readline()) {
this.processLogLine(line);
}
}; };
......
...@@ -2,4 +2,28 @@ ...@@ -2,4 +2,28 @@
SET tools_dir=%~dp0 SET tools_dir=%~dp0
%tools_dir%..\d8 %tools_dir%splaytree.js %tools_dir%codemap.js %tools_dir%csvparser.js %tools_dir%consarray.js %tools_dir%profile.js %tools_dir%profile_view.js %tools_dir%logreader.js %tools_dir%tickprocessor.js %tools_dir%tickprocessor-driver.js -- --windows %* SET log_file=v8.log
rem find the name of the log file to process, it must not start with a dash.
rem we prepend cmdline args with a number (in fact, any letter or number)
rem to cope with empty arguments.
SET arg1=1%1
IF NOT %arg1:~0,2% == 1 (IF NOT %arg1:~0,2% == 1- SET log_file=%1)
SET arg2=2%2
IF NOT %arg2:~0,2% == 2 (IF NOT %arg2:~0,2% == 2- SET log_file=%2)
SET arg3=3%3
IF NOT %arg3:~0,2% == 3 (IF NOT %arg3:~0,2% == 3- SET log_file=%3)
SET arg4=4%4
IF NOT %arg4:~0,2% == 4 (IF NOT %arg4:~0,2% == 4- SET log_file=%4)
SET arg5=5%5
IF NOT %arg5:~0,2% == 5 (IF NOT %arg5:~0,2% == 5- SET log_file=%5)
SET arg6=6%6
IF NOT %arg6:~0,2% == 6 (IF NOT %arg6:~0,2% == 6- SET log_file=%6)
SET arg7=7%7
IF NOT %arg7:~0,2% == 7 (IF NOT %arg7:~0,2% == 7- SET log_file=%7)
SET arg8=8%8
IF NOT %arg8:~0,2% == 8 (IF NOT %arg8:~0,2% == 8- SET log_file=%8)
SET arg9=9%9
IF NOT %arg9:~0,2% == 9 (IF NOT %arg9:~0,2% == 9- SET log_file=%9)
type %log_file% | %tools_dir%..\d8 %tools_dir%splaytree.js %tools_dir%codemap.js %tools_dir%csvparser.js %tools_dir%consarray.js %tools_dir%profile.js %tools_dir%profile_view.js %tools_dir%logreader.js %tools_dir%tickprocessor.js %tools_dir%tickprocessor-driver.js -- --windows %*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment