2016-05-19 08:17:29 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
|
|
|
document.onload = (function(d3){
|
|
|
|
"use strict";
|
|
|
|
var jsonObj;
|
|
|
|
var sourceExpandClassList = document.getElementById(SOURCE_EXPAND_ID).classList;
|
|
|
|
var sourceCollapseClassList = document.getElementById(SOURCE_COLLAPSE_ID).classList;
|
|
|
|
var sourceExpanded = sourceCollapseClassList.contains(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
var disassemblyExpandClassList = document.getElementById(DISASSEMBLY_EXPAND_ID).classList;
|
|
|
|
var disassemblyCollapseClassList = document.getElementById(DISASSEMBLY_COLLAPSE_ID).classList;
|
|
|
|
var disassemblyExpanded = disassemblyCollapseClassList.contains(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
var svg = null;
|
|
|
|
var graph = null;
|
|
|
|
var schedule = null;
|
|
|
|
var empty = null;
|
|
|
|
var currentPhaseView = null;
|
|
|
|
var disassemblyView = null;
|
|
|
|
var sourceView = null;
|
|
|
|
var selectionBroker = null;
|
|
|
|
|
|
|
|
function updatePanes() {
|
|
|
|
if (sourceExpanded) {
|
|
|
|
if (disassemblyExpanded) {
|
|
|
|
d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "30%");
|
|
|
|
d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "40%");
|
|
|
|
d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "30%");
|
|
|
|
} else {
|
|
|
|
d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "50%");
|
|
|
|
d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "50%");
|
|
|
|
d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "0%");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (disassemblyExpanded) {
|
|
|
|
d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "0%");
|
|
|
|
d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "50%");
|
|
|
|
d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "50%");
|
|
|
|
} else {
|
|
|
|
d3.select("#" + SOURCE_PANE_ID).style(WIDTH, "0%");
|
|
|
|
d3.select("#" + INTERMEDIATE_PANE_ID).style(WIDTH, "100%");
|
|
|
|
d3.select("#" + GENERATED_PANE_ID).style(WIDTH, "0%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-26 11:44:07 +00:00
|
|
|
function getLastExpandedState(type, default_state) {
|
|
|
|
var state = window.sessionStorage.getItem("expandedState-"+type);
|
|
|
|
if (state === null) return default_state;
|
|
|
|
return state === 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLastExpandedState(type, state) {
|
|
|
|
window.sessionStorage.setItem("expandedState-"+type, state);
|
|
|
|
}
|
|
|
|
|
2016-06-13 13:21:23 +00:00
|
|
|
function toggleSourceExpanded() {
|
|
|
|
setSourceExpanded(!sourceExpanded);
|
|
|
|
}
|
|
|
|
|
2016-05-19 08:17:29 +00:00
|
|
|
function setSourceExpanded(newState) {
|
|
|
|
sourceExpanded = newState;
|
2016-07-26 11:44:07 +00:00
|
|
|
setLastExpandedState("source", newState);
|
2016-05-19 08:17:29 +00:00
|
|
|
updatePanes();
|
|
|
|
if (newState) {
|
|
|
|
sourceCollapseClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
sourceCollapseClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
sourceExpandClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
sourceExpandClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
} else {
|
|
|
|
sourceCollapseClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
sourceCollapseClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
sourceExpandClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
sourceExpandClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-13 13:21:23 +00:00
|
|
|
function toggleDisassemblyExpanded() {
|
|
|
|
setDisassemblyExpanded(!disassemblyExpanded);
|
|
|
|
}
|
|
|
|
|
2016-05-19 08:17:29 +00:00
|
|
|
function setDisassemblyExpanded(newState) {
|
|
|
|
disassemblyExpanded = newState;
|
2016-07-26 11:44:07 +00:00
|
|
|
setLastExpandedState("disassembly", newState);
|
2016-05-19 08:17:29 +00:00
|
|
|
updatePanes();
|
|
|
|
if (newState) {
|
|
|
|
disassemblyCollapseClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
disassemblyCollapseClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
disassemblyExpandClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
disassemblyExpandClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
} else {
|
|
|
|
disassemblyCollapseClassList.add(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
disassemblyCollapseClassList.remove(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
disassemblyExpandClassList.add(COLLAPSE_PANE_BUTTON_VISIBLE);
|
|
|
|
disassemblyExpandClassList.remove(COLLAPSE_PANE_BUTTON_INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideCurrentPhase() {
|
|
|
|
var rememberedSelection = null;
|
|
|
|
if (currentPhaseView != null) {
|
|
|
|
rememberedSelection = currentPhaseView.detachSelection();
|
|
|
|
currentPhaseView.hide();
|
|
|
|
currentPhaseView = null;
|
|
|
|
}
|
|
|
|
return rememberedSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayPhaseView(view, data) {
|
|
|
|
var rememberedSelection = hideCurrentPhase();
|
|
|
|
view.show(data, rememberedSelection);
|
|
|
|
d3.select("#middle").classed("scrollable", view.isScrollable());
|
|
|
|
currentPhaseView = view;
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayPhase(phase) {
|
|
|
|
if (phase.type == 'graph') {
|
|
|
|
displayPhaseView(graph, phase.data);
|
|
|
|
} else if (phase.type == 'schedule') {
|
|
|
|
displayPhaseView(schedule, phase.data);
|
|
|
|
} else {
|
|
|
|
displayPhaseView(empty, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function fitPanesToParents() {
|
|
|
|
d3.select("#left").classed("scrollable", false)
|
|
|
|
d3.select("#right").classed("scrollable", false);
|
|
|
|
|
|
|
|
graph.fitGraphViewToWindow();
|
|
|
|
disassemblyView.resizeToParent();
|
|
|
|
sourceView.resizeToParent();
|
|
|
|
|
|
|
|
d3.select("#left").classed("scrollable", true);
|
|
|
|
d3.select("#right").classed("scrollable", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
selectionBroker = new SelectionBroker();
|
|
|
|
|
|
|
|
function initializeHandlers(g) {
|
2016-06-13 13:21:23 +00:00
|
|
|
d3.select("#source-collapse").on("click", function(){
|
|
|
|
toggleSourceExpanded(true);
|
2016-05-19 08:17:29 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
g.fitGraphViewToWindow();
|
2016-08-10 20:09:05 +00:00
|
|
|
}, 300);
|
2016-05-19 08:17:29 +00:00
|
|
|
});
|
2016-06-13 13:21:23 +00:00
|
|
|
d3.select("#disassembly-collapse").on("click", function(){
|
|
|
|
toggleDisassemblyExpanded();
|
2016-05-19 08:17:29 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
g.fitGraphViewToWindow();
|
2016-08-10 20:09:05 +00:00
|
|
|
}, 300);
|
2016-05-19 08:17:29 +00:00
|
|
|
});
|
|
|
|
window.onresize = function(){
|
|
|
|
fitPanesToParents();
|
|
|
|
};
|
|
|
|
d3.select("#hidden-file-upload").on("change", function() {
|
|
|
|
if (window.File && window.FileReader && window.FileList) {
|
|
|
|
var uploadFile = this.files[0];
|
|
|
|
var filereader = new window.FileReader();
|
|
|
|
var consts = Node.consts;
|
|
|
|
filereader.onload = function(){
|
|
|
|
var txtRes = filereader.result;
|
|
|
|
// If the JSON isn't properly terminated, assume compiler crashed and
|
|
|
|
// add best-guess empty termination
|
|
|
|
if (txtRes[txtRes.length-2] == ',') {
|
|
|
|
txtRes += '{"name":"disassembly","type":"disassembly","data":""}]}';
|
|
|
|
}
|
|
|
|
try{
|
|
|
|
jsonObj = JSON.parse(txtRes);
|
|
|
|
|
2016-08-10 08:16:37 +00:00
|
|
|
hideCurrentPhase();
|
|
|
|
|
2016-08-10 14:45:56 +00:00
|
|
|
selectionBroker.setNodePositionMap(jsonObj.nodePositions);
|
|
|
|
|
2016-05-19 08:17:29 +00:00
|
|
|
sourceView.initializeCode(jsonObj.source, jsonObj.sourcePosition);
|
2016-08-10 14:45:56 +00:00
|
|
|
disassemblyView.initializeCode(jsonObj.source);
|
2016-05-19 08:17:29 +00:00
|
|
|
|
|
|
|
var selectMenu = document.getElementById('display-selector');
|
|
|
|
var disassemblyPhase = null;
|
|
|
|
selectMenu.innerHTML = '';
|
|
|
|
for (var i = 0; i < jsonObj.phases.length; ++i) {
|
|
|
|
var optionElement = document.createElement("option");
|
|
|
|
optionElement.text = jsonObj.phases[i].name;
|
|
|
|
if (optionElement.text == 'disassembly') {
|
|
|
|
disassemblyPhase = jsonObj.phases[i];
|
|
|
|
} else {
|
|
|
|
selectMenu.add(optionElement, null);
|
|
|
|
}
|
|
|
|
}
|
2016-07-28 09:39:21 +00:00
|
|
|
|
|
|
|
var eventMenu = document.getElementById('event-selector');
|
|
|
|
eventMenu.innerHTML = '';
|
|
|
|
for (var event in jsonObj.eventCounts) {
|
|
|
|
var optionElement = document.createElement("option");
|
|
|
|
optionElement.text = event;
|
|
|
|
eventMenu.add(optionElement, null);
|
|
|
|
}
|
|
|
|
disassemblyView.initializePerfProfile(jsonObj.eventCounts);
|
2016-05-19 08:17:29 +00:00
|
|
|
disassemblyView.show(disassemblyPhase.data, null);
|
|
|
|
|
2016-07-26 11:44:07 +00:00
|
|
|
var initialPhaseIndex = +window.sessionStorage.getItem("lastSelectedPhase");
|
|
|
|
if (!(initialPhaseIndex in jsonObj.phases)) {
|
|
|
|
initialPhaseIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We wish to show the remembered phase {lastSelectedPhase}, but
|
|
|
|
// this will crash if the first view we switch to is a
|
|
|
|
// ScheduleView. So we first switch to the first phase, which
|
|
|
|
// should never be a ScheduleView.
|
2016-05-19 08:17:29 +00:00
|
|
|
displayPhase(jsonObj.phases[0]);
|
2016-07-26 11:44:07 +00:00
|
|
|
displayPhase(jsonObj.phases[initialPhaseIndex]);
|
|
|
|
selectMenu.selectedIndex = initialPhaseIndex;
|
2016-05-19 08:17:29 +00:00
|
|
|
|
|
|
|
selectMenu.onchange = function(item) {
|
2016-07-26 11:44:07 +00:00
|
|
|
window.sessionStorage.setItem("lastSelectedPhase", selectMenu.selectedIndex);
|
2016-05-19 08:17:29 +00:00
|
|
|
displayPhase(jsonObj.phases[selectMenu.selectedIndex]);
|
|
|
|
}
|
|
|
|
|
2016-07-28 09:39:21 +00:00
|
|
|
eventMenu.onchange = function(item) {
|
|
|
|
disassemblyView.show(disassemblyView.data, null);
|
|
|
|
}
|
|
|
|
|
2016-05-19 08:17:29 +00:00
|
|
|
fitPanesToParents();
|
2016-07-26 11:44:07 +00:00
|
|
|
|
|
|
|
d3.select("#search-input").attr("value", window.sessionStorage.getItem("lastSearch") || "");
|
|
|
|
|
2016-05-19 08:17:29 +00:00
|
|
|
}
|
|
|
|
catch(err) {
|
2016-07-26 11:44:07 +00:00
|
|
|
window.console.log("caught exception, clearing session storage just in case");
|
|
|
|
window.sessionStorage.clear(); // just in case
|
|
|
|
window.console.log("showing error");
|
2016-05-19 08:17:29 +00:00
|
|
|
window.alert("Invalid TurboFan JSON file\n" +
|
|
|
|
"error: " + err.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
filereader.readAsText(uploadFile);
|
|
|
|
} else {
|
|
|
|
alert("Can't load graph");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceView = new CodeView(SOURCE_PANE_ID, PR, "", 0, selectionBroker);
|
|
|
|
disassemblyView = new DisassemblyView(DISASSEMBLY_PANE_ID, selectionBroker);
|
|
|
|
graph = new GraphView(d3, GRAPH_PANE_ID, [], [], selectionBroker);
|
|
|
|
schedule = new ScheduleView(SCHEDULE_PANE_ID, selectionBroker);
|
|
|
|
empty = new EmptyView(EMPTY_PANE_ID, selectionBroker);
|
|
|
|
|
|
|
|
initializeHandlers(graph);
|
|
|
|
|
2016-07-26 11:44:07 +00:00
|
|
|
setSourceExpanded(getLastExpandedState("source", true));
|
|
|
|
setDisassemblyExpanded(getLastExpandedState("disassembly", false));
|
2016-05-19 08:17:29 +00:00
|
|
|
|
|
|
|
displayPhaseView(empty, null);
|
|
|
|
fitPanesToParents();
|
|
|
|
})(window.d3);
|