Commit 213152dd authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[tools] Remove outdated ic-processor

- Remove ic-processor.html since it's been fully integrated in the
  system-analyzer
- Use new tools/system-analyzer/processor.mjs for command line
  ic-processor
- Update tools landing page
- Partially fix dependencies on web specific components in helper.mjs

Bug: v8:10644
Change-Id: I0c99ff7c7859684e53aa3ab22489b1a8242e1a6e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2498606Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70799}
parent 47ea5fb6
<!DOCTYPE html>
<html>
<!--
Copyright 2016 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.
-->
<head>
<meta charset="utf-8">
<title>V8 IC explorer</title>
<style>
html {
font-family: monospace;
}
.entry-details {}
.entry-details TD {}
.details {
width: 0.1em;
}
.details span {
padding: 0 0.4em 0 0.4em;
background-color: black;
color: white;
border-radius: 25px;
text-align: center;
cursor: -webkit-zoom-in;
}
.count {
text-align: right;
width: 5em;
}
.percentage {
text-align: right;
width: 5em;
}
.key {
padding-left: 1em;
}
.drilldown-group-title {
font-weight: bold;
padding: 0.5em 0 0.2em 0;
}
</style>
<script type="module" src="./ic-processor.js"></script>
<script>
"use strict"
let entries = [];
let properties = ['type', 'category', 'functionName', 'filePosition',
'state', 'key', 'map', 'reason', 'file',
];
// For compatibility with console scripts:
print = console.log;
class CustomIcProcessor extends IcProcessor {
constructor() {
super();
this.entries = [];
}
functionName(pc) {
let entry = this.profile_.findEntry(pc);
return this.formatName(entry);
}
processPropertyIC(
type, pc, time, line, column, old_state, new_state, map, key, modifier,
slow_reason) {
let fnName = this.functionName(pc);
this.entries.push(new Entry(
type, fnName, time, line, column, key, old_state, new_state, map,
slow_reason));
}
};
class Entry {
constructor(
type, fn_file, time, line, column, key, oldState, newState, map, reason,
additional) {
this.time = time;
this.type = type;
this.category = 'other';
if (this.type.indexOf('Store') !== -1) {
this.category = 'Store';
} else if (this.type.indexOf('Load') !== -1) {
this.category = 'Load';
}
let parts = fn_file.split(' ');
this.functionName = parts[0];
this.file = parts[1];
let position = line + ':' + column;
this.filePosition = this.file + ':' + position;
this.oldState = oldState;
this.newState = newState;
this.state = this.oldState + ' → ' + this.newState;
this.key = key;
this.map = map.toString(16);
this.reason = reason;
this.additional = additional;
}
parseMapProperties(parts, offset) {
let next = parts[++offset];
if (!next.startsWith('dict')) return offset;
this.propertiesMode = next.substr(5) == '0' ? 'fast' : 'slow';
this.numberOfOwnProperties = parts[++offset].substr(4);
next = parts[++offset];
this.instanceType = next.substr(5, next.length - 6);
return offset;
}
parsePositionAndFile(parts, start) {
// find the position of 'at' in the parts array.
let offset = start;
for (let i = start + 1; i < parts.length; i++) {
offset++;
if (parts[i] == 'at') break;
}
if (parts[offset] !== 'at') return -1;
this.position = parts.slice(start, offset).join(' ');
offset += 1;
this.isNative = parts[offset] == 'native'
offset += this.isNative ? 1 : 0;
this.file = parts[offset];
return offset;
}
}
function loadFile() {
let files = document.getElementById("uploadInput").files;
let file = files[0];
let reader = new FileReader();
reader.onload = function(evt) {
let icProcessor = new CustomIcProcessor();
icProcessor.processString(this.result);
entries = icProcessor.entries;
document.getElementById("count").innerHTML = entries.length;
updateTable();
}
reader.readAsText(file);
initGroupKeySelect();
}
class Group {
constructor(property, key, entry) {
this.property = property;
this.key = key;
this.count = 1;
this.entries = [entry];
this.percentage = undefined;
this.groups = undefined;
}
add(entry) {
this.count++;
this.entries.push(entry)
}
createSubGroups() {
this.groups = {};
for (let i = 0; i < properties.length; i++) {
let subProperty = properties[i];
if (this.property == subProperty) continue;
this.groups[subProperty] = groupBy(this.entries, subProperty);
}
}
}
function groupBy(entries, property) {
let accumulator = Object.create(null);
let length = entries.length;
for (let i = 0; i < length; i++) {
let entry = entries[i];
let key = entry[property];
if (accumulator[key] == undefined) {
accumulator[key] = new Group(property, key, entry)
} else {
let group = accumulator[key];
if (group.entries == undefined) console.log([group, entry]);
group.add(entry)
}
}
let result = []
for (let key in accumulator) {
let group = accumulator[key];
group.percentage = Math.round(group.count / length * 100 * 100) / 100;
result.push(group);
}
result.sort((a, b) => {
return b.count - a.count
});
return result;
}
function escapeHtml(unsafe) {
if (!unsafe) return "";
return unsafe.toString()
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
function processValue(unsafe) {
if (!unsafe) return "";
if (!unsafe.startsWith("http")) return escapeHtml(unsafe);
let a = document.createElement("a");
a.href = unsafe;
a.textContent = unsafe;
return a;
}
function updateTable() {
let select = document.getElementById("group-key");
let key = select.options[select.selectedIndex].text;
let tableBody = document.getElementById("table-body");
removeAllChildren(tableBody);
let groups = groupBy(entries, key, true);
display(groups, tableBody);
}
function selecedOption(node) {
return node.options[node.selectedIndex]
}
function removeAllChildren(node) {
while (node.firstChild) {
node.removeChild(node.firstChild);
}
}
function display(entries, parent) {
let fragment = document.createDocumentFragment();
function td(tr, content, className) {
let node = document.createElement("td");
if (typeof content == "object") {
node.appendChild(content);
} else {
node.innerHTML = content;
}
node.className = className
tr.appendChild(node);
return node
}
let max = Math.min(1000, entries.length)
for (let i = 0; i < max; i++) {
let entry = entries[i];
let tr = document.createElement("tr");
tr.entry = entry;
td(tr, '<span onclick="toggleDetails(this)">&#8505;</a>', 'details');
td(tr, entry.percentage + "%", 'percentage');
td(tr, entry.count, 'count');
td(tr, processValue(entry.key), 'key');
fragment.appendChild(tr);
}
let omitted = entries.length - max;
if (omitted > 0) {
let tr = document.createElement("tr");
let tdNode = td(tr, 'Omitted ' + omitted + " entries.");
tdNode.colSpan = 4;
fragment.appendChild(tr);
}
parent.appendChild(fragment);
}
function displayDrilldown(entry, previousSibling) {
let tr = document.createElement('tr');
tr.className = "entry-details";
tr.style.display = "none";
// indent by one td.
tr.appendChild(document.createElement("td"));
let td = document.createElement("td");
td.colSpan = 3;
for (let key in entry.groups) {
td.appendChild(displayDrilldownGroup(entry, key));
}
tr.appendChild(td);
// Append the new TR after previousSibling.
previousSibling.parentNode.insertBefore(tr, previousSibling.nextSibling)
}
function displayDrilldownGroup(entry, key) {
let max = 20;
let group = entry.groups[key];
let div = document.createElement("div")
div.className = 'drilldown-group-title'
div.textContent = key + ' [top ' + max + ' out of ' + group.length + ']';
let table = document.createElement("table");
display(group.slice(0, max), table, false)
div.appendChild(table);
return div;
}
function toggleDetails(node) {
let tr = node.parentNode.parentNode;
let entry = tr.entry;
// Create subgroup in-place if the don't exist yet.
if (entry.groups === undefined) {
entry.createSubGroups();
displayDrilldown(entry, tr);
}
let details = tr.nextSibling;
let display = details.style.display;
if (display != "none") {
display = "none";
} else {
display = "table-row"
};
details.style.display = display;
}
function initGroupKeySelect() {
let select = document.getElementById("group-key");
select.options.length = 0;
for (let i in properties) {
let option = document.createElement("option");
option.text = properties[i];
select.add(option);
}
}
function handleOnLoad() {
document.querySelector("#uploadInput").focus();
}
</script>
</head>
<body onload="handleOnLoad()">
<h1>
<span style="color: #00FF00">I</span>
<span style="color: #FF00FF">C</span>
<span style="color: #00FFFF">E</span>
</h1> Your IC-Explorer.
<div id="legend" style="padding-right: 200px">
<div style="float:right; border-style: solid; border-width: 1px; padding:20px">
0 uninitialized<br>
X no feedback<br>
1 monomorphic<br>
^ recompute handler<br>
P polymorphic<br>
N megamorphic<br>
G generic
</div>
</div>
<h2>Usage</h2> Run your script with <code>--trace_ic</code> and upload <code>v8.log</code> on this page:<br/>
<code>/path/to/d8 --trace_ic your_script.js</code>
<h2>Data</h2>
<form name="fileForm">
<p>
<input id="uploadInput" type="file" name="files" onchange="loadFile();"> trace entries: <span id="count">0</span>
</p>
</form>
<h2>Result</h2>
<p>
Group-Key:
<select id="group-key" onchange="updateTable()"></select>
</p>
<p>
<table id="table" width="100%">
<tbody id="table-body">
</tbody>
</table>
</p>
</body>
</html>
......@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { IcProcessor, ArgumentsProcessor, readFile } from "./ic-processor.mjs";
import { Processor } from "./system-analyzer/processor.mjs";
import { WebInspector } from "./sourcemap.mjs";
import { BaseArgumentsProcessor } from "./arguments.mjs";
function processArguments(args) {
var processor = new ArgumentsProcessor(args);
......@@ -14,6 +15,18 @@ function processArguments(args) {
}
}
/**
* A thin wrapper around shell's 'read' function showing a file name on error.
*/
export function readFile(fileName) {
try {
return read(fileName);
} catch (e) {
print(fileName + ': ' + (e.message || e));
throw e;
}
}
function initSourceMapSupport() {
// Pull dev tools source maps into our name space.
SourceMap = WebInspector.SourceMap;
......@@ -26,11 +39,56 @@ function initSourceMapSupport() {
};
}
var params = processArguments(arguments);
var sourceMap = null;
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']
};
}
getDefaultResults() {
return {
logFileName: 'v8.log',
range: 'auto,auto',
};
}
}
const params = processArguments(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
var icProcessor = new IcProcessor();
icProcessor.processLogFile(params.logFileName);
const processor = new Processor();
processor.processLogFile(params.logFileName);
const typeAccumulator = new Map();
const accumulator = {
__proto__: null,
LoadGlobalIC: 0,
StoreGlobalIC: 0,
LoadIC: 0,
StoreIC: 0,
KeyedLoadIC: 0,
KeyedStoreIC: 0,
StoreInArrayLiteralIC: 0,
}
for (const ic of processor.icTimeline.all) {
print(
ic.type + ' (' + ic.oldState + '->' + ic.newState + ic.modifier + ') at ' +
ic.filePosition + ' ' + ic.key +
' (map 0x' + ic.map.toString(16) + ')' +
(ic.reason ? ' ' + ic.reason : '') + ' time: ' + ic.time);
accumulator[ic.type]++;
}
print("========================================");
for (const key of Object.keys(accumulator)) {
print(key + ": " + accumulator[key]);
}
// 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.
import { LogReader, parseString, parseVarArgs } from "./logreader.mjs";
import { BaseArgumentsProcessor } from "./arguments.mjs";
import { Profile } from "./profile.mjs";
function inherits(childCtor, parentCtor) {
childCtor.prototype.__proto__ = parentCtor.prototype;
};
/**
* A thin wrapper around shell's 'read' function showing a file name on error.
*/
export 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);
}
export function IcProcessor() {
var propertyICParser = [
parseInt, parseInt, parseInt, parseInt, parseString, parseString,
parseInt, parseString, parseString, parseString];
LogReader.call(this, {
'code-creation': {
parsers: [parseString, parseInt, parseInt, parseInt, parseInt,
parseString, parseVarArgs],
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 },
'LoadGlobalIC': {
parsers : propertyICParser,
processor: this.processPropertyIC.bind(this, "LoadGlobalIC") },
'StoreGlobalIC': {
parsers : propertyICParser,
processor: this.processPropertyIC.bind(this, "StoreGlobalIC") },
'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") },
'StoreInArrayLiteralIC': {
parsers : propertyICParser,
processor: this.processPropertyIC.bind(this, "StoreInArrayLiteralIC") },
});
this.profile_ = new Profile();
this.LoadGlobalIC = 0;
this.StoreGlobalIC = 0;
this.LoadIC = 0;
this.StoreIC = 0;
this.KeyedLoadIC = 0;
this.KeyedStoreIC = 0;
this.StoreInArrayLiteralIC = 0;
}
inherits(IcProcessor, LogReader);
/**
* @override
*/
IcProcessor.prototype.printError = function(str) {
print(str);
};
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);
}
}
IcProcessor.prototype.processLogFile = function(fileName) {
this.collectEntries = true
this.lastLogFileName_ = fileName;
var line;
while (line = readline()) {
this.processLogLine(line);
}
print();
print("=====================");
print("LoadGlobal: " + this.LoadGlobalIC);
print("StoreGlobal: " + this.StoreGlobalIC);
print("Load: " + this.LoadIC);
print("Store: " + this.StoreIC);
print("KeyedLoad: " + this.KeyedLoadIC);
print("KeyedStore: " + this.KeyedStoreIC);
print("StoreInArrayLiteral: " + this.StoreInArrayLiteralIC);
};
IcProcessor.prototype.addEntry = function(entry) {
this.entries.push(entry);
}
IcProcessor.prototype.processCodeCreation = function(
type, kind, timestamp, start, size, name, maybe_func) {
if (maybe_func.length) {
var funcAddr = parseInt(maybe_func[0]);
var state = parseState(maybe_func[1]);
this.profile_.addFuncCode(type, name, timestamp, start, size, funcAddr, state);
} else {
this.profile_.addCode(type, name, timestamp, start, size);
}
};
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;
return entry.getState() + array[1];
}
IcProcessor.prototype.processPropertyIC = function (
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);
}
export 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']
};
}
getDefaultResults() {
return {
logFileName: 'v8.log',
range: 'auto,auto',
};
}
}
......@@ -75,10 +75,6 @@ dd, dt {
<dt><a href="./heap-stats/index.html">Heap Stats</a></dt>
<dd>Visualize heap memory usage.</dd>
</div>
<div class="card">
<dt><a href="./ic-explorer.html">IC Explorer</a></dt>
<dd>Analyse inline caches.</dd>
</div>
<div class="card">
<dt><a href="./parse-processor.html">Parse Processor</a></dt>
<dd>Analyse parse, compile and first-execution.</dd>
......
......@@ -101,21 +101,8 @@ class CSSColor {
static get violet() {
return CSSColor.getColor('violet');
}
}
const kColors = [
CSSColor.green,
CSSColor.violet,
CSSColor.orange,
CSSColor.yellow,
CSSColor.primaryColor,
CSSColor.red,
CSSColor.blue,
CSSColor.yellow,
CSSColor.secondaryColor,
];
function typeToColor(type) {
switch (type) {
case 'new':
......@@ -201,5 +188,5 @@ class V8CustomElement extends HTMLElement {
export {
defineCustomElement, V8CustomElement, removeAllChildren,
$, div, kColors, typeToColor, CSSColor
$, div, typeToColor, CSSColor
};
......@@ -6,7 +6,7 @@ import { LogEntry } from './log.mjs';
export class IcLogEntry extends LogEntry {
constructor(
type, fn_file, time, line, column, key, oldState, newState, map, reason,
script, additional) {
script, modifier, additional) {
super(type, time);
this.category = 'other';
if (this.type.indexOf('Store') !== -1) {
......@@ -27,6 +27,7 @@ export class IcLogEntry extends LogEntry {
this.reason = reason;
this.additional = additional;
this.script = script;
this.modifier = modifier;
}
parseMapProperties(parts, offset) {
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { typeToColor } from '../helper.mjs';
import { LogEntry } from './log.mjs';
// ===========================================================================
......@@ -184,10 +183,6 @@ class Edge {
this.to = to;
}
getColor() {
return typeToColor(this.type);
}
finishSetup() {
let from = this.from;
if (from) from.addEdge(this);
......
// 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.
import { V8CustomElement, defineCustomElement } from "../helper.mjs";
import { V8CustomElement, defineCustomElement, typeToColor } from "../helper.mjs";
import { FocusEvent, SelectionEvent } from "../events.mjs";
defineCustomElement(
......@@ -122,7 +122,7 @@ defineCustomElement(
addTransitionEdge(map) {
let classes = ["transitionEdge"];
let edge = this.div(classes);
edge.style.backgroundColor = map.edge.getColor();
edge.style.backgroundColor = typeToColor(map.edge);
let labelNode = this.div("transitionLabel");
labelNode.innerText = map.edge.toString();
edge.appendChild(labelNode);
......@@ -151,7 +151,7 @@ defineCustomElement(
addMapNode(map) {
let node = this.div("map");
if (map.edge) node.style.backgroundColor = map.edge.getColor();
if (map.edge) node.style.backgroundColor = typeToColor(map.edge);
node.map = map;
node.addEventListener("click", () => this.selectMap(map));
if (map.children.length > 1) {
......
......@@ -240,7 +240,7 @@ export class Processor extends LogReader {
// TODO: Use SourcePosition here directly
let entry = new IcLogEntry(
type, fnName, time, line, column, key, old_state, new_state, map,
slow_reason, script);
slow_reason, script, modifier);
if (script) {
entry.sourcePosition = script.addSourcePosition(line, column, entry);
}
......@@ -352,4 +352,4 @@ export class Processor extends LogReader {
get scripts() {
return this._profile.scripts_.filter(script => script !== undefined);
}
}
\ No newline at end of file
}
......@@ -3,8 +3,7 @@
// found in the LICENSE file.
import {
defineCustomElement, V8CustomElement,
kColors, CSSColor
defineCustomElement, V8CustomElement, CSSColor
} from '../helper.mjs';
import { kChunkWidth, kChunkHeight } from "../log/map.mjs";
import {
......@@ -12,6 +11,19 @@ import {
SynchronizeSelectionEvent
} from '../events.mjs';
const kColors = [
CSSColor.green,
CSSColor.violet,
CSSColor.orange,
CSSColor.yellow,
CSSColor.primaryColor,
CSSColor.red,
CSSColor.blue,
CSSColor.yellow,
CSSColor.secondaryColor,
];
defineCustomElement('./timeline/timeline-track', (templateText) =>
class TimelineTrack extends V8CustomElement {
// TODO turn into static field once Safari supports it.
......
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