2017-03-04 13:04:58 +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.
|
|
|
|
|
|
|
|
"use strict"
|
|
|
|
|
|
|
|
function $(id) {
|
|
|
|
return document.getElementById(id);
|
|
|
|
}
|
|
|
|
|
2018-08-31 09:50:07 +00:00
|
|
|
function removeAllChildren(element) {
|
|
|
|
while (element.firstChild) {
|
|
|
|
element.removeChild(element.firstChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 09:39:44 +00:00
|
|
|
let components;
|
2017-03-04 13:04:58 +00:00
|
|
|
function createViews() {
|
2018-08-23 09:39:44 +00:00
|
|
|
components = [
|
|
|
|
new CallTreeView(),
|
|
|
|
new TimelineView(),
|
|
|
|
new HelpView(),
|
|
|
|
new SummaryView(),
|
|
|
|
new ModeBarView(),
|
2018-08-31 09:50:07 +00:00
|
|
|
new ScriptSourceView(),
|
2018-08-23 09:39:44 +00:00
|
|
|
];
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function emptyState() {
|
|
|
|
return {
|
|
|
|
file : null,
|
2018-08-23 09:39:44 +00:00
|
|
|
mode : null,
|
2017-03-22 16:02:25 +00:00
|
|
|
currentCodeId : null,
|
2018-08-31 09:50:07 +00:00
|
|
|
viewingSource: false,
|
2017-03-04 13:04:58 +00:00
|
|
|
start : 0,
|
|
|
|
end : Infinity,
|
2018-08-23 09:39:44 +00:00
|
|
|
timelineSize : {
|
|
|
|
width : 0,
|
|
|
|
height : 0
|
2017-03-04 13:04:58 +00:00
|
|
|
},
|
|
|
|
callTree : {
|
|
|
|
attribution : "js-exclude-bc",
|
|
|
|
categories : "code-type",
|
|
|
|
sort : "time"
|
2018-08-31 09:50:07 +00:00
|
|
|
},
|
|
|
|
sourceData: null
|
2017-03-04 13:04:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCallTreeState(state, callTreeState) {
|
|
|
|
state = Object.assign({}, state);
|
|
|
|
state.callTree = callTreeState;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
let main = {
|
|
|
|
currentState : emptyState(),
|
2017-03-17 12:21:03 +00:00
|
|
|
renderPending : false,
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
setMode(mode) {
|
2017-11-06 13:48:41 +00:00
|
|
|
if (mode !== main.currentState.mode) {
|
2017-03-22 16:02:25 +00:00
|
|
|
|
|
|
|
function setCallTreeModifiers(attribution, categories, sort) {
|
|
|
|
let callTreeState = Object.assign({}, main.currentState.callTree);
|
|
|
|
callTreeState.attribution = attribution;
|
|
|
|
callTreeState.categories = categories;
|
|
|
|
callTreeState.sort = sort;
|
|
|
|
return callTreeState;
|
|
|
|
}
|
|
|
|
|
|
|
|
let state = Object.assign({}, main.currentState);
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
switch (mode) {
|
|
|
|
case "bottom-up":
|
2017-03-22 16:02:25 +00:00
|
|
|
state.callTree =
|
|
|
|
setCallTreeModifiers("js-exclude-bc", "code-type", "time");
|
2017-03-04 13:04:58 +00:00
|
|
|
break;
|
|
|
|
case "top-down":
|
2017-03-22 16:02:25 +00:00
|
|
|
state.callTree =
|
|
|
|
setCallTreeModifiers("js-exclude-bc", "none", "time");
|
2017-03-04 13:04:58 +00:00
|
|
|
break;
|
|
|
|
case "function-list":
|
2017-03-22 16:02:25 +00:00
|
|
|
state.callTree =
|
|
|
|
setCallTreeModifiers("js-exclude-bc", "code-type", "own-time");
|
2017-03-04 13:04:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-22 16:02:25 +00:00
|
|
|
|
|
|
|
state.mode = mode;
|
|
|
|
|
|
|
|
main.currentState = state;
|
2017-03-04 13:04:58 +00:00
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setCallTreeAttribution(attribution) {
|
2017-11-06 13:48:41 +00:00
|
|
|
if (attribution !== main.currentState.attribution) {
|
2017-03-04 13:04:58 +00:00
|
|
|
let callTreeState = Object.assign({}, main.currentState.callTree);
|
|
|
|
callTreeState.attribution = attribution;
|
|
|
|
main.currentState = setCallTreeState(main.currentState, callTreeState);
|
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setCallTreeSort(sort) {
|
2017-11-06 13:48:41 +00:00
|
|
|
if (sort !== main.currentState.sort) {
|
2017-03-04 13:04:58 +00:00
|
|
|
let callTreeState = Object.assign({}, main.currentState.callTree);
|
|
|
|
callTreeState.sort = sort;
|
|
|
|
main.currentState = setCallTreeState(main.currentState, callTreeState);
|
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setCallTreeCategories(categories) {
|
2017-11-06 13:48:41 +00:00
|
|
|
if (categories !== main.currentState.categories) {
|
2017-03-04 13:04:58 +00:00
|
|
|
let callTreeState = Object.assign({}, main.currentState.callTree);
|
|
|
|
callTreeState.categories = categories;
|
|
|
|
main.currentState = setCallTreeState(main.currentState, callTreeState);
|
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setViewInterval(start, end) {
|
2017-11-06 13:48:41 +00:00
|
|
|
if (start !== main.currentState.start ||
|
|
|
|
end !== main.currentState.end) {
|
2017-03-04 13:04:58 +00:00
|
|
|
main.currentState = Object.assign({}, main.currentState);
|
|
|
|
main.currentState.start = start;
|
|
|
|
main.currentState.end = end;
|
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-08-31 09:50:07 +00:00
|
|
|
updateSources(file) {
|
|
|
|
let statusDiv = $("source-status");
|
|
|
|
if (!file) {
|
|
|
|
statusDiv.textContent = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!file.scripts || file.scripts.length === 0) {
|
|
|
|
statusDiv.textContent =
|
|
|
|
"Script source not available. Run profiler with --log-source-code.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
statusDiv.textContent = "Script source is available.";
|
|
|
|
main.currentState.sourceData = new SourceData(file);
|
|
|
|
},
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
setFile(file) {
|
2017-11-06 13:48:41 +00:00
|
|
|
if (file !== main.currentState.file) {
|
2018-08-23 09:39:44 +00:00
|
|
|
let lastMode = main.currentState.mode || "summary";
|
|
|
|
main.currentState = emptyState();
|
2017-03-04 13:04:58 +00:00
|
|
|
main.currentState.file = file;
|
2018-08-31 09:50:07 +00:00
|
|
|
main.updateSources(file);
|
2018-08-23 09:39:44 +00:00
|
|
|
main.setMode(lastMode);
|
2017-03-04 13:04:58 +00:00
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-08 15:03:22 +00:00
|
|
|
setCurrentCode(codeId) {
|
2017-11-06 13:48:41 +00:00
|
|
|
if (codeId !== main.currentState.currentCodeId) {
|
2017-03-08 15:03:22 +00:00
|
|
|
main.currentState = Object.assign({}, main.currentState);
|
|
|
|
main.currentState.currentCodeId = codeId;
|
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-08-31 09:50:07 +00:00
|
|
|
setViewingSource(value) {
|
|
|
|
if (main.currentState.viewingSource !== value) {
|
|
|
|
main.currentState = Object.assign({}, main.currentState);
|
|
|
|
main.currentState.viewingSource = value;
|
|
|
|
main.delayRender();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
onResize() {
|
2018-08-23 09:39:44 +00:00
|
|
|
main.delayRender();
|
2017-03-04 13:04:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLoad() {
|
|
|
|
function loadHandler(evt) {
|
|
|
|
let f = evt.target.files[0];
|
|
|
|
if (f) {
|
|
|
|
let reader = new FileReader();
|
|
|
|
reader.onload = function(event) {
|
2018-08-23 09:39:44 +00:00
|
|
|
main.setFile(JSON.parse(event.target.result));
|
2017-03-04 13:04:58 +00:00
|
|
|
};
|
|
|
|
reader.onerror = function(event) {
|
|
|
|
console.error(
|
|
|
|
"File could not be read! Code " + event.target.error.code);
|
|
|
|
};
|
|
|
|
reader.readAsText(f);
|
|
|
|
} else {
|
|
|
|
main.setFile(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("fileinput").addEventListener(
|
|
|
|
"change", loadHandler, false);
|
|
|
|
createViews();
|
|
|
|
},
|
|
|
|
|
|
|
|
delayRender() {
|
2017-03-17 12:21:03 +00:00
|
|
|
if (main.renderPending) return;
|
|
|
|
main.renderPending = true;
|
|
|
|
|
|
|
|
window.requestAnimationFrame(() => {
|
|
|
|
main.renderPending = false;
|
2017-03-04 13:04:58 +00:00
|
|
|
for (let c of components) {
|
|
|
|
c.render(main.currentState);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-13 08:33:00 +00:00
|
|
|
const CATEGORY_COLOR = "#f5f5f5";
|
|
|
|
const bucketDescriptors =
|
2017-03-04 13:04:58 +00:00
|
|
|
[ { kinds : [ "JSOPT" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#64dd17",
|
|
|
|
backgroundColor : "#80e27e",
|
2017-03-22 16:02:25 +00:00
|
|
|
text : "JS Optimized" },
|
2020-12-07 09:36:31 +00:00
|
|
|
{ kinds : [ "JSNCI" ],
|
|
|
|
color : "#3289a8",
|
|
|
|
backgroundColor : "#3289a8",
|
|
|
|
text : "JS NCI" },
|
|
|
|
{ kinds : [ "JSTURBOPROP" ],
|
|
|
|
color : "#693eb8",
|
|
|
|
backgroundColor : "#a6c452",
|
|
|
|
text : "JS Turboprop" },
|
2017-03-22 16:02:25 +00:00
|
|
|
{ kinds : [ "JSUNOPT", "BC" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#dd2c00",
|
|
|
|
backgroundColor : "#ff9e80",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "JS Unoptimized" },
|
|
|
|
{ kinds : [ "IC" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#ff6d00",
|
|
|
|
backgroundColor : "#ffab40",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "IC" },
|
|
|
|
{ kinds : [ "STUB", "BUILTIN", "REGEXP" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#ffd600",
|
|
|
|
backgroundColor : "#ffea00",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "Other generated" },
|
|
|
|
{ kinds : [ "CPP", "LIB" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#304ffe",
|
|
|
|
backgroundColor : "#6ab7ff",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "C++" },
|
|
|
|
{ kinds : [ "CPPEXT" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#003c8f",
|
|
|
|
backgroundColor : "#c0cfff",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "C++/external" },
|
2017-08-10 14:39:55 +00:00
|
|
|
{ kinds : [ "CPPPARSE" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#aa00ff",
|
|
|
|
backgroundColor : "#ffb2ff",
|
2017-08-10 14:39:55 +00:00
|
|
|
text : "C++/Parser" },
|
|
|
|
{ kinds : [ "CPPCOMPBC" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#43a047",
|
|
|
|
backgroundColor : "#88c399",
|
2017-08-10 14:39:55 +00:00
|
|
|
text : "C++/Bytecode compiler" },
|
2017-03-04 13:04:58 +00:00
|
|
|
{ kinds : [ "CPPCOMP" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#00e5ff",
|
|
|
|
backgroundColor : "#6effff",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "C++/Compiler" },
|
|
|
|
{ kinds : [ "CPPGC" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#6200ea",
|
|
|
|
backgroundColor : "#e1bee7",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "C++/GC" },
|
|
|
|
{ kinds : [ "UNKNOWN" ],
|
2018-08-13 08:33:00 +00:00
|
|
|
color : "#bdbdbd",
|
|
|
|
backgroundColor : "#efefef",
|
2017-03-04 13:04:58 +00:00
|
|
|
text : "Unknown" }
|
|
|
|
];
|
|
|
|
|
2017-11-06 13:48:41 +00:00
|
|
|
let kindToBucketDescriptor = {};
|
2017-03-17 12:06:09 +00:00
|
|
|
for (let i = 0; i < bucketDescriptors.length; i++) {
|
|
|
|
let bucket = bucketDescriptors[i];
|
|
|
|
for (let j = 0; j < bucket.kinds.length; j++) {
|
|
|
|
kindToBucketDescriptor[bucket.kinds[j]] = bucket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
function bucketFromKind(kind) {
|
|
|
|
for (let i = 0; i < bucketDescriptors.length; i++) {
|
|
|
|
let bucket = bucketDescriptors[i];
|
|
|
|
for (let j = 0; j < bucket.kinds.length; j++) {
|
|
|
|
if (bucket.kinds[j] === kind) {
|
|
|
|
return bucket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-03-08 15:03:22 +00:00
|
|
|
function codeTypeToText(type) {
|
|
|
|
switch (type) {
|
|
|
|
case "UNKNOWN":
|
|
|
|
return "Unknown";
|
2017-08-10 14:39:55 +00:00
|
|
|
case "CPPPARSE":
|
2018-08-13 08:33:00 +00:00
|
|
|
return "C++ Parser";
|
2017-08-10 14:39:55 +00:00
|
|
|
case "CPPCOMPBC":
|
2018-08-13 08:33:00 +00:00
|
|
|
return "C++ Bytecode Compiler)";
|
2017-03-08 15:03:22 +00:00
|
|
|
case "CPPCOMP":
|
2018-08-13 08:33:00 +00:00
|
|
|
return "C++ Compiler";
|
2017-03-08 15:03:22 +00:00
|
|
|
case "CPPGC":
|
2018-08-13 08:33:00 +00:00
|
|
|
return "C++ GC";
|
2017-03-08 15:03:22 +00:00
|
|
|
case "CPPEXT":
|
|
|
|
return "C++ External";
|
|
|
|
case "CPP":
|
|
|
|
return "C++";
|
|
|
|
case "LIB":
|
|
|
|
return "Library";
|
|
|
|
case "IC":
|
|
|
|
return "IC";
|
|
|
|
case "BC":
|
|
|
|
return "Bytecode";
|
|
|
|
case "STUB":
|
|
|
|
return "Stub";
|
|
|
|
case "BUILTIN":
|
|
|
|
return "Builtin";
|
|
|
|
case "REGEXP":
|
|
|
|
return "RegExp";
|
|
|
|
case "JSOPT":
|
|
|
|
return "JS opt";
|
2020-12-07 09:36:31 +00:00
|
|
|
case "JSNCI":
|
|
|
|
return "JS NCI";
|
|
|
|
case "JSTURBOPROP":
|
|
|
|
return "JS Turboprop";
|
2017-03-08 15:03:22 +00:00
|
|
|
case "JSUNOPT":
|
|
|
|
return "JS unopt";
|
|
|
|
}
|
|
|
|
console.error("Unknown type: " + type);
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
function createTypeNode(type) {
|
2017-03-08 15:03:22 +00:00
|
|
|
if (type === "CAT") {
|
|
|
|
return document.createTextNode("");
|
|
|
|
}
|
|
|
|
let span = document.createElement("span");
|
|
|
|
span.classList.add("code-type-chip");
|
|
|
|
span.textContent = codeTypeToText(type);
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
return span;
|
2017-03-08 15:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function filterFromFilterId(id) {
|
|
|
|
switch (id) {
|
|
|
|
case "full-tree":
|
|
|
|
return (type, kind) => true;
|
|
|
|
case "js-funs":
|
|
|
|
return (type, kind) => type !== 'CODE';
|
|
|
|
case "js-exclude-bc":
|
|
|
|
return (type, kind) =>
|
2018-08-13 13:45:39 +00:00
|
|
|
type !== 'CODE' || kind !== "BytecodeHandler";
|
2017-03-08 15:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
function createIndentNode(indent) {
|
2017-03-22 16:02:25 +00:00
|
|
|
let div = document.createElement("div");
|
|
|
|
div.style.display = "inline-block";
|
2018-08-13 13:45:39 +00:00
|
|
|
div.style.width = (indent + 0.5) + "em";
|
2017-03-22 16:02:25 +00:00
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
function createArrowNode() {
|
|
|
|
let span = document.createElement("span");
|
|
|
|
span.classList.add("tree-row-arrow");
|
|
|
|
return span;
|
|
|
|
}
|
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
function createFunctionNode(name, codeId) {
|
|
|
|
let nameElement = document.createElement("span");
|
|
|
|
nameElement.appendChild(document.createTextNode(name));
|
2018-08-13 13:45:39 +00:00
|
|
|
nameElement.classList.add("tree-row-name");
|
|
|
|
if (codeId !== -1) {
|
|
|
|
nameElement.classList.add("codeid-link");
|
|
|
|
nameElement.onclick = (event) => {
|
|
|
|
main.setCurrentCode(codeId);
|
|
|
|
// Prevent the click from bubbling to the row and causing it to
|
|
|
|
// collapse/expand.
|
|
|
|
event.stopPropagation();
|
|
|
|
};
|
|
|
|
}
|
2017-03-22 16:02:25 +00:00
|
|
|
return nameElement;
|
|
|
|
}
|
|
|
|
|
2018-08-31 09:50:07 +00:00
|
|
|
function createViewSourceNode(codeId) {
|
|
|
|
let linkElement = document.createElement("span");
|
|
|
|
linkElement.appendChild(document.createTextNode("View source"));
|
|
|
|
linkElement.classList.add("view-source-link");
|
|
|
|
linkElement.onclick = (event) => {
|
|
|
|
main.setCurrentCode(codeId);
|
|
|
|
main.setViewingSource(true);
|
|
|
|
// Prevent the click from bubbling to the row and causing it to
|
|
|
|
// collapse/expand.
|
|
|
|
event.stopPropagation();
|
|
|
|
};
|
|
|
|
return linkElement;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
const COLLAPSED_ARROW = "\u25B6";
|
|
|
|
const EXPANDED_ARROW = "\u25BC";
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
class CallTreeView {
|
|
|
|
constructor() {
|
|
|
|
this.element = $("calltree");
|
|
|
|
this.treeElement = $("calltree-table");
|
|
|
|
this.selectAttribution = $("calltree-attribution");
|
|
|
|
this.selectCategories = $("calltree-categories");
|
|
|
|
this.selectSort = $("calltree-sort");
|
|
|
|
|
|
|
|
this.selectAttribution.onchange = () => {
|
|
|
|
main.setCallTreeAttribution(this.selectAttribution.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.selectCategories.onchange = () => {
|
|
|
|
main.setCallTreeCategories(this.selectCategories.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.selectSort.onchange = () => {
|
|
|
|
main.setCallTreeSort(this.selectSort.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.currentState = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
sortFromId(id) {
|
|
|
|
switch (id) {
|
|
|
|
case "time":
|
2017-03-06 09:37:37 +00:00
|
|
|
return (c1, c2) => {
|
|
|
|
if (c1.ticks < c2.ticks) return 1;
|
|
|
|
else if (c1.ticks > c2.ticks) return -1;
|
|
|
|
return c2.ownTicks - c1.ownTicks;
|
2017-11-06 13:48:41 +00:00
|
|
|
};
|
2017-03-04 13:04:58 +00:00
|
|
|
case "own-time":
|
2017-03-06 09:37:37 +00:00
|
|
|
return (c1, c2) => {
|
|
|
|
if (c1.ownTicks < c2.ownTicks) return 1;
|
|
|
|
else if (c1.ownTicks > c2.ownTicks) return -1;
|
|
|
|
return c2.ticks - c1.ticks;
|
2017-11-06 13:48:41 +00:00
|
|
|
};
|
2017-03-04 13:04:58 +00:00
|
|
|
case "category-time":
|
|
|
|
return (c1, c2) => {
|
|
|
|
if (c1.type === c2.type) return c2.ticks - c1.ticks;
|
|
|
|
if (c1.type < c2.type) return 1;
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
case "category-own-time":
|
|
|
|
return (c1, c2) => {
|
|
|
|
if (c1.type === c2.type) return c2.ownTicks - c1.ownTicks;
|
|
|
|
if (c1.type < c2.type) return 1;
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expandTree(tree, indent) {
|
|
|
|
let index = 0;
|
|
|
|
let id = "R/";
|
|
|
|
let row = tree.row;
|
|
|
|
|
|
|
|
if (row) {
|
|
|
|
index = row.rowIndex;
|
|
|
|
id = row.id;
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
tree.arrow.textContent = EXPANDED_ARROW;
|
|
|
|
// Collapse the children when the row is clicked again.
|
|
|
|
let expandHandler = row.onclick;
|
|
|
|
row.onclick = () => {
|
|
|
|
this.collapseRow(tree, expandHandler);
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect the children, and sort them by ticks.
|
|
|
|
let children = [];
|
2017-03-06 09:37:37 +00:00
|
|
|
let filter =
|
2017-03-08 15:03:22 +00:00
|
|
|
filterFromFilterId(this.currentState.callTree.attribution);
|
2017-03-06 09:37:37 +00:00
|
|
|
for (let childId in tree.children) {
|
|
|
|
let child = tree.children[childId];
|
|
|
|
if (child.ticks > 0) {
|
|
|
|
children.push(child);
|
|
|
|
if (child.delayedExpansion) {
|
|
|
|
expandTreeNode(this.currentState.file, child, filter);
|
|
|
|
}
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
children.sort(this.sortFromId(this.currentState.callTree.sort));
|
|
|
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let node = children[i];
|
|
|
|
let row = this.rows.insertRow(index);
|
|
|
|
row.id = id + i + "/";
|
|
|
|
|
2018-08-13 08:33:00 +00:00
|
|
|
if (node.type === "CAT") {
|
|
|
|
row.style.backgroundColor = CATEGORY_COLOR;
|
|
|
|
} else {
|
2017-03-04 13:04:58 +00:00
|
|
|
row.style.backgroundColor = bucketFromKind(node.type).backgroundColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inclusive time % cell.
|
|
|
|
let c = row.insertCell();
|
|
|
|
c.textContent = (node.ticks * 100 / this.tickCount).toFixed(2) + "%";
|
|
|
|
c.style.textAlign = "right";
|
|
|
|
// Percent-of-parent cell.
|
|
|
|
c = row.insertCell();
|
|
|
|
c.textContent = (node.ticks * 100 / tree.ticks).toFixed(2) + "%";
|
|
|
|
c.style.textAlign = "right";
|
|
|
|
// Exclusive time % cell.
|
2017-03-22 16:02:25 +00:00
|
|
|
if (this.currentState.mode !== "bottom-up") {
|
2017-03-04 13:04:58 +00:00
|
|
|
c = row.insertCell(-1);
|
|
|
|
c.textContent = (node.ownTicks * 100 / this.tickCount).toFixed(2) + "%";
|
|
|
|
c.style.textAlign = "right";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the name cell.
|
|
|
|
let nameCell = row.insertCell();
|
2018-08-13 13:45:39 +00:00
|
|
|
nameCell.appendChild(createIndentNode(indent + 1));
|
|
|
|
let arrow = createArrowNode();
|
|
|
|
nameCell.appendChild(arrow);
|
|
|
|
nameCell.appendChild(createTypeNode(node.type));
|
2017-03-22 16:02:25 +00:00
|
|
|
nameCell.appendChild(createFunctionNode(node.name, node.codeId));
|
2018-08-31 09:50:07 +00:00
|
|
|
if (main.currentState.sourceData &&
|
2018-10-09 05:03:17 +00:00
|
|
|
node.codeId >= 0 &&
|
|
|
|
main.currentState.sourceData.hasSource(
|
|
|
|
this.currentState.file.code[node.codeId].func)) {
|
2018-08-31 09:50:07 +00:00
|
|
|
nameCell.appendChild(createViewSourceNode(node.codeId));
|
|
|
|
}
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
// Inclusive ticks cell.
|
|
|
|
c = row.insertCell();
|
|
|
|
c.textContent = node.ticks;
|
|
|
|
c.style.textAlign = "right";
|
2017-03-22 16:02:25 +00:00
|
|
|
if (this.currentState.mode !== "bottom-up") {
|
2017-03-04 13:04:58 +00:00
|
|
|
// Exclusive ticks cell.
|
|
|
|
c = row.insertCell(-1);
|
|
|
|
c.textContent = node.ownTicks;
|
|
|
|
c.style.textAlign = "right";
|
|
|
|
}
|
|
|
|
if (node.children.length > 0) {
|
2018-08-13 13:45:39 +00:00
|
|
|
arrow.textContent = COLLAPSED_ARROW;
|
|
|
|
row.onclick = () => { this.expandTree(node, indent + 1); };
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node.row = row;
|
2018-08-13 13:45:39 +00:00
|
|
|
node.arrow = arrow;
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
collapseRow(tree, expandHandler) {
|
2017-03-04 13:04:58 +00:00
|
|
|
let row = tree.row;
|
|
|
|
let id = row.id;
|
|
|
|
let index = row.rowIndex;
|
|
|
|
while (row.rowIndex < this.rows.rows.length &&
|
|
|
|
this.rows.rows[index].id.startsWith(id)) {
|
|
|
|
this.rows.deleteRow(index);
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
tree.arrow.textContent = COLLAPSED_ARROW;
|
|
|
|
row.onclick = expandHandler;
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
fillSelects(mode, calltree) {
|
2017-03-04 13:04:58 +00:00
|
|
|
function addOptions(e, values, current) {
|
|
|
|
while (e.options.length > 0) {
|
|
|
|
e.remove(0);
|
|
|
|
}
|
|
|
|
for (let i = 0; i < values.length; i++) {
|
|
|
|
let option = document.createElement("option");
|
|
|
|
option.value = values[i].value;
|
|
|
|
option.textContent = values[i].text;
|
|
|
|
e.appendChild(option);
|
|
|
|
}
|
|
|
|
e.value = current;
|
|
|
|
}
|
|
|
|
|
|
|
|
let attributions = [
|
|
|
|
{ value : "js-exclude-bc",
|
|
|
|
text : "Attribute bytecode handlers to caller" },
|
|
|
|
{ value : "full-tree",
|
|
|
|
text : "Count each code object separately" },
|
|
|
|
{ value : "js-funs",
|
|
|
|
text : "Attribute non-functions to JS functions" }
|
|
|
|
];
|
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
switch (mode) {
|
2017-03-04 13:04:58 +00:00
|
|
|
case "bottom-up":
|
|
|
|
addOptions(this.selectAttribution, attributions, calltree.attribution);
|
|
|
|
addOptions(this.selectCategories, [
|
|
|
|
{ value : "code-type", text : "Code type" },
|
|
|
|
{ value : "none", text : "None" }
|
|
|
|
], calltree.categories);
|
|
|
|
addOptions(this.selectSort, [
|
|
|
|
{ value : "time", text : "Time (including children)" },
|
|
|
|
{ value : "category-time", text : "Code category, time" },
|
|
|
|
], calltree.sort);
|
|
|
|
return;
|
|
|
|
case "top-down":
|
|
|
|
addOptions(this.selectAttribution, attributions, calltree.attribution);
|
|
|
|
addOptions(this.selectCategories, [
|
2017-04-11 11:33:47 +00:00
|
|
|
{ value : "none", text : "None" },
|
|
|
|
{ value : "rt-entry", text : "Runtime entries" }
|
2017-03-04 13:04:58 +00:00
|
|
|
], calltree.categories);
|
|
|
|
addOptions(this.selectSort, [
|
|
|
|
{ value : "time", text : "Time (including children)" },
|
|
|
|
{ value : "own-time", text : "Own time" },
|
|
|
|
{ value : "category-time", text : "Code category, time" },
|
|
|
|
{ value : "category-own-time", text : "Code category, own time"}
|
|
|
|
], calltree.sort);
|
|
|
|
return;
|
|
|
|
case "function-list":
|
|
|
|
addOptions(this.selectAttribution, attributions, calltree.attribution);
|
|
|
|
addOptions(this.selectCategories, [
|
2017-03-06 09:37:37 +00:00
|
|
|
{ value : "code-type", text : "Code type" },
|
2017-03-04 13:04:58 +00:00
|
|
|
{ value : "none", text : "None" }
|
|
|
|
], calltree.categories);
|
|
|
|
addOptions(this.selectSort, [
|
|
|
|
{ value : "own-time", text : "Own time" },
|
|
|
|
{ value : "time", text : "Time (including children)" },
|
|
|
|
{ value : "category-own-time", text : "Code category, own time"},
|
|
|
|
{ value : "category-time", text : "Code category, time" },
|
|
|
|
], calltree.sort);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.error("Unexpected mode");
|
|
|
|
}
|
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
static isCallTreeMode(mode) {
|
|
|
|
switch (mode) {
|
|
|
|
case "bottom-up":
|
|
|
|
case "top-down":
|
|
|
|
case "function-list":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
render(newState) {
|
|
|
|
let oldState = this.currentState;
|
2017-03-22 16:02:25 +00:00
|
|
|
if (!newState.file || !CallTreeView.isCallTreeMode(newState.mode)) {
|
2017-03-04 13:04:58 +00:00
|
|
|
this.element.style.display = "none";
|
2017-03-22 16:02:25 +00:00
|
|
|
this.currentState = null;
|
2017-03-04 13:04:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentState = newState;
|
|
|
|
if (oldState) {
|
|
|
|
if (newState.file === oldState.file &&
|
|
|
|
newState.start === oldState.start &&
|
|
|
|
newState.end === oldState.end &&
|
2017-03-22 16:02:25 +00:00
|
|
|
newState.mode === oldState.mode &&
|
2017-03-04 13:04:58 +00:00
|
|
|
newState.callTree.attribution === oldState.callTree.attribution &&
|
|
|
|
newState.callTree.categories === oldState.callTree.categories &&
|
|
|
|
newState.callTree.sort === oldState.callTree.sort) {
|
|
|
|
// No change => just return.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element.style.display = "inherit";
|
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
let mode = this.currentState.mode;
|
|
|
|
if (!oldState || mode !== oldState.mode) {
|
2017-03-04 13:04:58 +00:00
|
|
|
// Technically, we should also call this if attribution, categories or
|
|
|
|
// sort change, but the selection is already highlighted by the combobox
|
|
|
|
// itself, so we do need to do anything here.
|
2017-03-22 16:02:25 +00:00
|
|
|
this.fillSelects(newState.mode, newState.callTree);
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 09:37:37 +00:00
|
|
|
let ownTimeClass = (mode === "bottom-up") ? "numeric-hidden" : "numeric";
|
2017-03-04 13:04:58 +00:00
|
|
|
let ownTimeTh = $(this.treeElement.id + "-own-time-header");
|
2017-03-06 09:37:37 +00:00
|
|
|
ownTimeTh.classList = ownTimeClass;
|
2017-03-04 13:04:58 +00:00
|
|
|
let ownTicksTh = $(this.treeElement.id + "-own-ticks-header");
|
2017-03-06 09:37:37 +00:00
|
|
|
ownTicksTh.classList = ownTimeClass;
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
// Build the tree.
|
|
|
|
let stackProcessor;
|
2017-03-08 15:03:22 +00:00
|
|
|
let filter = filterFromFilterId(this.currentState.callTree.attribution);
|
2017-03-04 13:04:58 +00:00
|
|
|
if (mode === "top-down") {
|
2017-04-11 11:33:47 +00:00
|
|
|
if (this.currentState.callTree.categories === "rt-entry") {
|
|
|
|
stackProcessor =
|
|
|
|
new RuntimeCallTreeProcessor();
|
|
|
|
} else {
|
|
|
|
stackProcessor =
|
|
|
|
new PlainCallTreeProcessor(filter, false);
|
|
|
|
}
|
2017-03-04 13:04:58 +00:00
|
|
|
} else if (mode === "function-list") {
|
2017-03-06 09:37:37 +00:00
|
|
|
stackProcessor = new FunctionListTree(
|
|
|
|
filter, this.currentState.callTree.categories === "code-type");
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
console.assert(mode === "bottom-up");
|
2017-11-06 13:48:41 +00:00
|
|
|
if (this.currentState.callTree.categories === "none") {
|
2017-03-04 13:04:58 +00:00
|
|
|
stackProcessor =
|
|
|
|
new PlainCallTreeProcessor(filter, true);
|
|
|
|
} else {
|
|
|
|
console.assert(this.currentState.callTree.categories === "code-type");
|
|
|
|
stackProcessor =
|
|
|
|
new CategorizedCallTreeProcessor(filter, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.tickCount =
|
|
|
|
generateTree(this.currentState.file,
|
|
|
|
this.currentState.start,
|
|
|
|
this.currentState.end,
|
|
|
|
stackProcessor);
|
|
|
|
// TODO(jarin) Handle the case when tick count is negative.
|
|
|
|
|
|
|
|
this.tree = stackProcessor.tree;
|
|
|
|
|
|
|
|
// Remove old content of the table, replace with new one.
|
|
|
|
let oldRows = this.treeElement.getElementsByTagName("tbody");
|
|
|
|
let newRows = document.createElement("tbody");
|
|
|
|
this.rows = newRows;
|
|
|
|
|
|
|
|
// Populate the table.
|
|
|
|
this.expandTree(this.tree, 0);
|
|
|
|
|
|
|
|
// Swap in the new rows.
|
|
|
|
this.treeElement.replaceChild(newRows, oldRows[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TimelineView {
|
|
|
|
constructor() {
|
|
|
|
this.element = $("timeline");
|
|
|
|
this.canvas = $("timeline-canvas");
|
|
|
|
this.legend = $("timeline-legend");
|
2017-03-08 15:03:22 +00:00
|
|
|
this.currentCode = $("timeline-currentCode");
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
this.canvas.onmousedown = this.onMouseDown.bind(this);
|
|
|
|
this.canvas.onmouseup = this.onMouseUp.bind(this);
|
|
|
|
this.canvas.onmousemove = this.onMouseMove.bind(this);
|
|
|
|
|
|
|
|
this.selectionStart = null;
|
|
|
|
this.selectionEnd = null;
|
|
|
|
this.selecting = false;
|
|
|
|
|
2017-03-07 13:29:43 +00:00
|
|
|
this.fontSize = 12;
|
2017-03-17 12:06:09 +00:00
|
|
|
this.imageOffset = Math.round(this.fontSize * 1.2);
|
2017-03-22 16:02:25 +00:00
|
|
|
this.functionTimelineHeight = 24;
|
|
|
|
this.functionTimelineTickHeight = 16;
|
2017-03-07 13:29:43 +00:00
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
this.currentState = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseDown(e) {
|
|
|
|
this.selectionStart =
|
|
|
|
e.clientX - this.canvas.getBoundingClientRect().left;
|
|
|
|
this.selectionEnd = this.selectionStart + 1;
|
|
|
|
this.selecting = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseMove(e) {
|
|
|
|
if (this.selecting) {
|
|
|
|
this.selectionEnd =
|
|
|
|
e.clientX - this.canvas.getBoundingClientRect().left;
|
|
|
|
this.drawSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseUp(e) {
|
|
|
|
if (this.selectionStart !== null) {
|
|
|
|
let x = e.clientX - this.canvas.getBoundingClientRect().left;
|
|
|
|
if (Math.abs(x - this.selectionStart) < 10) {
|
|
|
|
this.selectionStart = null;
|
|
|
|
this.selectionEnd = null;
|
|
|
|
let ctx = this.canvas.getContext("2d");
|
2017-03-17 12:06:09 +00:00
|
|
|
ctx.drawImage(this.buffer, 0, this.imageOffset);
|
2017-03-04 13:04:58 +00:00
|
|
|
} else {
|
|
|
|
this.selectionEnd = x;
|
|
|
|
this.drawSelection();
|
|
|
|
}
|
|
|
|
let file = this.currentState.file;
|
|
|
|
if (file) {
|
|
|
|
let start = this.selectionStart === null ? 0 : this.selectionStart;
|
|
|
|
let end = this.selectionEnd === null ? Infinity : this.selectionEnd;
|
|
|
|
let firstTime = file.ticks[0].tm;
|
|
|
|
let lastTime = file.ticks[file.ticks.length - 1].tm;
|
|
|
|
|
|
|
|
let width = this.buffer.width;
|
|
|
|
|
|
|
|
start = (start / width) * (lastTime - firstTime) + firstTime;
|
|
|
|
end = (end / width) * (lastTime - firstTime) + firstTime;
|
|
|
|
|
|
|
|
if (end < start) {
|
|
|
|
let temp = start;
|
|
|
|
start = end;
|
|
|
|
end = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
main.setViewInterval(start, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.selecting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
drawSelection() {
|
|
|
|
let ctx = this.canvas.getContext("2d");
|
|
|
|
|
2017-03-07 13:29:43 +00:00
|
|
|
// Draw the timeline image.
|
|
|
|
ctx.drawImage(this.buffer, 0, this.imageOffset);
|
|
|
|
|
|
|
|
// Draw the current interval highlight.
|
|
|
|
let left;
|
|
|
|
let right;
|
2017-03-04 13:04:58 +00:00
|
|
|
if (this.selectionStart !== null && this.selectionEnd !== null) {
|
|
|
|
ctx.fillStyle = "rgba(0, 0, 0, 0.3)";
|
2017-03-07 13:29:43 +00:00
|
|
|
left = Math.min(this.selectionStart, this.selectionEnd);
|
|
|
|
right = Math.max(this.selectionStart, this.selectionEnd);
|
2017-03-08 15:03:22 +00:00
|
|
|
let height = this.buffer.height - this.functionTimelineHeight;
|
|
|
|
ctx.fillRect(0, this.imageOffset, left, height);
|
|
|
|
ctx.fillRect(right, this.imageOffset, this.buffer.width - right, height);
|
2017-03-07 13:29:43 +00:00
|
|
|
} else {
|
|
|
|
left = 0;
|
|
|
|
right = this.buffer.width;
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 13:29:43 +00:00
|
|
|
// Draw the scale text.
|
|
|
|
let file = this.currentState.file;
|
|
|
|
ctx.fillStyle = "white";
|
|
|
|
ctx.fillRect(0, 0, this.canvas.width, this.imageOffset);
|
|
|
|
if (file && file.ticks.length > 0) {
|
|
|
|
let firstTime = file.ticks[0].tm;
|
|
|
|
let lastTime = file.ticks[file.ticks.length - 1].tm;
|
|
|
|
|
|
|
|
let leftTime =
|
|
|
|
firstTime + left / this.canvas.width * (lastTime - firstTime);
|
|
|
|
let rightTime =
|
|
|
|
firstTime + right / this.canvas.width * (lastTime - firstTime);
|
|
|
|
|
|
|
|
let leftText = (leftTime / 1000000).toFixed(3) + "s";
|
|
|
|
let rightText = (rightTime / 1000000).toFixed(3) + "s";
|
|
|
|
|
|
|
|
ctx.textBaseline = 'top';
|
|
|
|
ctx.font = this.fontSize + "px Arial";
|
|
|
|
ctx.fillStyle = "black";
|
|
|
|
|
|
|
|
let leftWidth = ctx.measureText(leftText).width;
|
|
|
|
let rightWidth = ctx.measureText(rightText).width;
|
|
|
|
|
|
|
|
let leftStart = left - leftWidth / 2;
|
|
|
|
let rightStart = right - rightWidth / 2;
|
|
|
|
|
|
|
|
if (leftStart < 0) leftStart = 0;
|
|
|
|
if (rightStart + rightWidth > this.canvas.width) {
|
|
|
|
rightStart = this.canvas.width - rightWidth;
|
|
|
|
}
|
|
|
|
if (leftStart + leftWidth > rightStart) {
|
|
|
|
if (leftStart > this.canvas.width - (rightStart - rightWidth)) {
|
|
|
|
rightStart = leftStart + leftWidth;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
leftStart = rightStart - leftWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.fillText(leftText, leftStart, 0);
|
|
|
|
ctx.fillText(rightText, rightStart, 0);
|
|
|
|
}
|
|
|
|
}
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
render(newState) {
|
|
|
|
let oldState = this.currentState;
|
|
|
|
|
|
|
|
if (!newState.file) {
|
|
|
|
this.element.style.display = "none";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-31 09:50:07 +00:00
|
|
|
let width = Math.round(document.documentElement.clientWidth - 20);
|
|
|
|
let height = Math.round(document.documentElement.clientHeight / 5);
|
2018-08-23 09:39:44 +00:00
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
if (oldState) {
|
2018-08-23 09:39:44 +00:00
|
|
|
if (width === oldState.timelineSize.width &&
|
|
|
|
height === oldState.timelineSize.height &&
|
2017-03-04 13:04:58 +00:00
|
|
|
newState.file === oldState.file &&
|
2017-03-08 15:03:22 +00:00
|
|
|
newState.currentCodeId === oldState.currentCodeId &&
|
2017-03-04 13:04:58 +00:00
|
|
|
newState.start === oldState.start &&
|
|
|
|
newState.end === oldState.end) {
|
|
|
|
// No change, nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 12:51:12 +00:00
|
|
|
this.currentState = newState;
|
2018-08-23 09:39:44 +00:00
|
|
|
this.currentState.timelineSize.width = width;
|
|
|
|
this.currentState.timelineSize.height = height;
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
this.element.style.display = "inherit";
|
|
|
|
|
2018-08-14 12:51:12 +00:00
|
|
|
let file = this.currentState.file;
|
|
|
|
|
|
|
|
const minPixelsPerBucket = 10;
|
|
|
|
const minTicksPerBucket = 8;
|
|
|
|
let maxBuckets = Math.round(file.ticks.length / minTicksPerBucket);
|
|
|
|
let bucketCount = Math.min(
|
|
|
|
Math.round(width / minPixelsPerBucket), maxBuckets);
|
|
|
|
|
|
|
|
// Make sure the canvas has the right dimensions.
|
2017-03-04 13:04:58 +00:00
|
|
|
this.canvas.width = width;
|
2017-03-07 13:29:43 +00:00
|
|
|
this.canvas.height = height;
|
|
|
|
|
|
|
|
// Make space for the selection text.
|
|
|
|
height -= this.imageOffset;
|
2017-03-04 13:04:58 +00:00
|
|
|
|
2017-03-08 15:03:22 +00:00
|
|
|
let currentCodeId = this.currentState.currentCodeId;
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
let firstTime = file.ticks[0].tm;
|
|
|
|
let lastTime = file.ticks[file.ticks.length - 1].tm;
|
|
|
|
let start = Math.max(this.currentState.start, firstTime);
|
|
|
|
let end = Math.min(this.currentState.end, lastTime);
|
|
|
|
|
|
|
|
this.selectionStart = (start - firstTime) / (lastTime - firstTime) * width;
|
|
|
|
this.selectionEnd = (end - firstTime) / (lastTime - firstTime) * width;
|
|
|
|
|
|
|
|
let stackProcessor = new CategorySampler(file, bucketCount);
|
|
|
|
generateTree(file, 0, Infinity, stackProcessor);
|
2017-03-08 15:03:22 +00:00
|
|
|
let codeIdProcessor = new FunctionTimelineProcessor(
|
|
|
|
currentCodeId,
|
|
|
|
filterFromFilterId(this.currentState.callTree.attribution));
|
|
|
|
generateTree(file, 0, Infinity, codeIdProcessor);
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
let buffer = document.createElement("canvas");
|
|
|
|
|
2017-03-07 13:29:43 +00:00
|
|
|
buffer.width = width;
|
|
|
|
buffer.height = height;
|
2017-03-04 13:04:58 +00:00
|
|
|
|
|
|
|
// Calculate the bar heights for each bucket.
|
2017-03-08 15:03:22 +00:00
|
|
|
let graphHeight = height - this.functionTimelineHeight;
|
2017-03-04 13:04:58 +00:00
|
|
|
let buckets = stackProcessor.buckets;
|
|
|
|
let bucketsGraph = [];
|
|
|
|
for (let i = 0; i < buckets.length; i++) {
|
|
|
|
let sum = 0;
|
|
|
|
let bucketData = [];
|
|
|
|
let total = buckets[i].total;
|
2018-08-14 12:51:12 +00:00
|
|
|
if (total > 0) {
|
|
|
|
for (let j = 0; j < bucketDescriptors.length; j++) {
|
|
|
|
let desc = bucketDescriptors[j];
|
|
|
|
for (let k = 0; k < desc.kinds.length; k++) {
|
|
|
|
sum += buckets[i][desc.kinds[k]];
|
|
|
|
}
|
|
|
|
bucketData.push(Math.round(graphHeight * sum / total));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No ticks fell into this bucket. Fill with "Unknown."
|
|
|
|
for (let j = 0; j < bucketDescriptors.length; j++) {
|
|
|
|
let desc = bucketDescriptors[j];
|
|
|
|
bucketData.push(desc.text === "Unknown" ? graphHeight : 0);
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bucketsGraph.push(bucketData);
|
|
|
|
}
|
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
// Draw the category graph into the buffer.
|
2018-08-14 12:51:12 +00:00
|
|
|
let bucketWidth = width / (bucketsGraph.length - 1);
|
2017-03-04 13:04:58 +00:00
|
|
|
let ctx = buffer.getContext('2d');
|
|
|
|
for (let i = 0; i < bucketsGraph.length - 1; i++) {
|
|
|
|
let bucketData = bucketsGraph[i];
|
|
|
|
let nextBucketData = bucketsGraph[i + 1];
|
2018-08-14 12:51:12 +00:00
|
|
|
let x1 = Math.round(i * bucketWidth);
|
|
|
|
let x2 = Math.round((i + 1) * bucketWidth);
|
2017-03-04 13:04:58 +00:00
|
|
|
for (let j = 0; j < bucketData.length; j++) {
|
|
|
|
ctx.beginPath();
|
2018-08-14 12:51:12 +00:00
|
|
|
ctx.moveTo(x1, j > 0 ? bucketData[j - 1] : 0);
|
|
|
|
ctx.lineTo(x2, j > 0 ? nextBucketData[j - 1] : 0);
|
2017-03-17 12:06:09 +00:00
|
|
|
ctx.lineTo(x2, nextBucketData[j]);
|
|
|
|
ctx.lineTo(x1, bucketData[j]);
|
2017-03-04 13:04:58 +00:00
|
|
|
ctx.closePath();
|
|
|
|
ctx.fillStyle = bucketDescriptors[j].color;
|
|
|
|
ctx.fill();
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 16:02:25 +00:00
|
|
|
|
|
|
|
// Draw the function ticks.
|
2017-03-08 15:03:22 +00:00
|
|
|
let functionTimelineYOffset = graphHeight;
|
2017-03-22 16:02:25 +00:00
|
|
|
let functionTimelineTickHeight = this.functionTimelineTickHeight;
|
|
|
|
let functionTimelineHalfHeight =
|
|
|
|
Math.round(functionTimelineTickHeight / 2);
|
2017-03-08 15:03:22 +00:00
|
|
|
let timestampScaler = width / (lastTime - firstTime);
|
2017-03-22 16:02:25 +00:00
|
|
|
let timestampToX = (t) => Math.round((t - firstTime) * timestampScaler);
|
2017-03-08 15:03:22 +00:00
|
|
|
ctx.fillStyle = "white";
|
|
|
|
ctx.fillRect(
|
|
|
|
0,
|
|
|
|
functionTimelineYOffset,
|
|
|
|
buffer.width,
|
2017-03-22 16:02:25 +00:00
|
|
|
this.functionTimelineHeight);
|
2017-03-08 15:03:22 +00:00
|
|
|
for (let i = 0; i < codeIdProcessor.blocks.length; i++) {
|
|
|
|
let block = codeIdProcessor.blocks[i];
|
2017-03-17 12:06:09 +00:00
|
|
|
let bucket = kindToBucketDescriptor[block.kind];
|
|
|
|
ctx.fillStyle = bucket.color;
|
2017-03-08 15:03:22 +00:00
|
|
|
ctx.fillRect(
|
2017-03-22 16:02:25 +00:00
|
|
|
timestampToX(block.start),
|
2017-03-08 15:03:22 +00:00
|
|
|
functionTimelineYOffset,
|
|
|
|
Math.max(1, Math.round((block.end - block.start) * timestampScaler)),
|
2017-03-22 16:02:25 +00:00
|
|
|
block.topOfStack ?
|
|
|
|
functionTimelineTickHeight : functionTimelineHalfHeight);
|
2017-03-17 12:06:09 +00:00
|
|
|
}
|
|
|
|
ctx.strokeStyle = "black";
|
|
|
|
ctx.lineWidth = "1";
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(0, functionTimelineYOffset + 0.5);
|
|
|
|
ctx.lineTo(buffer.width, functionTimelineYOffset + 0.5);
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.strokeStyle = "rgba(0,0,0,0.2)";
|
|
|
|
ctx.lineWidth = "1";
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(0, functionTimelineYOffset + functionTimelineHalfHeight - 0.5);
|
|
|
|
ctx.lineTo(buffer.width,
|
|
|
|
functionTimelineYOffset + functionTimelineHalfHeight - 0.5);
|
|
|
|
ctx.stroke();
|
2017-03-04 13:04:58 +00:00
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
// Draw marks for optimizations and deoptimizations in the function
|
|
|
|
// timeline.
|
|
|
|
if (currentCodeId && currentCodeId >= 0 &&
|
|
|
|
file.code[currentCodeId].func) {
|
|
|
|
let y = Math.round(functionTimelineYOffset + functionTimelineTickHeight +
|
|
|
|
(this.functionTimelineHeight - functionTimelineTickHeight) / 2);
|
|
|
|
let func = file.functions[file.code[currentCodeId].func];
|
|
|
|
for (let i = 0; i < func.codes.length; i++) {
|
|
|
|
let code = file.code[func.codes[i]];
|
|
|
|
if (code.kind === "Opt") {
|
|
|
|
if (code.deopt) {
|
|
|
|
// Draw deoptimization mark.
|
|
|
|
let x = timestampToX(code.deopt.tm);
|
|
|
|
ctx.lineWidth = 0.7;
|
|
|
|
ctx.strokeStyle = "red";
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(x - 3, y - 3);
|
|
|
|
ctx.lineTo(x + 3, y + 3);
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(x - 3, y + 3);
|
|
|
|
ctx.lineTo(x + 3, y - 3);
|
|
|
|
ctx.stroke();
|
|
|
|
}
|
|
|
|
// Draw optimization mark.
|
|
|
|
let x = timestampToX(code.tm);
|
|
|
|
ctx.lineWidth = 0.7;
|
|
|
|
ctx.strokeStyle = "blue";
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(x - 3, y - 3);
|
|
|
|
ctx.lineTo(x, y);
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(x - 3, y + 3);
|
|
|
|
ctx.lineTo(x, y);
|
|
|
|
ctx.stroke();
|
|
|
|
} else {
|
|
|
|
// Draw code creation mark.
|
|
|
|
let x = Math.round(timestampToX(code.tm));
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = "black";
|
|
|
|
ctx.arc(x, y, 3, 0, 2 * Math.PI);
|
|
|
|
ctx.fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
// Remember stuff for later.
|
|
|
|
this.buffer = buffer;
|
|
|
|
|
|
|
|
// Draw the buffer.
|
|
|
|
this.drawSelection();
|
|
|
|
|
|
|
|
// (Re-)Populate the graph legend.
|
|
|
|
while (this.legend.cells.length > 0) {
|
|
|
|
this.legend.deleteCell(0);
|
|
|
|
}
|
|
|
|
let cell = this.legend.insertCell(-1);
|
|
|
|
cell.textContent = "Legend: ";
|
|
|
|
cell.style.padding = "1ex";
|
|
|
|
for (let i = 0; i < bucketDescriptors.length; i++) {
|
|
|
|
let cell = this.legend.insertCell(-1);
|
|
|
|
cell.style.padding = "1ex";
|
|
|
|
let desc = bucketDescriptors[i];
|
|
|
|
let div = document.createElement("div");
|
|
|
|
div.style.display = "inline-block";
|
|
|
|
div.style.width = "0.6em";
|
|
|
|
div.style.height = "1.2ex";
|
|
|
|
div.style.backgroundColor = desc.color;
|
|
|
|
div.style.borderStyle = "solid";
|
|
|
|
div.style.borderWidth = "1px";
|
|
|
|
div.style.borderColor = "Black";
|
|
|
|
cell.appendChild(div);
|
|
|
|
cell.appendChild(document.createTextNode(" " + desc.text));
|
|
|
|
}
|
2017-03-08 15:03:22 +00:00
|
|
|
|
2018-08-31 09:50:07 +00:00
|
|
|
removeAllChildren(this.currentCode);
|
2017-03-08 15:03:22 +00:00
|
|
|
if (currentCodeId) {
|
|
|
|
let currentCode = file.code[currentCodeId];
|
|
|
|
this.currentCode.appendChild(document.createTextNode(currentCode.name));
|
|
|
|
} else {
|
|
|
|
this.currentCode.appendChild(document.createTextNode("<none>"));
|
|
|
|
}
|
2017-03-04 13:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-22 16:02:25 +00:00
|
|
|
class ModeBarView {
|
|
|
|
constructor() {
|
|
|
|
let modeBar = this.element = $("mode-bar");
|
|
|
|
|
|
|
|
function addMode(id, text, active) {
|
|
|
|
let div = document.createElement("div");
|
|
|
|
div.classList = "mode-button" + (active ? " active-mode-button" : "");
|
|
|
|
div.id = "mode-" + id;
|
|
|
|
div.textContent = text;
|
|
|
|
div.onclick = () => {
|
|
|
|
if (main.currentState.mode === id) return;
|
|
|
|
let old = $("mode-" + main.currentState.mode);
|
|
|
|
old.classList = "mode-button";
|
|
|
|
div.classList = "mode-button active-mode-button";
|
|
|
|
main.setMode(id);
|
|
|
|
};
|
|
|
|
modeBar.appendChild(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
addMode("summary", "Summary", true);
|
|
|
|
addMode("bottom-up", "Bottom up");
|
|
|
|
addMode("top-down", "Top down");
|
|
|
|
addMode("function-list", "Functions");
|
|
|
|
}
|
|
|
|
|
|
|
|
render(newState) {
|
|
|
|
if (!newState.file) {
|
|
|
|
this.element.style.display = "none";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element.style.display = "inherit";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SummaryView {
|
|
|
|
constructor() {
|
|
|
|
this.element = $("summary");
|
|
|
|
this.currentState = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
render(newState) {
|
|
|
|
let oldState = this.currentState;
|
|
|
|
|
|
|
|
if (!newState.file || newState.mode !== "summary") {
|
|
|
|
this.element.style.display = "none";
|
|
|
|
this.currentState = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentState = newState;
|
|
|
|
if (oldState) {
|
|
|
|
if (newState.file === oldState.file &&
|
|
|
|
newState.start === oldState.start &&
|
|
|
|
newState.end === oldState.end) {
|
|
|
|
// No change, nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.element.style.display = "inherit";
|
2018-08-31 09:50:07 +00:00
|
|
|
removeAllChildren(this.element);
|
2017-03-22 16:02:25 +00:00
|
|
|
|
|
|
|
let stats = computeOptimizationStats(
|
|
|
|
this.currentState.file, newState.start, newState.end);
|
|
|
|
|
|
|
|
let table = document.createElement("table");
|
|
|
|
let rows = document.createElement("tbody");
|
|
|
|
|
|
|
|
function addRow(text, number, indent) {
|
|
|
|
let row = rows.insertRow(-1);
|
|
|
|
let textCell = row.insertCell(-1);
|
|
|
|
textCell.textContent = text;
|
|
|
|
let numberCell = row.insertCell(-1);
|
|
|
|
numberCell.textContent = number;
|
|
|
|
if (indent) {
|
|
|
|
textCell.style.textIndent = indent + "em";
|
|
|
|
numberCell.style.textIndent = indent + "em";
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
function makeCollapsible(row, arrow) {
|
|
|
|
arrow.textContent = EXPANDED_ARROW;
|
|
|
|
let expandHandler = row.onclick;
|
|
|
|
row.onclick = () => {
|
2017-03-22 16:02:25 +00:00
|
|
|
let id = row.id;
|
|
|
|
let index = row.rowIndex + 1;
|
|
|
|
while (index < rows.rows.length &&
|
|
|
|
rows.rows[index].id.startsWith(id)) {
|
|
|
|
rows.deleteRow(index);
|
|
|
|
}
|
2018-08-13 13:45:39 +00:00
|
|
|
arrow.textContent = COLLAPSED_ARROW;
|
|
|
|
row.onclick = expandHandler;
|
2017-03-22 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
function expandDeoptInstances(row, arrow, instances, indent, kind) {
|
2017-03-22 16:02:25 +00:00
|
|
|
let index = row.rowIndex;
|
|
|
|
for (let i = 0; i < instances.length; i++) {
|
|
|
|
let childRow = rows.insertRow(index + 1);
|
|
|
|
childRow.id = row.id + i + "/";
|
|
|
|
|
|
|
|
let deopt = instances[i].deopt;
|
|
|
|
|
|
|
|
let textCell = childRow.insertCell(-1);
|
|
|
|
textCell.appendChild(document.createTextNode(deopt.posText));
|
|
|
|
textCell.style.textIndent = indent + "em";
|
|
|
|
let reasonCell = childRow.insertCell(-1);
|
|
|
|
reasonCell.appendChild(
|
|
|
|
document.createTextNode("Reason: " + deopt.reason));
|
|
|
|
reasonCell.style.textIndent = indent + "em";
|
|
|
|
}
|
2018-08-13 13:45:39 +00:00
|
|
|
makeCollapsible(row, arrow);
|
2017-03-22 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
function expandDeoptFunctionList(row, arrow, list, indent, kind) {
|
2017-03-22 16:02:25 +00:00
|
|
|
let index = row.rowIndex;
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
|
let childRow = rows.insertRow(index + 1);
|
|
|
|
childRow.id = row.id + i + "/";
|
|
|
|
|
|
|
|
let textCell = childRow.insertCell(-1);
|
2018-08-13 13:45:39 +00:00
|
|
|
textCell.appendChild(createIndentNode(indent));
|
|
|
|
let childArrow = createArrowNode();
|
|
|
|
textCell.appendChild(childArrow);
|
2017-03-22 16:02:25 +00:00
|
|
|
textCell.appendChild(
|
|
|
|
createFunctionNode(list[i].f.name, list[i].f.codes[0]));
|
|
|
|
|
|
|
|
let numberCell = childRow.insertCell(-1);
|
|
|
|
numberCell.textContent = list[i].instances.length;
|
|
|
|
numberCell.style.textIndent = indent + "em";
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
childArrow.textContent = COLLAPSED_ARROW;
|
|
|
|
childRow.onclick = () => {
|
2017-03-22 16:02:25 +00:00
|
|
|
expandDeoptInstances(
|
2018-08-13 13:45:39 +00:00
|
|
|
childRow, childArrow, list[i].instances, indent + 1);
|
2017-03-22 16:02:25 +00:00
|
|
|
};
|
|
|
|
}
|
2018-08-13 13:45:39 +00:00
|
|
|
makeCollapsible(row, arrow);
|
2017-03-22 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:45:39 +00:00
|
|
|
function expandOptimizedFunctionList(row, arrow, list, indent, kind) {
|
2017-03-22 16:02:25 +00:00
|
|
|
let index = row.rowIndex;
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
|
let childRow = rows.insertRow(index + 1);
|
|
|
|
childRow.id = row.id + i + "/";
|
|
|
|
|
|
|
|
let textCell = childRow.insertCell(-1);
|
|
|
|
textCell.appendChild(
|
|
|
|
createFunctionNode(list[i].f.name, list[i].f.codes[0]));
|
|
|
|
textCell.style.textIndent = indent + "em";
|
|
|
|
|
|
|
|
let numberCell = childRow.insertCell(-1);
|
|
|
|
numberCell.textContent = list[i].instances.length;
|
|
|
|
numberCell.style.textIndent = indent + "em";
|
|
|
|
}
|
2018-08-13 13:45:39 +00:00
|
|
|
makeCollapsible(row, arrow);
|
2017-03-22 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function addExpandableRow(text, list, indent, kind) {
|
|
|
|
let row = rows.insertRow(-1);
|
|
|
|
|
|
|
|
row.id = "opt-table/" + kind + "/";
|
2018-08-13 08:33:00 +00:00
|
|
|
row.style.backgroundColor = CATEGORY_COLOR;
|
2017-03-22 16:02:25 +00:00
|
|
|
|
|
|
|
let textCell = row.insertCell(-1);
|
2018-08-13 13:45:39 +00:00
|
|
|
textCell.appendChild(createIndentNode(indent));
|
|
|
|
let arrow = createArrowNode();
|
|
|
|
textCell.appendChild(arrow);
|
2017-03-22 16:02:25 +00:00
|
|
|
textCell.appendChild(document.createTextNode(text));
|
|
|
|
|
|
|
|
let numberCell = row.insertCell(-1);
|
|
|
|
numberCell.textContent = list.count;
|
|
|
|
if (indent) {
|
|
|
|
numberCell.style.textIndent = indent + "em";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list.count > 0) {
|
2018-08-13 13:45:39 +00:00
|
|
|
arrow.textContent = COLLAPSED_ARROW;
|
2017-03-22 16:02:25 +00:00
|
|
|
if (kind === "opt") {
|
2018-08-13 13:45:39 +00:00
|
|
|
row.onclick = () => {
|
2017-03-22 16:02:25 +00:00
|
|
|
expandOptimizedFunctionList(
|
2018-08-13 13:45:39 +00:00
|
|
|
row, arrow, list.functions, indent + 1, kind);
|
2017-03-22 16:02:25 +00:00
|
|
|
};
|
|
|
|
} else {
|
2018-08-13 13:45:39 +00:00
|
|
|
row.onclick = () => {
|
2017-03-22 16:02:25 +00:00
|
|
|
expandDeoptFunctionList(
|
2018-08-13 13:45:39 +00:00
|
|
|
row, arrow, list.functions, indent + 1, kind);
|
2017-03-22 16:02:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
addRow("Total function count:", stats.functionCount);
|
|
|
|
addRow("Optimized function count:", stats.optimizedFunctionCount, 1);
|
2020-12-07 09:36:31 +00:00
|
|
|
if (stats.turbopropOptimizedFunctionCount != 0) {
|
|
|
|
addRow("Turboprop optimized function count:", stats.turbopropOptimizedFunctionCount, 1);
|
|
|
|
}
|
2017-03-22 16:02:25 +00:00
|
|
|
addRow("Deoptimized function count:", stats.deoptimizedFunctionCount, 2);
|
|
|
|
|
|
|
|
addExpandableRow("Optimization count:", stats.optimizations, 0, "opt");
|
2020-12-07 09:36:31 +00:00
|
|
|
if (stats.turbopropOptimizedFunctionCount != 0) {
|
|
|
|
addExpandableRow("Turboprop Optimization count:", stats.turbopropOptimizations, 0, "tp");
|
|
|
|
}
|
2017-03-22 16:02:25 +00:00
|
|
|
let deoptCount = stats.eagerDeoptimizations.count +
|
|
|
|
stats.softDeoptimizations.count + stats.lazyDeoptimizations.count;
|
|
|
|
addRow("Deoptimization count:", deoptCount);
|
|
|
|
addExpandableRow("Eager:", stats.eagerDeoptimizations, 1, "eager");
|
|
|
|
addExpandableRow("Lazy:", stats.lazyDeoptimizations, 1, "lazy");
|
|
|
|
addExpandableRow("Soft:", stats.softDeoptimizations, 1, "soft");
|
2020-12-07 09:36:31 +00:00
|
|
|
if (stats.softBailouts.count != 0) {
|
|
|
|
addExpandableRow("SoftBailout:", stats.softBailouts, 1, "softbailout");
|
|
|
|
}
|
|
|
|
if (stats.eagerBailouts.count != 0) {
|
|
|
|
addExpandableRow("EagerBailout:", stats.eagerBailouts, 1, "eagerbailout");
|
|
|
|
}
|
2017-03-22 16:02:25 +00:00
|
|
|
|
|
|
|
table.appendChild(rows);
|
|
|
|
this.element.appendChild(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 09:50:07 +00:00
|
|
|
class ScriptSourceView {
|
|
|
|
constructor() {
|
|
|
|
this.table = $("source-viewer");
|
|
|
|
this.hideButton = $("source-viewer-hide-button");
|
|
|
|
this.hideButton.onclick = () => {
|
|
|
|
main.setViewingSource(false);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render(newState) {
|
|
|
|
let oldState = this.currentState;
|
|
|
|
if (!newState.file || !newState.viewingSource) {
|
|
|
|
this.table.style.display = "none";
|
|
|
|
this.hideButton.style.display = "none";
|
|
|
|
this.currentState = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oldState) {
|
|
|
|
if (newState.file === oldState.file &&
|
|
|
|
newState.currentCodeId === oldState.currentCodeId &&
|
|
|
|
newState.viewingSource === oldState.viewingSource) {
|
|
|
|
// No change, nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.currentState = newState;
|
|
|
|
|
|
|
|
this.table.style.display = "inline-block";
|
|
|
|
this.hideButton.style.display = "inline";
|
|
|
|
removeAllChildren(this.table);
|
|
|
|
|
2018-10-08 05:44:29 +00:00
|
|
|
let functionId =
|
|
|
|
this.currentState.file.code[this.currentState.currentCodeId].func;
|
2018-08-31 09:50:07 +00:00
|
|
|
let sourceView =
|
2018-10-08 05:44:29 +00:00
|
|
|
this.currentState.sourceData.generateSourceView(functionId);
|
2018-08-31 09:50:07 +00:00
|
|
|
for (let i = 0; i < sourceView.source.length; i++) {
|
|
|
|
let sampleCount = sourceView.lineSampleCounts[i] || 0;
|
|
|
|
let sampleProportion = sourceView.samplesTotal > 0 ?
|
|
|
|
sampleCount / sourceView.samplesTotal : 0;
|
|
|
|
let heatBucket;
|
|
|
|
if (sampleProportion === 0) {
|
|
|
|
heatBucket = "line-none";
|
|
|
|
} else if (sampleProportion < 0.2) {
|
|
|
|
heatBucket = "line-cold";
|
|
|
|
} else if (sampleProportion < 0.4) {
|
|
|
|
heatBucket = "line-mediumcold";
|
|
|
|
} else if (sampleProportion < 0.6) {
|
|
|
|
heatBucket = "line-mediumhot";
|
|
|
|
} else if (sampleProportion < 0.8) {
|
|
|
|
heatBucket = "line-hot";
|
|
|
|
} else {
|
|
|
|
heatBucket = "line-superhot";
|
|
|
|
}
|
|
|
|
|
|
|
|
let row = this.table.insertRow(-1);
|
|
|
|
|
|
|
|
let lineNumberCell = row.insertCell(-1);
|
|
|
|
lineNumberCell.classList.add("source-line-number");
|
|
|
|
lineNumberCell.textContent = i + sourceView.firstLineNumber;
|
|
|
|
|
|
|
|
let sampleCountCell = row.insertCell(-1);
|
|
|
|
sampleCountCell.classList.add(heatBucket);
|
|
|
|
sampleCountCell.textContent = sampleCount;
|
|
|
|
|
|
|
|
let sourceLineCell = row.insertCell(-1);
|
|
|
|
sourceLineCell.classList.add(heatBucket);
|
|
|
|
sourceLineCell.textContent = sourceView.source[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
$("timeline-currentCode").scrollIntoView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SourceData {
|
|
|
|
constructor(file) {
|
|
|
|
this.scripts = new Map();
|
2018-10-08 05:44:29 +00:00
|
|
|
for (let i = 0; i < file.scripts.length; i++) {
|
|
|
|
const scriptBlock = file.scripts[i];
|
2018-08-31 09:50:07 +00:00
|
|
|
if (scriptBlock === null) continue; // Array may be sparse.
|
2020-12-07 09:36:31 +00:00
|
|
|
if (scriptBlock.source === undefined) continue;
|
2018-08-31 09:50:07 +00:00
|
|
|
let source = scriptBlock.source.split("\n");
|
2018-10-08 05:44:29 +00:00
|
|
|
this.scripts.set(i, source);
|
2018-08-31 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.functions = new Map();
|
|
|
|
for (let codeId = 0; codeId < file.code.length; ++codeId) {
|
|
|
|
let codeBlock = file.code[codeId];
|
2018-10-09 05:03:17 +00:00
|
|
|
if (codeBlock.source && codeBlock.func !== undefined) {
|
2018-10-08 05:44:29 +00:00
|
|
|
let data = this.functions.get(codeBlock.func);
|
2018-08-31 09:50:07 +00:00
|
|
|
if (!data) {
|
2018-10-08 05:44:29 +00:00
|
|
|
data = new FunctionSourceData(codeBlock.source.script,
|
|
|
|
codeBlock.source.start,
|
2018-08-31 09:50:07 +00:00
|
|
|
codeBlock.source.end);
|
2018-10-08 05:44:29 +00:00
|
|
|
this.functions.set(codeBlock.func, data);
|
2018-08-31 09:50:07 +00:00
|
|
|
}
|
|
|
|
data.addSourceBlock(codeId, codeBlock.source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let tick of file.ticks) {
|
|
|
|
let stack = tick.s;
|
|
|
|
for (let i = 0; i < stack.length; i += 2) {
|
|
|
|
let codeId = stack[i];
|
|
|
|
if (codeId < 0) continue;
|
2018-10-09 05:03:17 +00:00
|
|
|
let functionId = file.code[codeId].func;
|
2018-10-08 05:44:29 +00:00
|
|
|
if (this.functions.has(functionId)) {
|
2018-08-31 09:50:07 +00:00
|
|
|
let codeOffset = stack[i + 1];
|
2018-10-08 05:44:29 +00:00
|
|
|
this.functions.get(functionId).addOffsetSample(codeId, codeOffset);
|
2018-08-31 09:50:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 05:44:29 +00:00
|
|
|
getScript(scriptId) {
|
|
|
|
return this.scripts.get(scriptId);
|
2018-08-31 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-08 05:44:29 +00:00
|
|
|
getLineForScriptOffset(script, scriptOffset) {
|
2018-08-31 09:50:07 +00:00
|
|
|
let line = 0;
|
|
|
|
let charsConsumed = 0;
|
|
|
|
for (; line < script.length; ++line) {
|
|
|
|
charsConsumed += script[line].length + 1; // Add 1 for newline.
|
|
|
|
if (charsConsumed > scriptOffset) break;
|
|
|
|
}
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2018-10-08 05:44:29 +00:00
|
|
|
hasSource(functionId) {
|
|
|
|
return this.functions.has(functionId);
|
2018-08-31 09:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-08 05:44:29 +00:00
|
|
|
generateSourceView(functionId) {
|
|
|
|
console.assert(this.hasSource(functionId));
|
|
|
|
let data = this.functions.get(functionId);
|
|
|
|
let scriptId = data.scriptId;
|
|
|
|
let script = this.getScript(scriptId);
|
2018-08-31 09:50:07 +00:00
|
|
|
let firstLineNumber =
|
2018-10-08 05:44:29 +00:00
|
|
|
this.getLineForScriptOffset(script, data.startScriptOffset);
|
2018-08-31 09:50:07 +00:00
|
|
|
let lastLineNumber =
|
2018-10-08 05:44:29 +00:00
|
|
|
this.getLineForScriptOffset(script, data.endScriptOffset);
|
2018-08-31 09:50:07 +00:00
|
|
|
let lines = script.slice(firstLineNumber, lastLineNumber + 1);
|
|
|
|
normalizeLeadingWhitespace(lines);
|
|
|
|
|
|
|
|
let samplesTotal = 0;
|
|
|
|
let lineSampleCounts = [];
|
|
|
|
for (let [codeId, block] of data.codes) {
|
|
|
|
block.offsets.forEach((sampleCount, codeOffset) => {
|
|
|
|
let sourceOffset = block.positionTable.getScriptOffset(codeOffset);
|
|
|
|
let lineNumber =
|
2018-10-08 05:44:29 +00:00
|
|
|
this.getLineForScriptOffset(script, sourceOffset) - firstLineNumber;
|
2018-08-31 09:50:07 +00:00
|
|
|
samplesTotal += sampleCount;
|
|
|
|
lineSampleCounts[lineNumber] =
|
|
|
|
(lineSampleCounts[lineNumber] || 0) + sampleCount;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
source: lines,
|
|
|
|
lineSampleCounts: lineSampleCounts,
|
|
|
|
samplesTotal: samplesTotal,
|
|
|
|
firstLineNumber: firstLineNumber + 1 // Source code is 1-indexed.
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FunctionSourceData {
|
2018-10-08 05:44:29 +00:00
|
|
|
constructor(scriptId, startScriptOffset, endScriptOffset) {
|
|
|
|
this.scriptId = scriptId;
|
2018-08-31 09:50:07 +00:00
|
|
|
this.startScriptOffset = startScriptOffset;
|
|
|
|
this.endScriptOffset = endScriptOffset;
|
|
|
|
|
|
|
|
this.codes = new Map();
|
|
|
|
}
|
|
|
|
|
|
|
|
addSourceBlock(codeId, source) {
|
|
|
|
this.codes.set(codeId, {
|
|
|
|
positionTable: new SourcePositionTable(source.positions),
|
|
|
|
offsets: []
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addOffsetSample(codeId, codeOffset) {
|
|
|
|
let codeIdOffsets = this.codes.get(codeId).offsets;
|
|
|
|
codeIdOffsets[codeOffset] = (codeIdOffsets[codeOffset] || 0) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SourcePositionTable {
|
|
|
|
constructor(encodedTable) {
|
|
|
|
this.offsetTable = [];
|
|
|
|
let offsetPairRegex = /C([0-9]+)O([0-9]+)/g;
|
|
|
|
while (true) {
|
|
|
|
let regexResult = offsetPairRegex.exec(encodedTable);
|
|
|
|
if (!regexResult) break;
|
|
|
|
let codeOffset = parseInt(regexResult[1]);
|
|
|
|
let scriptOffset = parseInt(regexResult[2]);
|
|
|
|
if (isNaN(codeOffset) || isNaN(scriptOffset)) continue;
|
|
|
|
this.offsetTable.push(codeOffset, scriptOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getScriptOffset(codeOffset) {
|
|
|
|
console.assert(codeOffset >= 0);
|
|
|
|
for (let i = this.offsetTable.length - 2; i >= 0; i -= 2) {
|
|
|
|
if (this.offsetTable[i] <= codeOffset) {
|
|
|
|
return this.offsetTable[i + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.offsetTable[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 13:04:58 +00:00
|
|
|
class HelpView {
|
|
|
|
constructor() {
|
|
|
|
this.element = $("help");
|
|
|
|
}
|
|
|
|
|
|
|
|
render(newState) {
|
|
|
|
this.element.style.display = newState.file ? "none" : "inherit";
|
|
|
|
}
|
|
|
|
}
|