2020-09-02 13:17:35 +00:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
2020-11-03 08:01:33 +00:00
|
|
|
import {LogReader, parseString, parseVarArgs} from '../logreader.mjs';
|
|
|
|
import {Profile} from '../profile.mjs';
|
2021-06-30 11:17:33 +00:00
|
|
|
import {RemoteLinuxCppEntriesProvider, RemoteMacOSCppEntriesProvider} from '../tickprocessor.mjs'
|
2020-11-03 08:01:33 +00:00
|
|
|
|
2022-04-26 17:18:04 +00:00
|
|
|
import {CodeLogEntry, CPPCodeLogEntry, DeoptLogEntry, FeedbackVectorEntry, SharedLibLogEntry} from './log/code.mjs';
|
2020-11-03 08:01:33 +00:00
|
|
|
import {IcLogEntry} from './log/ic.mjs';
|
|
|
|
import {Edge, MapLogEntry} from './log/map.mjs';
|
2021-06-07 14:57:44 +00:00
|
|
|
import {TickLogEntry} from './log/tick.mjs';
|
2021-06-28 19:46:31 +00:00
|
|
|
import {TimerLogEntry} from './log/timer.mjs';
|
2020-11-03 08:01:33 +00:00
|
|
|
import {Timeline} from './timeline.mjs';
|
2020-09-02 13:17:35 +00:00
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
2021-06-30 11:17:33 +00:00
|
|
|
class AsyncConsumer {
|
|
|
|
constructor(consumer_fn) {
|
|
|
|
this._chunks = [];
|
|
|
|
this._consumer = consumer_fn;
|
|
|
|
this._pendingWork = Promise.resolve();
|
|
|
|
this._isConsuming = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get pendingWork() {
|
|
|
|
return this._pendingWork;
|
|
|
|
}
|
|
|
|
|
|
|
|
push(chunk) {
|
|
|
|
this._chunks.push(chunk);
|
|
|
|
this.consumeAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
async consumeAll() {
|
|
|
|
if (!this._isConsuming) this._pendingWork = this._consumeAll();
|
|
|
|
return await this._pendingWork;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _consumeAll() {
|
|
|
|
this._isConsuming = true;
|
|
|
|
while (this._chunks.length > 0) {
|
|
|
|
await this._consumer(this._chunks.shift());
|
|
|
|
}
|
|
|
|
this._isConsuming = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 10:13:33 +00:00
|
|
|
export class Processor extends LogReader {
|
2021-06-07 14:57:44 +00:00
|
|
|
_codeTimeline = new Timeline();
|
|
|
|
_deoptTimeline = new Timeline();
|
|
|
|
_icTimeline = new Timeline();
|
|
|
|
_mapTimeline = new Timeline();
|
|
|
|
_tickTimeline = new Timeline();
|
2021-06-28 19:46:31 +00:00
|
|
|
_timerTimeline = new Timeline();
|
2020-10-19 10:45:42 +00:00
|
|
|
_formatPCRegexp = /(.*):[0-9]+:[0-9]+$/;
|
2020-12-03 17:48:45 +00:00
|
|
|
_lastTimestamp = 0;
|
|
|
|
_lastCodeLogEntry;
|
2022-03-02 09:56:03 +00:00
|
|
|
_lastTickLogEntry;
|
2022-04-14 15:17:44 +00:00
|
|
|
|
2022-04-26 17:18:04 +00:00
|
|
|
_cppEntriesProvider;
|
|
|
|
|
2021-06-11 10:29:41 +00:00
|
|
|
_chunkRemainder = '';
|
2022-04-14 15:17:44 +00:00
|
|
|
_lineNumber = 1;
|
2022-04-08 18:54:33 +00:00
|
|
|
|
|
|
|
_totalInputBytes = 0;
|
|
|
|
_processedInputChars = 0;
|
|
|
|
_progressCallback;
|
|
|
|
|
2020-09-02 13:17:35 +00:00
|
|
|
MAJOR_VERSION = 7;
|
|
|
|
MINOR_VERSION = 6;
|
2022-12-15 20:07:00 +00:00
|
|
|
constructor(useBigInt = false) {
|
|
|
|
super(false, false, useBigInt);
|
|
|
|
this.useBigInt = useBigInt;
|
|
|
|
this.kZero = useBigInt ? 0n : 0;
|
|
|
|
this.parseAddress = useBigInt ? BigInt : parseInt;
|
2021-06-30 11:17:33 +00:00
|
|
|
this._chunkConsumer =
|
|
|
|
new AsyncConsumer((chunk) => this._processChunk(chunk));
|
2022-12-15 20:07:00 +00:00
|
|
|
this._profile = new Profile(useBigInt);
|
2020-11-30 10:53:12 +00:00
|
|
|
const propertyICParser = [
|
2022-12-15 20:07:00 +00:00
|
|
|
this.parseAddress, parseInt, parseInt, parseInt, parseString, parseString,
|
2020-09-02 13:17:35 +00:00
|
|
|
parseString, parseString, parseString, parseString
|
|
|
|
];
|
2022-04-06 10:18:33 +00:00
|
|
|
this.setDispatchTable({
|
2020-09-02 13:17:35 +00:00
|
|
|
__proto__: null,
|
2020-11-30 10:53:12 +00:00
|
|
|
'v8-version': {
|
|
|
|
parsers: [
|
|
|
|
parseInt,
|
|
|
|
parseInt,
|
|
|
|
],
|
2022-04-06 10:18:33 +00:00
|
|
|
processor: this.processV8Version,
|
2020-11-30 10:53:12 +00:00
|
|
|
},
|
2021-06-14 10:10:17 +00:00
|
|
|
'shared-library': {
|
2022-12-15 20:07:00 +00:00
|
|
|
parsers: [
|
|
|
|
parseString, this.parseAddress, this.parseAddress, this.parseAddress
|
|
|
|
],
|
2022-04-06 10:18:33 +00:00
|
|
|
processor: this.processSharedLibrary.bind(this),
|
|
|
|
isAsync: true,
|
2021-06-14 10:10:17 +00:00
|
|
|
},
|
2020-09-02 13:17:35 +00:00
|
|
|
'code-creation': {
|
|
|
|
parsers: [
|
2022-12-15 20:07:00 +00:00
|
|
|
parseString, parseInt, parseInt, this.parseAddress, this.parseAddress,
|
|
|
|
parseString, parseVarArgs
|
2020-09-02 13:17:35 +00:00
|
|
|
],
|
|
|
|
processor: this.processCodeCreation
|
|
|
|
},
|
2020-10-19 12:39:55 +00:00
|
|
|
'code-deopt': {
|
|
|
|
parsers: [
|
2022-12-15 20:07:00 +00:00
|
|
|
parseInt, parseInt, this.parseAddress, parseInt, parseInt,
|
|
|
|
parseString, parseString, parseString
|
2020-10-19 12:39:55 +00:00
|
|
|
],
|
|
|
|
processor: this.processCodeDeopt
|
|
|
|
},
|
2022-12-15 20:07:00 +00:00
|
|
|
'code-move': {
|
|
|
|
parsers: [this.parseAddress, this.parseAddress],
|
|
|
|
processor: this.processCodeMove
|
|
|
|
},
|
|
|
|
'code-delete':
|
|
|
|
{parsers: [this.parseAddress], processor: this.processCodeDelete},
|
2020-11-30 10:53:12 +00:00
|
|
|
'code-source-info': {
|
2020-09-02 13:17:35 +00:00
|
|
|
parsers: [
|
2022-12-15 20:07:00 +00:00
|
|
|
this.parseAddress, parseInt, parseInt, parseInt, parseString,
|
|
|
|
parseString, parseString
|
2020-09-02 13:17:35 +00:00
|
|
|
],
|
2020-11-30 10:53:12 +00:00
|
|
|
processor: this.processCodeSourceInfo
|
2020-09-02 13:17:35 +00:00
|
|
|
},
|
2020-12-01 19:37:17 +00:00
|
|
|
'code-disassemble': {
|
2022-12-15 20:07:00 +00:00
|
|
|
parsers: [this.parseAddress, parseString, parseString],
|
2020-12-01 19:37:17 +00:00
|
|
|
processor: this.processCodeDisassemble
|
|
|
|
},
|
2021-10-27 08:50:53 +00:00
|
|
|
'feedback-vector': {
|
|
|
|
parsers: [
|
2022-12-15 20:07:00 +00:00
|
|
|
parseInt, parseString, parseInt, this.parseAddress, parseString,
|
|
|
|
parseString, parseInt, parseInt, parseString
|
2021-10-27 08:50:53 +00:00
|
|
|
],
|
|
|
|
processor: this.processFeedbackVector
|
|
|
|
},
|
2020-09-02 13:17:35 +00:00
|
|
|
'script-source': {
|
|
|
|
parsers: [parseInt, parseString, parseString],
|
|
|
|
processor: this.processScriptSource
|
|
|
|
},
|
2022-12-15 20:07:00 +00:00
|
|
|
'sfi-move': {
|
|
|
|
parsers: [this.parseAddress, this.parseAddress],
|
|
|
|
processor: this.processFunctionMove
|
|
|
|
},
|
2021-05-31 12:18:32 +00:00
|
|
|
'tick': {
|
2022-12-15 20:07:00 +00:00
|
|
|
parsers: [
|
|
|
|
this.parseAddress, parseInt, parseInt, this.parseAddress, parseInt,
|
|
|
|
parseVarArgs
|
|
|
|
],
|
2021-05-31 12:18:32 +00:00
|
|
|
processor: this.processTick
|
|
|
|
},
|
|
|
|
'active-runtime-timer': undefined,
|
|
|
|
'heap-sample-begin': undefined,
|
|
|
|
'heap-sample-end': undefined,
|
2021-06-28 19:46:31 +00:00
|
|
|
'timer-event-start': {
|
|
|
|
parsers: [parseString, parseInt],
|
|
|
|
processor: this.processTimerEventStart
|
|
|
|
},
|
|
|
|
'timer-event-end': {
|
|
|
|
parsers: [parseString, parseInt],
|
|
|
|
processor: this.processTimerEventEnd
|
|
|
|
},
|
2020-09-02 13:17:35 +00:00
|
|
|
'map-create':
|
2020-11-03 08:01:33 +00:00
|
|
|
{parsers: [parseInt, parseString], processor: this.processMapCreate},
|
2020-09-02 13:17:35 +00:00
|
|
|
'map': {
|
|
|
|
parsers: [
|
2022-12-15 20:07:00 +00:00
|
|
|
parseString, parseInt, parseString, parseString, this.parseAddress,
|
|
|
|
parseInt, parseInt, parseString, parseString
|
2020-09-02 13:17:35 +00:00
|
|
|
],
|
|
|
|
processor: this.processMap
|
|
|
|
},
|
|
|
|
'map-details': {
|
|
|
|
parsers: [parseInt, parseString, parseString],
|
|
|
|
processor: this.processMapDetails
|
|
|
|
},
|
|
|
|
'LoadGlobalIC': {
|
2020-11-30 10:53:12 +00:00
|
|
|
parsers: propertyICParser,
|
2020-09-02 13:17:35 +00:00
|
|
|
processor: this.processPropertyIC.bind(this, 'LoadGlobalIC')
|
|
|
|
},
|
|
|
|
'StoreGlobalIC': {
|
2020-11-30 10:53:12 +00:00
|
|
|
parsers: propertyICParser,
|
2020-09-02 13:17:35 +00:00
|
|
|
processor: this.processPropertyIC.bind(this, 'StoreGlobalIC')
|
|
|
|
},
|
|
|
|
'LoadIC': {
|
2020-11-30 10:53:12 +00:00
|
|
|
parsers: propertyICParser,
|
2020-09-02 13:17:35 +00:00
|
|
|
processor: this.processPropertyIC.bind(this, 'LoadIC')
|
|
|
|
},
|
|
|
|
'StoreIC': {
|
2020-11-30 10:53:12 +00:00
|
|
|
parsers: propertyICParser,
|
2020-09-02 13:17:35 +00:00
|
|
|
processor: this.processPropertyIC.bind(this, 'StoreIC')
|
|
|
|
},
|
|
|
|
'KeyedLoadIC': {
|
2020-11-30 10:53:12 +00:00
|
|
|
parsers: propertyICParser,
|
2020-09-02 13:17:35 +00:00
|
|
|
processor: this.processPropertyIC.bind(this, 'KeyedLoadIC')
|
|
|
|
},
|
|
|
|
'KeyedStoreIC': {
|
2020-11-30 10:53:12 +00:00
|
|
|
parsers: propertyICParser,
|
2020-09-02 13:17:35 +00:00
|
|
|
processor: this.processPropertyIC.bind(this, 'KeyedStoreIC')
|
|
|
|
},
|
|
|
|
'StoreInArrayLiteralIC': {
|
2020-11-30 10:53:12 +00:00
|
|
|
parsers: propertyICParser,
|
2020-09-02 13:17:35 +00:00
|
|
|
processor: this.processPropertyIC.bind(this, 'StoreInArrayLiteralIC')
|
|
|
|
},
|
2020-12-03 17:48:45 +00:00
|
|
|
'api': {
|
|
|
|
parsers: [parseString, parseVarArgs],
|
|
|
|
processor: this.processApiEvent
|
|
|
|
},
|
2022-04-06 10:18:33 +00:00
|
|
|
});
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printError(str) {
|
|
|
|
console.error(str);
|
|
|
|
throw str
|
|
|
|
}
|
|
|
|
|
2021-06-11 10:29:41 +00:00
|
|
|
processChunk(chunk) {
|
2021-06-30 11:17:33 +00:00
|
|
|
this._chunkConsumer.push(chunk)
|
|
|
|
}
|
|
|
|
|
2022-04-08 18:54:33 +00:00
|
|
|
setProgressCallback(totalSize, callback) {
|
|
|
|
this._totalInputBytes = totalSize;
|
|
|
|
this._progressCallback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _updateProgress() {
|
|
|
|
if (!this._progressCallback) return;
|
|
|
|
// We use chars and bytes interchangeably for simplicity. This causes us to
|
|
|
|
// slightly underestimate progress.
|
|
|
|
this._progressCallback(
|
|
|
|
this._processedInputChars / this._totalInputBytes,
|
|
|
|
this._processedInputChars);
|
|
|
|
}
|
|
|
|
|
2021-06-30 11:17:33 +00:00
|
|
|
async _processChunk(chunk) {
|
2022-04-08 18:54:33 +00:00
|
|
|
const prevProcessedInputChars = this._processedInputChars;
|
2021-06-11 10:29:41 +00:00
|
|
|
let end = chunk.length;
|
2020-09-02 13:17:35 +00:00
|
|
|
let current = 0;
|
|
|
|
let next = 0;
|
|
|
|
let line;
|
|
|
|
try {
|
|
|
|
while (current < end) {
|
2021-06-11 10:29:41 +00:00
|
|
|
next = chunk.indexOf('\n', current);
|
|
|
|
if (next === -1) {
|
2022-04-14 15:17:44 +00:00
|
|
|
this._chunkRemainder += chunk.substring(current);
|
2021-06-11 10:29:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
line = chunk.substring(current, next);
|
|
|
|
if (this._chunkRemainder) {
|
|
|
|
line = this._chunkRemainder + line;
|
|
|
|
this._chunkRemainder = '';
|
|
|
|
}
|
2020-09-02 13:17:35 +00:00
|
|
|
current = next + 1;
|
2022-04-14 15:17:44 +00:00
|
|
|
this._lineNumber++;
|
2021-06-30 11:17:33 +00:00
|
|
|
await this.processLogLine(line);
|
2022-04-08 18:54:33 +00:00
|
|
|
this._processedInputChars = prevProcessedInputChars + current;
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
2022-04-08 18:54:33 +00:00
|
|
|
this._updateProgress();
|
2020-09-02 13:17:35 +00:00
|
|
|
} catch (e) {
|
2022-04-14 15:17:44 +00:00
|
|
|
console.error(`Could not parse log line ${
|
|
|
|
this._lineNumber}, trying to continue: ${e}`);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 11:17:33 +00:00
|
|
|
async processLogFile(fileName) {
|
2020-09-02 13:17:35 +00:00
|
|
|
this.collectEntries = true;
|
|
|
|
this.lastLogFileName_ = fileName;
|
|
|
|
let i = 1;
|
|
|
|
let line;
|
|
|
|
try {
|
|
|
|
while (line = readline()) {
|
2021-06-30 11:17:33 +00:00
|
|
|
await this.processLogLine(line);
|
2020-09-02 13:17:35 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error(
|
2020-11-10 11:47:40 +00:00
|
|
|
`Error occurred during parsing line ${i}` +
|
2020-11-03 08:01:33 +00:00
|
|
|
', trying to continue: ' + e);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
this.finalize();
|
|
|
|
}
|
|
|
|
|
2021-06-30 11:17:33 +00:00
|
|
|
async finalize() {
|
|
|
|
await this._chunkConsumer.consumeAll();
|
2022-03-02 09:56:03 +00:00
|
|
|
if (this._profile.warnings.size > 0) {
|
|
|
|
console.warn('Found profiler warnings:', this._profile.warnings);
|
|
|
|
}
|
2020-09-02 13:17:35 +00:00
|
|
|
// TODO(cbruni): print stats;
|
2020-10-19 10:45:42 +00:00
|
|
|
this._mapTimeline.transitions = new Map();
|
2020-09-02 13:17:35 +00:00
|
|
|
let id = 0;
|
2020-10-19 10:45:42 +00:00
|
|
|
this._mapTimeline.forEach(map => {
|
2020-09-02 13:17:35 +00:00
|
|
|
if (map.isRoot()) id = map.finalizeRootMap(id + 1);
|
|
|
|
if (map.edge && map.edge.name) {
|
2020-11-10 11:47:40 +00:00
|
|
|
const edge = map.edge;
|
|
|
|
const list = this._mapTimeline.transitions.get(edge.name);
|
2020-09-02 13:17:35 +00:00
|
|
|
if (list === undefined) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._mapTimeline.transitions.set(edge.name, [edge]);
|
2020-09-02 13:17:35 +00:00
|
|
|
} else {
|
|
|
|
list.push(edge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-03 17:48:45 +00:00
|
|
|
processV8Version(majorVersion, minorVersion) {
|
|
|
|
if ((majorVersion == this.MAJOR_VERSION &&
|
|
|
|
minorVersion <= this.MINOR_VERSION) ||
|
|
|
|
(majorVersion < this.MAJOR_VERSION)) {
|
|
|
|
window.alert(
|
|
|
|
`Unsupported version ${majorVersion}.${minorVersion}. \n` +
|
|
|
|
`Please use the matching tool for given the V8 version.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 11:17:33 +00:00
|
|
|
async processSharedLibrary(name, startAddr, endAddr, aslrSlide) {
|
|
|
|
const entry = this._profile.addLibrary(name, startAddr, endAddr);
|
2021-06-15 11:19:00 +00:00
|
|
|
entry.logEntry = new SharedLibLogEntry(entry);
|
2021-06-17 15:09:24 +00:00
|
|
|
// Many events rely on having a script around, creating fake entries for
|
|
|
|
// shared libraries.
|
|
|
|
this._profile.addScriptSource(-1, name, '');
|
2022-12-07 00:04:45 +00:00
|
|
|
|
2022-04-26 17:18:04 +00:00
|
|
|
if (this._cppEntriesProvider == undefined) {
|
|
|
|
await this._setupCppEntriesProvider();
|
|
|
|
}
|
2022-12-07 00:04:45 +00:00
|
|
|
|
2021-06-30 11:17:33 +00:00
|
|
|
await this._cppEntriesProvider.parseVmSymbols(
|
|
|
|
name, startAddr, endAddr, aslrSlide, (fName, fStart, fEnd) => {
|
2022-04-26 17:18:04 +00:00
|
|
|
const entry = this._profile.addStaticCode(fName, fStart, fEnd);
|
|
|
|
entry.logEntry = new CPPCodeLogEntry(entry);
|
2021-06-30 11:17:33 +00:00
|
|
|
});
|
2021-06-14 10:10:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 17:18:04 +00:00
|
|
|
async _setupCppEntriesProvider() {
|
|
|
|
// Probe the local symbol server for the platform:
|
|
|
|
const url = new URL('http://localhost:8000/v8/info/platform')
|
2022-08-10 14:10:38 +00:00
|
|
|
let platform = {name: 'linux'};
|
2022-04-26 17:18:04 +00:00
|
|
|
try {
|
2022-07-19 13:11:01 +00:00
|
|
|
const response = await fetch(url, {timeout: 1});
|
2022-08-10 14:10:38 +00:00
|
|
|
if (response.status == 404) {
|
|
|
|
throw new Error(
|
|
|
|
`Local symbol server returned 404: ${await response.text()}`);
|
|
|
|
}
|
|
|
|
platform = await response.json();
|
2022-04-26 17:18:04 +00:00
|
|
|
} catch (e) {
|
2022-07-19 13:11:01 +00:00
|
|
|
console.warn(`Local symbol server is not running on ${url}`);
|
2022-04-26 17:18:04 +00:00
|
|
|
console.warn(e);
|
|
|
|
}
|
2022-08-10 14:10:38 +00:00
|
|
|
let CppEntriesProvider = RemoteLinuxCppEntriesProvider;
|
|
|
|
if (platform.name === 'darwin') {
|
|
|
|
CppEntriesProvider = RemoteMacOSCppEntriesProvider;
|
2022-04-26 17:18:04 +00:00
|
|
|
}
|
2022-08-10 14:10:38 +00:00
|
|
|
this._cppEntriesProvider = new CppEntriesProvider(
|
|
|
|
platform.nmExec, platform.objdumpExec, platform.targetRootFS,
|
|
|
|
platform.apkEmbeddedLibrary);
|
2022-04-26 17:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processCodeCreation(
|
|
|
|
type, kind, timestamp, start, size, nameAndPosition, maybe_func) {
|
2020-12-03 17:48:45 +00:00
|
|
|
this._lastTimestamp = timestamp;
|
2022-06-23 14:47:26 +00:00
|
|
|
let profilerEntry;
|
2020-12-01 19:37:17 +00:00
|
|
|
let stateName = '';
|
2020-09-02 13:17:35 +00:00
|
|
|
if (maybe_func.length) {
|
2022-12-15 20:07:00 +00:00
|
|
|
const funcAddr = this.parseAddress(maybe_func[0]);
|
2020-12-01 19:37:17 +00:00
|
|
|
stateName = maybe_func[1] ?? '';
|
2020-12-01 17:36:40 +00:00
|
|
|
const state = Profile.parseState(maybe_func[1]);
|
2022-06-23 14:47:26 +00:00
|
|
|
profilerEntry = this._profile.addFuncCode(
|
2022-04-26 17:18:04 +00:00
|
|
|
type, nameAndPosition, timestamp, start, size, funcAddr, state);
|
2020-09-02 13:17:35 +00:00
|
|
|
} else {
|
2022-06-23 14:47:26 +00:00
|
|
|
profilerEntry = this._profile.addAnyCode(
|
2022-04-26 17:18:04 +00:00
|
|
|
type, nameAndPosition, timestamp, start, size);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
2022-04-26 17:18:04 +00:00
|
|
|
const name = nameAndPosition.slice(0, nameAndPosition.indexOf(' '));
|
2021-05-25 08:49:11 +00:00
|
|
|
this._lastCodeLogEntry = new CodeLogEntry(
|
|
|
|
type + stateName, timestamp,
|
2022-04-26 17:18:04 +00:00
|
|
|
Profile.getKindFromState(Profile.parseState(stateName)), kind, name,
|
2022-06-23 14:47:26 +00:00
|
|
|
profilerEntry);
|
2020-12-03 17:48:45 +00:00
|
|
|
this._codeTimeline.push(this._lastCodeLogEntry);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 08:01:33 +00:00
|
|
|
processCodeDeopt(
|
|
|
|
timestamp, codeSize, instructionStart, inliningId, scriptOffset,
|
|
|
|
deoptKind, deoptLocation, deoptReason) {
|
2020-12-03 17:48:45 +00:00
|
|
|
this._lastTimestamp = timestamp;
|
2022-04-04 13:52:17 +00:00
|
|
|
const profCodeEntry = this._profile.findEntry(instructionStart);
|
2020-12-03 17:48:45 +00:00
|
|
|
const logEntry = new DeoptLogEntry(
|
2022-04-04 13:52:17 +00:00
|
|
|
deoptKind, timestamp, profCodeEntry, deoptReason, deoptLocation,
|
2020-12-14 09:41:32 +00:00
|
|
|
scriptOffset, instructionStart, codeSize, inliningId);
|
2022-04-04 13:52:17 +00:00
|
|
|
profCodeEntry.logEntry.add(logEntry);
|
2020-12-03 17:48:45 +00:00
|
|
|
this._deoptTimeline.push(logEntry);
|
2022-04-04 13:52:17 +00:00
|
|
|
this.addSourcePosition(profCodeEntry, logEntry);
|
2020-12-14 09:41:32 +00:00
|
|
|
logEntry.functionSourcePosition = logEntry.sourcePosition;
|
|
|
|
// custom parse deopt location
|
2021-04-29 08:46:51 +00:00
|
|
|
if (deoptLocation === '<unknown>') return;
|
|
|
|
// Handle deopt location for inlined code: <location> inlined at <location>
|
|
|
|
const inlinedPos = deoptLocation.indexOf(' inlined at ');
|
|
|
|
if (inlinedPos > 0) {
|
|
|
|
deoptLocation = deoptLocation.substring(0, inlinedPos)
|
2020-12-14 09:41:32 +00:00
|
|
|
}
|
2022-04-04 13:52:17 +00:00
|
|
|
const script = this.getProfileEntryScript(profCodeEntry);
|
2021-06-15 12:47:33 +00:00
|
|
|
if (!script) return;
|
2021-04-29 08:46:51 +00:00
|
|
|
const colSeparator = deoptLocation.lastIndexOf(':');
|
|
|
|
const rowSeparator = deoptLocation.lastIndexOf(':', colSeparator - 1);
|
|
|
|
const line =
|
|
|
|
parseInt(deoptLocation.substring(rowSeparator + 1, colSeparator));
|
|
|
|
const column = parseInt(
|
|
|
|
deoptLocation.substring(colSeparator + 1, deoptLocation.length - 1));
|
|
|
|
logEntry.sourcePosition = script.addSourcePosition(line, column, logEntry);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 08:50:53 +00:00
|
|
|
processFeedbackVector(
|
|
|
|
timestamp, fbv_address, fbv_length, instructionStart, optimization_marker,
|
|
|
|
optimization_tier, invocation_count, profiler_ticks, fbv_string) {
|
2022-04-04 13:52:17 +00:00
|
|
|
const profCodeEntry = this._profile.findEntry(instructionStart);
|
|
|
|
if (!profCodeEntry) {
|
2022-12-15 20:07:00 +00:00
|
|
|
console.warn('Didn\'t find code for FBV', {fbv_string, instructionStart});
|
2021-10-27 08:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const fbv = new FeedbackVectorEntry(
|
2022-04-04 13:52:17 +00:00
|
|
|
timestamp, profCodeEntry.logEntry, fbv_address, fbv_length,
|
2021-10-27 08:50:53 +00:00
|
|
|
optimization_marker, optimization_tier, invocation_count,
|
|
|
|
profiler_ticks, fbv_string);
|
2022-04-04 13:52:17 +00:00
|
|
|
profCodeEntry.logEntry.setFeedbackVector(fbv);
|
2021-10-27 08:50:53 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 13:17:35 +00:00
|
|
|
processScriptSource(scriptId, url, source) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._profile.addScriptSource(scriptId, url, source);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processCodeMove(from, to) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._profile.moveCode(from, to);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processCodeDelete(start) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._profile.deleteCode(start);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processFunctionMove(from, to) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._profile.moveFunc(from, to);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 12:18:32 +00:00
|
|
|
processTick(
|
2021-06-07 14:57:44 +00:00
|
|
|
pc, time_ns, is_external_callback, tos_or_external_callback, vmState,
|
|
|
|
stack) {
|
2021-05-31 12:18:32 +00:00
|
|
|
if (is_external_callback) {
|
|
|
|
// Don't use PC when in external callback code, as it can point
|
|
|
|
// inside callback's code, and we will erroneously report
|
|
|
|
// that a callback calls itself. Instead we use tos_or_external_callback,
|
|
|
|
// as simply resetting PC will produce unaccounted ticks.
|
|
|
|
pc = tos_or_external_callback;
|
2022-12-15 20:07:00 +00:00
|
|
|
tos_or_external_callback = this.kZero;
|
2021-05-31 12:18:32 +00:00
|
|
|
} else if (tos_or_external_callback) {
|
|
|
|
// Find out, if top of stack was pointing inside a JS function
|
|
|
|
// meaning that we have encountered a frameless invocation.
|
|
|
|
const funcEntry = this._profile.findEntry(tos_or_external_callback);
|
|
|
|
if (!funcEntry?.isJSFunction?.()) {
|
2022-12-15 20:07:00 +00:00
|
|
|
tos_or_external_callback = this.kZero;
|
2021-05-31 12:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-07 14:57:44 +00:00
|
|
|
const entryStack = this._profile.recordTick(
|
|
|
|
time_ns, vmState,
|
2021-05-31 12:18:32 +00:00
|
|
|
this.processStack(pc, tos_or_external_callback, stack));
|
2022-03-02 09:56:03 +00:00
|
|
|
const newEntry = new TickLogEntry(time_ns, vmState, entryStack);
|
|
|
|
this._tickTimeline.push(newEntry);
|
|
|
|
if (this._lastTickLogEntry !== undefined) {
|
|
|
|
this._lastTickLogEntry.end(time_ns);
|
|
|
|
}
|
|
|
|
this._lastTickLogEntry = newEntry;
|
2021-05-31 12:18:32 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 10:53:12 +00:00
|
|
|
processCodeSourceInfo(
|
2020-12-03 17:48:45 +00:00
|
|
|
start, scriptId, startPos, endPos, sourcePositions, inliningPositions,
|
2020-11-30 10:53:12 +00:00
|
|
|
inlinedFunctions) {
|
|
|
|
this._profile.addSourcePositions(
|
2020-12-03 17:48:45 +00:00
|
|
|
start, scriptId, startPos, endPos, sourcePositions, inliningPositions,
|
2020-11-30 10:53:12 +00:00
|
|
|
inlinedFunctions);
|
2021-06-30 11:17:33 +00:00
|
|
|
if (this._lastCodeLogEntry === undefined) return;
|
2020-12-03 17:48:45 +00:00
|
|
|
let profileEntry = this._profile.findEntry(start);
|
|
|
|
if (profileEntry !== this._lastCodeLogEntry._entry) return;
|
|
|
|
this.addSourcePosition(profileEntry, this._lastCodeLogEntry);
|
|
|
|
this._lastCodeLogEntry = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
addSourcePosition(profileEntry, logEntry) {
|
|
|
|
let script = this.getProfileEntryScript(profileEntry);
|
|
|
|
const parts = profileEntry.getRawName().split(':');
|
|
|
|
if (parts.length < 3) return;
|
|
|
|
const line = parseInt(parts[parts.length - 2]);
|
|
|
|
const column = parseInt(parts[parts.length - 1]);
|
|
|
|
logEntry.sourcePosition = script.addSourcePosition(line, column, logEntry);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 19:37:17 +00:00
|
|
|
processCodeDisassemble(start, kind, disassemble) {
|
|
|
|
this._profile.addDisassemble(start, kind, disassemble);
|
|
|
|
}
|
|
|
|
|
2020-09-02 13:17:35 +00:00
|
|
|
processPropertyIC(
|
2020-12-07 08:44:54 +00:00
|
|
|
type, pc, time, line, column, old_state, new_state, mapId, key, modifier,
|
2020-11-03 08:01:33 +00:00
|
|
|
slow_reason) {
|
2020-12-03 17:48:45 +00:00
|
|
|
this._lastTimestamp = time;
|
2021-06-15 11:19:00 +00:00
|
|
|
const codeEntry = this._profile.findEntry(pc);
|
|
|
|
const fnName = this.formatProfileEntry(codeEntry);
|
|
|
|
const script = this.getProfileEntryScript(codeEntry);
|
2020-12-07 08:44:54 +00:00
|
|
|
const map = this.getOrCreateMapEntry(mapId, time);
|
2020-09-23 10:30:17 +00:00
|
|
|
// TODO: Use SourcePosition here directly
|
2020-10-19 10:13:33 +00:00
|
|
|
let entry = new IcLogEntry(
|
2020-11-03 08:01:33 +00:00
|
|
|
type, fnName, time, line, column, key, old_state, new_state, map,
|
2021-06-15 11:19:00 +00:00
|
|
|
slow_reason, modifier, codeEntry);
|
2020-09-23 10:30:17 +00:00
|
|
|
if (script) {
|
|
|
|
entry.sourcePosition = script.addSourcePosition(line, column, entry);
|
|
|
|
}
|
2020-10-19 10:45:42 +00:00
|
|
|
this._icTimeline.push(entry);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 10:53:12 +00:00
|
|
|
formatProfileEntry(profileEntry, line, column) {
|
|
|
|
if (!profileEntry) return '<unknown>';
|
|
|
|
if (profileEntry.type === 'Builtin') return profileEntry.name;
|
|
|
|
const name = profileEntry.func.getName();
|
|
|
|
const array = this._formatPCRegexp.exec(name);
|
|
|
|
const formatted =
|
|
|
|
(array === null) ? name : profileEntry.getState() + array[1];
|
|
|
|
if (line === undefined || column === undefined) return formatted;
|
|
|
|
return `${formatted}:${line}:${column}`;
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 10:53:12 +00:00
|
|
|
getProfileEntryScript(profileEntry) {
|
|
|
|
if (!profileEntry) return undefined;
|
|
|
|
if (profileEntry.type === 'Builtin') return undefined;
|
|
|
|
const script = profileEntry.source?.script;
|
|
|
|
if (script !== undefined) return script;
|
2021-06-15 11:19:00 +00:00
|
|
|
let fileName;
|
2021-06-30 11:17:33 +00:00
|
|
|
if (profileEntry.type === 'SHARED_LIB') {
|
2021-06-15 11:19:00 +00:00
|
|
|
fileName = profileEntry.name;
|
|
|
|
} else {
|
|
|
|
// Slow path, try to get the script from the url:
|
|
|
|
const fnName = this.formatProfileEntry(profileEntry);
|
|
|
|
let parts = fnName.split(' ');
|
|
|
|
fileName = parts[parts.length - 1];
|
|
|
|
}
|
2020-11-30 10:53:12 +00:00
|
|
|
return this.getScript(fileName);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processMap(type, time, from, to, pc, line, column, reason, name) {
|
2020-12-03 17:48:45 +00:00
|
|
|
this._lastTimestamp = time;
|
2020-12-01 10:15:44 +00:00
|
|
|
const time_ = parseInt(time);
|
2020-09-02 13:17:35 +00:00
|
|
|
if (type === 'Deprecate') return this.deprecateMap(type, time_, from);
|
2020-12-01 10:15:44 +00:00
|
|
|
// Skip normalized maps that were cached so we don't introduce multiple
|
|
|
|
// edges with the same source and target map.
|
|
|
|
if (type === 'NormalizeCached') return;
|
2020-12-07 08:44:54 +00:00
|
|
|
const from_ = this.getOrCreateMapEntry(from, time_);
|
|
|
|
const to_ = this.getOrCreateMapEntry(to, time_);
|
2020-12-01 10:15:44 +00:00
|
|
|
if (type === 'Normalize') {
|
|
|
|
// Fix a bug where we log "Normalize" transitions for maps created from
|
|
|
|
// the NormalizedMapCache.
|
2021-06-15 11:19:00 +00:00
|
|
|
if (to_.parent?.id === from || to_.time < from_.time || to_.depth > 0) {
|
2020-12-01 10:15:44 +00:00
|
|
|
console.log(`Skipping transition to cached normalized map`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-04-04 13:52:17 +00:00
|
|
|
if (pc) {
|
|
|
|
const profCodeEntry = this._profile.findEntry(pc);
|
|
|
|
if (profCodeEntry) {
|
|
|
|
to_.entry = profCodeEntry;
|
|
|
|
profCodeEntry.logEntry.add(to_);
|
|
|
|
let script = this.getProfileEntryScript(profCodeEntry);
|
|
|
|
if (script) {
|
|
|
|
to_.sourcePosition = script.addSourcePosition(line, column, to_);
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 10:30:17 +00:00
|
|
|
}
|
2022-04-04 13:52:17 +00:00
|
|
|
let edge = new Edge(type, name, reason, time, from_, to_);
|
2021-06-15 11:19:00 +00:00
|
|
|
if (to_.parent !== undefined && to_.parent === from_) {
|
2020-12-01 10:15:44 +00:00
|
|
|
// Fix bug where we double log transitions.
|
|
|
|
console.warn('Fixing up double transition');
|
|
|
|
to_.edge.updateFrom(edge);
|
|
|
|
} else {
|
|
|
|
edge.finishSetup();
|
|
|
|
}
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deprecateMap(type, time, id) {
|
2020-12-03 17:48:45 +00:00
|
|
|
this._lastTimestamp = time;
|
2020-12-07 08:44:54 +00:00
|
|
|
this.getOrCreateMapEntry(id, time).deprecate();
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processMapCreate(time, id) {
|
|
|
|
// map-create events might override existing maps if the addresses get
|
|
|
|
// recycled. Hence we do not check for existing maps.
|
2020-12-03 17:48:45 +00:00
|
|
|
this._lastTimestamp = time;
|
2020-12-01 10:15:44 +00:00
|
|
|
this.createMapEntry(id, time);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processMapDetails(time, id, string) {
|
|
|
|
// TODO(cbruni): fix initial map logging.
|
2020-12-07 08:44:54 +00:00
|
|
|
const map = this.getOrCreateMapEntry(id, time);
|
2020-09-02 13:17:35 +00:00
|
|
|
map.description = string;
|
|
|
|
}
|
|
|
|
|
2020-10-19 10:13:33 +00:00
|
|
|
createMapEntry(id, time) {
|
2020-12-03 17:48:45 +00:00
|
|
|
this._lastTimestamp = time;
|
2020-12-01 10:15:44 +00:00
|
|
|
const map = new MapLogEntry(id, time);
|
2020-10-19 10:45:42 +00:00
|
|
|
this._mapTimeline.push(map);
|
2020-09-02 13:17:35 +00:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2020-12-07 08:44:54 +00:00
|
|
|
getOrCreateMapEntry(id, time) {
|
2020-09-02 13:17:35 +00:00
|
|
|
if (id === '0x000000000000') return undefined;
|
2020-12-01 10:15:44 +00:00
|
|
|
const map = MapLogEntry.get(id, time);
|
|
|
|
if (map !== undefined) return map;
|
|
|
|
console.warn(`No map details provided: id=${id}`);
|
|
|
|
// Manually patch in a map to continue running.
|
|
|
|
return this.createMapEntry(id, time);
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getScript(url) {
|
2020-10-19 10:45:42 +00:00
|
|
|
const script = this._profile.getScript(url);
|
2020-09-23 10:30:17 +00:00
|
|
|
// TODO create placeholder script for empty urls.
|
|
|
|
if (script === undefined) {
|
|
|
|
console.error(`Could not find script for url: '${url}'`)
|
|
|
|
}
|
|
|
|
return script;
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 08:01:26 +00:00
|
|
|
processApiEvent(type, varArgs) {
|
2022-04-07 12:48:04 +00:00
|
|
|
// legacy events that are no longer supported
|
2020-12-03 17:48:45 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 19:46:31 +00:00
|
|
|
processTimerEventStart(type, time) {
|
|
|
|
const entry = new TimerLogEntry(type, time);
|
|
|
|
this._timerTimeline.push(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
processTimerEventEnd(type, time) {
|
|
|
|
// Timer-events are infrequent, and not deeply nested, doing a linear walk
|
|
|
|
// is usually good enough.
|
|
|
|
for (let i = this._timerTimeline.length - 1; i >= 0; i--) {
|
|
|
|
const timer = this._timerTimeline.at(i);
|
|
|
|
if (timer.type == type && !timer.isInitialized) {
|
|
|
|
timer.end(time);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.error('Couldn\'t find matching timer event start', {type, time});
|
|
|
|
}
|
|
|
|
|
2020-09-02 13:17:35 +00:00
|
|
|
get icTimeline() {
|
2020-10-19 10:45:42 +00:00
|
|
|
return this._icTimeline;
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get mapTimeline() {
|
2020-10-19 10:45:42 +00:00
|
|
|
return this._mapTimeline;
|
2020-09-02 13:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 12:39:55 +00:00
|
|
|
get deoptTimeline() {
|
|
|
|
return this._deoptTimeline;
|
|
|
|
}
|
|
|
|
|
2020-11-30 10:34:28 +00:00
|
|
|
get codeTimeline() {
|
|
|
|
return this._codeTimeline;
|
|
|
|
}
|
|
|
|
|
2021-06-07 14:57:44 +00:00
|
|
|
get tickTimeline() {
|
|
|
|
return this._tickTimeline;
|
|
|
|
}
|
|
|
|
|
2021-06-28 19:46:31 +00:00
|
|
|
get timerTimeline() {
|
|
|
|
return this._timerTimeline;
|
|
|
|
}
|
|
|
|
|
2020-09-23 10:30:17 +00:00
|
|
|
get scripts() {
|
2020-10-19 10:45:42 +00:00
|
|
|
return this._profile.scripts_.filter(script => script !== undefined);
|
2020-09-23 10:30:17 +00:00
|
|
|
}
|
2020-12-14 09:41:32 +00:00
|
|
|
|
|
|
|
get profile() {
|
|
|
|
return this._profile;
|
|
|
|
}
|
2020-10-26 18:02:54 +00:00
|
|
|
}
|