2011-09-15 12:47:06 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2009-06-18 07:59:13 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fileoverview Log Reader is used to process log file produced by V8.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for processing log files.
|
|
|
|
*
|
|
|
|
* @param {Array.<Object>} dispatchTable A table used for parsing and processing
|
|
|
|
* log records.
|
2015-01-20 16:06:03 +00:00
|
|
|
* @param {boolean} timedRange Ignore ticks outside timed range.
|
2015-05-05 14:15:07 +00:00
|
|
|
* @param {boolean} pairwiseTimedRange Ignore ticks outside pairs of timer
|
|
|
|
* markers.
|
2009-06-18 07:59:13 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2015-05-05 14:15:07 +00:00
|
|
|
function LogReader(dispatchTable, timedRange, pairwiseTimedRange) {
|
2009-06-18 07:59:13 +00:00
|
|
|
/**
|
|
|
|
* @type {Array.<Object>}
|
|
|
|
*/
|
|
|
|
this.dispatchTable_ = dispatchTable;
|
2010-02-08 08:15:18 +00:00
|
|
|
|
2015-01-20 16:06:03 +00:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.timedRange_ = timedRange;
|
|
|
|
|
2015-05-05 14:15:07 +00:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.pairwiseTimedRange_ = pairwiseTimedRange;
|
|
|
|
if (pairwiseTimedRange) {
|
|
|
|
this.timedRange_ = true;
|
|
|
|
}
|
|
|
|
|
2010-02-08 08:15:18 +00:00
|
|
|
/**
|
|
|
|
* Current line.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
this.lineNum_ = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CSV lines parser.
|
2011-02-10 07:47:28 +00:00
|
|
|
* @type {CsvParser}
|
2010-02-08 08:15:18 +00:00
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
this.csvParser_ = new CsvParser();
|
2015-01-20 16:06:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Keeps track of whether we've seen a "current-time" tick yet.
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.hasSeenTimerMarker_ = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of log lines seen since last "current-time" tick.
|
|
|
|
* @type {Array.<String>}
|
|
|
|
*/
|
|
|
|
this.logLinesSinceLastTimerMarker_ = [];
|
2009-06-18 07:59:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for printing error messages.
|
|
|
|
*
|
|
|
|
* @param {string} str Error message.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
LogReader.prototype.printError = function(str) {
|
2009-06-18 07:59:13 +00:00
|
|
|
// Do nothing.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes a portion of V8 profiler event log.
|
|
|
|
*
|
|
|
|
* @param {string} chunk A portion of log.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
LogReader.prototype.processLogChunk = function(chunk) {
|
2009-06-18 07:59:13 +00:00
|
|
|
this.processLog_(chunk.split('\n'));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-02-08 08:15:18 +00:00
|
|
|
/**
|
|
|
|
* Processes a line of V8 profiler event log.
|
|
|
|
*
|
|
|
|
* @param {string} line A line of log.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
LogReader.prototype.processLogLine = function(line) {
|
2015-01-20 16:06:03 +00:00
|
|
|
if (!this.timedRange_) {
|
2018-06-06 11:03:19 +00:00
|
|
|
this.processLogLine_(line);
|
2015-01-20 16:06:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (line.startsWith("current-time")) {
|
|
|
|
if (this.hasSeenTimerMarker_) {
|
|
|
|
this.processLog_(this.logLinesSinceLastTimerMarker_);
|
|
|
|
this.logLinesSinceLastTimerMarker_ = [];
|
2015-05-05 14:15:07 +00:00
|
|
|
// In pairwise mode, a "current-time" line ends the timed range.
|
|
|
|
if (this.pairwiseTimedRange_) {
|
|
|
|
this.hasSeenTimerMarker_ = false;
|
|
|
|
}
|
2015-01-20 16:06:03 +00:00
|
|
|
} else {
|
|
|
|
this.hasSeenTimerMarker_ = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this.hasSeenTimerMarker_) {
|
|
|
|
this.logLinesSinceLastTimerMarker_.push(line);
|
|
|
|
} else if (!line.startsWith("tick")) {
|
2018-06-06 11:03:19 +00:00
|
|
|
this.processLogLine_(line);
|
2015-01-20 16:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-08 08:15:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-18 07:59:13 +00:00
|
|
|
/**
|
|
|
|
* Processes stack record.
|
|
|
|
*
|
|
|
|
* @param {number} pc Program counter.
|
Fix issue 553: function frame is skipped in profile when compare stub is called.
The problem appeared due to a fact that stubs doesn't create a stack
frame, reusing the stack frame of the caller function. When building
stack traces, the current function is retrieved from PC, and its
callees are retrieved by traversing the stack backwards. Thus, for
stubs, the stub itself was discovered via PC, and then stub's caller's
caller was retrieved from stack.
To fix this problem, a pointer to JSFunction object is now captured
from the topmost stack frame, and is saved into stack trace log
record. Then a simple heuristics is applied whether a referred
function should be added to decoded stack, or not, to avoid reporting
the same function twice (from PC and from the pointer.)
BUG=553
TEST=added to mjsunit/tools/tickprocessor
Review URL: http://codereview.chromium.org/546089
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-01-21 16:42:41 +00:00
|
|
|
* @param {number} func JS Function.
|
2009-06-18 07:59:13 +00:00
|
|
|
* @param {Array.<string>} stack String representation of a stack.
|
|
|
|
* @return {Array.<number>} Processed stack.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
LogReader.prototype.processStack = function(pc, func, stack) {
|
Fix issue 553: function frame is skipped in profile when compare stub is called.
The problem appeared due to a fact that stubs doesn't create a stack
frame, reusing the stack frame of the caller function. When building
stack traces, the current function is retrieved from PC, and its
callees are retrieved by traversing the stack backwards. Thus, for
stubs, the stub itself was discovered via PC, and then stub's caller's
caller was retrieved from stack.
To fix this problem, a pointer to JSFunction object is now captured
from the topmost stack frame, and is saved into stack trace log
record. Then a simple heuristics is applied whether a referred
function should be added to decoded stack, or not, to avoid reporting
the same function twice (from PC and from the pointer.)
BUG=553
TEST=added to mjsunit/tools/tickprocessor
Review URL: http://codereview.chromium.org/546089
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-01-21 16:42:41 +00:00
|
|
|
var fullStack = func ? [pc, func] : [pc];
|
2009-06-18 07:59:13 +00:00
|
|
|
var prevFrame = pc;
|
|
|
|
for (var i = 0, n = stack.length; i < n; ++i) {
|
|
|
|
var frame = stack[i];
|
|
|
|
var firstChar = frame.charAt(0);
|
|
|
|
if (firstChar == '+' || firstChar == '-') {
|
|
|
|
// An offset from the previous frame.
|
|
|
|
prevFrame += parseInt(frame, 16);
|
|
|
|
fullStack.push(prevFrame);
|
|
|
|
// Filter out possible 'overflow' string.
|
|
|
|
} else if (firstChar != 'o') {
|
|
|
|
fullStack.push(parseInt(frame, 16));
|
2014-10-17 15:44:02 +00:00
|
|
|
} else {
|
2017-03-17 12:39:26 +00:00
|
|
|
this.printError("dropping: " + frame);
|
2009-06-18 07:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return fullStack;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a particular dispatch must be skipped.
|
|
|
|
*
|
|
|
|
* @param {!Object} dispatch Dispatch record.
|
|
|
|
* @return {boolean} True if dispatch must be skipped.
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
LogReader.prototype.skipDispatch = function(dispatch) {
|
2009-06-18 07:59:13 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2018-06-20 12:08:47 +00:00
|
|
|
// Parses dummy variable for readability;
|
|
|
|
const parseString = 'parse-string';
|
|
|
|
const parseVarArgs = 'parse-var-args';
|
2009-06-18 07:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does a dispatch of a log record.
|
|
|
|
*
|
|
|
|
* @param {Array.<string>} fields Log record.
|
|
|
|
* @private
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
LogReader.prototype.dispatchLogRow_ = function(fields) {
|
2009-06-18 07:59:13 +00:00
|
|
|
// Obtain the dispatch.
|
|
|
|
var command = fields[0];
|
|
|
|
var dispatch = this.dispatchTable_[command];
|
2018-06-06 11:03:19 +00:00
|
|
|
if (dispatch === undefined) return;
|
2009-06-18 07:59:13 +00:00
|
|
|
|
|
|
|
if (dispatch === null || this.skipDispatch(dispatch)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse fields.
|
|
|
|
var parsedFields = [];
|
|
|
|
for (var i = 0; i < dispatch.parsers.length; ++i) {
|
|
|
|
var parser = dispatch.parsers[i];
|
2018-06-20 12:08:47 +00:00
|
|
|
if (parser === parseString) {
|
2009-06-18 07:59:13 +00:00
|
|
|
parsedFields.push(fields[1 + i]);
|
|
|
|
} else if (typeof parser == 'function') {
|
|
|
|
parsedFields.push(parser(fields[1 + i]));
|
2018-06-20 12:08:47 +00:00
|
|
|
} else if (parser === parseVarArgs) {
|
2009-06-18 07:59:13 +00:00
|
|
|
// var-args
|
|
|
|
parsedFields.push(fields.slice(1 + i));
|
|
|
|
break;
|
2018-06-20 12:08:47 +00:00
|
|
|
} else {
|
|
|
|
throw new Error("Invalid log field parser: " + parser);
|
2009-06-18 07:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run the processor.
|
|
|
|
dispatch.processor.apply(this, parsedFields);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes log lines.
|
|
|
|
*
|
|
|
|
* @param {Array.<string>} lines Log lines.
|
|
|
|
* @private
|
|
|
|
*/
|
2011-02-10 07:47:28 +00:00
|
|
|
LogReader.prototype.processLog_ = function(lines) {
|
2018-06-06 11:03:19 +00:00
|
|
|
for (var i = 0, n = lines.length; i < n; ++i) {
|
|
|
|
this.processLogLine_(lines[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes a single log line.
|
|
|
|
*
|
|
|
|
* @param {String} a log line
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
LogReader.prototype.processLogLine_ = function(line) {
|
|
|
|
if (line.length > 0) {
|
2010-02-08 08:15:18 +00:00
|
|
|
try {
|
|
|
|
var fields = this.csvParser_.parseLine(line);
|
2009-06-18 07:59:13 +00:00
|
|
|
this.dispatchLogRow_(fields);
|
2010-02-08 08:15:18 +00:00
|
|
|
} catch (e) {
|
|
|
|
this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e));
|
2009-08-17 09:31:58 +00:00
|
|
|
}
|
2009-06-18 07:59:13 +00:00
|
|
|
}
|
2018-06-06 11:03:19 +00:00
|
|
|
this.lineNum_++;
|
2009-06-18 07:59:13 +00:00
|
|
|
};
|