Commit b8f9b047 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[log] Fix function event logging

Drive-by-fix:
 - improve log parsing by not wrapping single lines in arrays

Change-Id: Ic4c5fdeb7875c8c5db57843f583e93285026ff74
BUG: chromium:757467, chromium:850038
Reviewed-on: https://chromium-review.googlesource.com/1078753
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53547}
parent cb29d620
......@@ -112,7 +112,7 @@ LogReader.prototype.processLogChunk = function(chunk) {
*/
LogReader.prototype.processLogLine = function(line) {
if (!this.timedRange_) {
this.processLog_([line]);
this.processLogLine_(line);
return;
}
if (line.startsWith("current-time")) {
......@@ -130,7 +130,7 @@ LogReader.prototype.processLogLine = function(line) {
if (this.hasSeenTimerMarker_) {
this.logLinesSinceLastTimerMarker_.push(line);
} else if (!line.startsWith("tick")) {
this.processLog_([line]);
this.processLogLine_(line);
}
}
};
......@@ -185,9 +185,8 @@ LogReader.prototype.skipDispatch = function(dispatch) {
LogReader.prototype.dispatchLogRow_ = function(fields) {
// Obtain the dispatch.
var command = fields[0];
if (!(command in this.dispatchTable_)) return;
var dispatch = this.dispatchTable_[command];
if (dispatch === undefined) return;
if (dispatch === null || this.skipDispatch(dispatch)) {
return;
......@@ -220,11 +219,19 @@ LogReader.prototype.dispatchLogRow_ = function(fields) {
* @private
*/
LogReader.prototype.processLog_ = function(lines) {
for (var i = 0, n = lines.length; i < n; ++i, ++this.lineNum_) {
var line = lines[i];
if (!line) {
continue;
}
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) {
try {
var fields = this.csvParser_.parseLine(line);
this.dispatchLogRow_(fields);
......@@ -232,4 +239,5 @@ LogReader.prototype.processLog_ = function(lines) {
this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e));
}
}
this.lineNum_++;
};
......@@ -149,7 +149,7 @@ function text(string) {
}
function delay(t) {
return new Promise(resolve = > setTimeout(resolve, t));
return new Promise(resolve => setTimeout(resolve, t));
}
function renderParseResults(parseProcessor) {
......
......@@ -687,25 +687,35 @@ function startOf(timestamp, time) {
class ParseProcessor extends LogReader {
constructor() {
super();
let config = (processor) => {
this.dispatchTable_ = {
// Avoid accidental leaking of __proto__ properties and force this object
// to be in dictionary-mode.
__proto__: null,
// "function", {event type},
// {script file},{script id},{start position},{end position},
// {time},{timestamp},{function name}
return {
parsers: [null, parseInt, parseInt, parseInt, parseFloat, parseInt, null],
processor: processor
'function': {
parsers: [
null, null, parseInt, parseInt, parseInt, parseFloat, parseInt, null
],
processor: this.processFunctionEvent
}
};
this.dispatchTable_ = {
'parse-full': config(this.processFull),
'parse-function': config(this.processFunction),
'parse-script': config(this.processScript),
'parse-eval': config(this.processEval),
'preparse-no-resolution': config(this.processPreparseNoResolution),
'preparse-resolution': config(this.processPreparseResolution),
'first-execution': config(this.processFirstExecution),
'compile-lazy': config(this.processCompileLazy),
'compile': config(this.processCompile)
this.functionEventDispatchTable_ = {
// Avoid accidental leaking of __proto__ properties and force this object
// to be in dictionary-mode.
__proto__: null,
'full-parse': this.processFull.bind(this),
'parse-function': this.processFunction.bind(this),
'parse-script': this.processScript.bind(this),
'parse-eval': this.processEval.bind(this),
'preparse-no-resolution': this.processPreparseNoResolution.bind(this),
'preparse-resolution': this.processPreparseResolution.bind(this),
'first-execution': this.processFirstExecution.bind(this),
'compile-lazy': this.processCompileLazy.bind(this),
'compile': this.processCompile.bind(this)
'compile-eval': this.processCompileEval.bind(this)
'optimize-lazy': this.processOptimizeLazy.bind(this)
};
this.idToScript = new Map();
......@@ -778,7 +788,19 @@ class ParseProcessor extends LogReader {
];
let metrics = series.map(each => each[0]);
this.totalScript.getAccumulatedTimeMetrics(metrics, 0, this.lastEvent, 10);
};
}
processFunctionEvent(
eventName, file, scriptId, startPosition, endPosition, time, timestamp,
functionName) {
let handlerFn = this.functionEventDispatchTable_[eventName];
if (handlerFn === undefined) {
console.error('Couldn\'t find handler for function event:' + eventName);
}
handlerFn(
file, scriptId, startPosition, endPosition, time, timestamp,
functionName);
}
addEntry(entry) {
this.entries.push(entry);
......@@ -802,6 +824,9 @@ class ParseProcessor extends LogReader {
lookupFunktion(file, scriptId,
startPosition, endPosition, time, timestamp, functionName) {
if (file == "" && scriptId == -1) {
return this.lookupFunktionByRange(startPosition, endPosition);
}
let script = this.lookupScript(file, scriptId);
let funktion = script.funktionAtPosition(startPosition);
if (funktion === void 0) {
......@@ -810,6 +835,25 @@ class ParseProcessor extends LogReader {
return funktion;
}
// Iterates over all functions and tries to find matching ones.
lookupFunktionsByRange(start, end) {
let results = [];
this.idToScript.forEach(script => {
script.forEach(funktion => {
if (funktion.startPostion == start && funktion.endPosition == end) {
results.push(funktion);
}
});
});
return results;
}
lookupFunktionByRange(start, end) {
let results = this.lookupFunktionsByRange(start, end);
if (results.length != 1) throw "Could not find unique function by range";
return results[0];
}
processEval(file, scriptId, startPosition,
endPosition, time, timestamp, functionName) {
let script = this.lookupScript(file, scriptId);
......@@ -880,11 +924,10 @@ class ParseProcessor extends LogReader {
}
processCompileLazy(file, scriptId,
startPosition, endPosition, time, timestamp, functionName) {
startPosition, endPosition, time, timestamp, functionName) {
let funktion = this.lookupFunktion(...arguments);
funktion.lazyCompileTimestamp = startOf(timestamp, time);
funktion.lazyCompileTime = time;
script.firstPar
}
processCompile(file, scriptId,
......
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