2017-02-20 09:20:42 +00:00
|
|
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
function inherits(childCtor, parentCtor) {
|
|
|
|
childCtor.prototype.__proto__ = parentCtor.prototype;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A thin wrapper around shell's 'read' function showing a file name on error.
|
|
|
|
*/
|
|
|
|
function readFile(fileName) {
|
|
|
|
try {
|
|
|
|
return read(fileName);
|
|
|
|
} catch (e) {
|
|
|
|
print(fileName + ': ' + (e.message || e));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parser for dynamic code optimization state.
|
|
|
|
*/
|
|
|
|
function parseState(s) {
|
|
|
|
switch (s) {
|
|
|
|
case "": return Profile.CodeState.COMPILED;
|
|
|
|
case "~": return Profile.CodeState.OPTIMIZABLE;
|
|
|
|
case "*": return Profile.CodeState.OPTIMIZED;
|
|
|
|
}
|
|
|
|
throw new Error("unknown code state: " + s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function IcProcessor() {
|
2020-07-14 16:26:35 +00:00
|
|
|
var propertyICParser = [
|
|
|
|
parseInt, parseInt, parseInt, parseInt, parseString, parseString,
|
|
|
|
parseInt, parseString, parseString, parseString];
|
2017-02-20 09:20:42 +00:00
|
|
|
LogReader.call(this, {
|
|
|
|
'code-creation': {
|
2018-06-20 12:08:47 +00:00
|
|
|
parsers: [parseString, parseInt, parseInt, parseInt, parseInt,
|
|
|
|
parseString, parseVarArgs],
|
2017-02-20 09:20:42 +00:00
|
|
|
processor: this.processCodeCreation },
|
|
|
|
'code-move': { parsers: [parseInt, parseInt],
|
|
|
|
processor: this.processCodeMove },
|
|
|
|
'code-delete': { parsers: [parseInt],
|
|
|
|
processor: this.processCodeDelete },
|
|
|
|
'sfi-move': { parsers: [parseInt, parseInt],
|
|
|
|
processor: this.processFunctionMove },
|
2019-01-17 15:09:20 +00:00
|
|
|
'LoadGlobalIC': {
|
|
|
|
parsers : propertyICParser,
|
|
|
|
processor: this.processPropertyIC.bind(this, "LoadGlobalIC") },
|
|
|
|
'StoreGlobalIC': {
|
|
|
|
parsers : propertyICParser,
|
|
|
|
processor: this.processPropertyIC.bind(this, "StoreGlobalIC") },
|
2017-02-20 09:20:42 +00:00
|
|
|
'LoadIC': {
|
|
|
|
parsers : propertyICParser,
|
|
|
|
processor: this.processPropertyIC.bind(this, "LoadIC") },
|
|
|
|
'StoreIC': {
|
|
|
|
parsers : propertyICParser,
|
|
|
|
processor: this.processPropertyIC.bind(this, "StoreIC") },
|
|
|
|
'KeyedLoadIC': {
|
|
|
|
parsers : propertyICParser,
|
|
|
|
processor: this.processPropertyIC.bind(this, "KeyedLoadIC") },
|
|
|
|
'KeyedStoreIC': {
|
|
|
|
parsers : propertyICParser,
|
|
|
|
processor: this.processPropertyIC.bind(this, "KeyedStoreIC") },
|
2018-03-02 20:30:34 +00:00
|
|
|
'StoreInArrayLiteralIC': {
|
|
|
|
parsers : propertyICParser,
|
|
|
|
processor: this.processPropertyIC.bind(this, "StoreInArrayLiteralIC") },
|
2017-02-20 09:20:42 +00:00
|
|
|
});
|
|
|
|
this.profile_ = new Profile();
|
|
|
|
|
2019-01-17 15:09:20 +00:00
|
|
|
this.LoadGlobalIC = 0;
|
|
|
|
this.StoreGlobalIC = 0;
|
2017-02-20 09:20:42 +00:00
|
|
|
this.LoadIC = 0;
|
|
|
|
this.StoreIC = 0;
|
|
|
|
this.KeyedLoadIC = 0;
|
|
|
|
this.KeyedStoreIC = 0;
|
2018-03-02 20:30:34 +00:00
|
|
|
this.StoreInArrayLiteralIC = 0;
|
2017-02-20 09:20:42 +00:00
|
|
|
}
|
|
|
|
inherits(IcProcessor, LogReader);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
IcProcessor.prototype.printError = function(str) {
|
|
|
|
print(str);
|
|
|
|
};
|
|
|
|
|
2017-04-11 14:39:25 +00:00
|
|
|
IcProcessor.prototype.processString = function(string) {
|
|
|
|
var end = string.length;
|
|
|
|
var current = 0;
|
|
|
|
var next = 0;
|
|
|
|
var line;
|
|
|
|
var i = 0;
|
|
|
|
var entry;
|
|
|
|
while (current < end) {
|
|
|
|
next = string.indexOf("\n", current);
|
|
|
|
if (next === -1) break;
|
|
|
|
i++;
|
|
|
|
line = string.substring(current, next);
|
|
|
|
current = next + 1;
|
|
|
|
this.processLogLine(line);
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 09:20:42 +00:00
|
|
|
|
|
|
|
IcProcessor.prototype.processLogFile = function(fileName) {
|
2017-04-11 14:39:25 +00:00
|
|
|
this.collectEntries = true
|
2017-02-20 09:20:42 +00:00
|
|
|
this.lastLogFileName_ = fileName;
|
|
|
|
var line;
|
|
|
|
while (line = readline()) {
|
|
|
|
this.processLogLine(line);
|
|
|
|
}
|
|
|
|
print();
|
|
|
|
print("=====================");
|
2019-01-17 15:09:20 +00:00
|
|
|
print("LoadGlobal: " + this.LoadGlobalIC);
|
|
|
|
print("StoreGlobal: " + this.StoreGlobalIC);
|
2017-02-20 09:20:42 +00:00
|
|
|
print("Load: " + this.LoadIC);
|
|
|
|
print("Store: " + this.StoreIC);
|
|
|
|
print("KeyedLoad: " + this.KeyedLoadIC);
|
|
|
|
print("KeyedStore: " + this.KeyedStoreIC);
|
2018-03-02 20:30:34 +00:00
|
|
|
print("StoreInArrayLiteral: " + this.StoreInArrayLiteralIC);
|
2017-02-20 09:20:42 +00:00
|
|
|
};
|
|
|
|
|
2017-04-11 14:39:25 +00:00
|
|
|
IcProcessor.prototype.addEntry = function(entry) {
|
|
|
|
this.entries.push(entry);
|
|
|
|
}
|
2017-02-20 09:20:42 +00:00
|
|
|
|
|
|
|
IcProcessor.prototype.processCodeCreation = function(
|
2017-04-11 14:39:25 +00:00
|
|
|
type, kind, timestamp, start, size, name, maybe_func) {
|
2017-02-20 09:20:42 +00:00
|
|
|
if (maybe_func.length) {
|
|
|
|
var funcAddr = parseInt(maybe_func[0]);
|
|
|
|
var state = parseState(maybe_func[1]);
|
2017-04-11 14:39:25 +00:00
|
|
|
this.profile_.addFuncCode(type, name, timestamp, start, size, funcAddr, state);
|
2017-02-20 09:20:42 +00:00
|
|
|
} else {
|
2017-04-11 14:39:25 +00:00
|
|
|
this.profile_.addCode(type, name, timestamp, start, size);
|
2017-02-20 09:20:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
IcProcessor.prototype.processCodeMove = function(from, to) {
|
|
|
|
this.profile_.moveCode(from, to);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
IcProcessor.prototype.processCodeDelete = function(start) {
|
|
|
|
this.profile_.deleteCode(start);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
IcProcessor.prototype.processFunctionMove = function(from, to) {
|
|
|
|
this.profile_.moveFunc(from, to);
|
|
|
|
};
|
|
|
|
|
|
|
|
IcProcessor.prototype.formatName = function(entry) {
|
|
|
|
if (!entry) return "<unknown>"
|
|
|
|
var name = entry.func.getName();
|
|
|
|
var re = /(.*):[0-9]+:[0-9]+$/;
|
|
|
|
var array = re.exec(name);
|
|
|
|
if (!array) return name;
|
2017-04-25 12:01:18 +00:00
|
|
|
return entry.getState() + array[1];
|
2017-02-20 09:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IcProcessor.prototype.processPropertyIC = function (
|
2020-07-14 16:26:35 +00:00
|
|
|
type, pc, time, line, column, old_state, new_state, map, name, modifier,
|
|
|
|
slow_reason) {
|
|
|
|
this[type]++;
|
|
|
|
let entry = this.profile_.findEntry(pc);
|
|
|
|
print(
|
|
|
|
type + ' (' + old_state + '->' + new_state + modifier + ') at ' +
|
|
|
|
this.formatName(entry) + ':' + line + ':' + column + ' ' + name +
|
|
|
|
' (map 0x' + map.toString(16) + ')' +
|
|
|
|
(slow_reason ? ' ' + slow_reason : '') + 'time: ' + time);
|
2017-02-20 09:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-14 16:26:35 +00:00
|
|
|
|
2017-10-23 22:47:02 +00:00
|
|
|
class ArgumentsProcessor extends BaseArgumentsProcessor {
|
|
|
|
getArgsDispatch() {
|
|
|
|
return {
|
|
|
|
'--range': ['range', 'auto,auto',
|
|
|
|
'Specify the range limit as [start],[end]'],
|
|
|
|
'--source-map': ['sourceMap', null,
|
|
|
|
'Specify the source map that should be used for output']
|
|
|
|
};
|
2017-02-20 09:20:42 +00:00
|
|
|
}
|
2017-10-23 22:47:02 +00:00
|
|
|
getDefaultResults() {
|
|
|
|
return {
|
|
|
|
logFileName: 'v8.log',
|
|
|
|
range: 'auto,auto',
|
|
|
|
};
|
2017-02-20 09:20:42 +00:00
|
|
|
}
|
2017-10-23 22:47:02 +00:00
|
|
|
}
|