browser/devtools/profiler/cleopatra/js/devtools.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 var gInstanceUID;
michael@0 8 var gParsedQS;
michael@0 9 var gHideSourceLinks;
michael@0 10
michael@0 11 function getParam(key) {
michael@0 12 if (gParsedQS)
michael@0 13 return gParsedQS[key];
michael@0 14
michael@0 15 var query = window.location.search.substring(1);
michael@0 16 gParsedQS = {};
michael@0 17
michael@0 18 query.split("&").forEach(function (pair) {
michael@0 19 pair = pair.split("=");
michael@0 20 gParsedQS[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
michael@0 21 });
michael@0 22
michael@0 23 return gParsedQS[key];
michael@0 24 }
michael@0 25
michael@0 26 /**
michael@0 27 * Sends a message to the parent window with a status
michael@0 28 * update.
michael@0 29 *
michael@0 30 * @param string status
michael@0 31 * Status to send to the parent page:
michael@0 32 * - loaded, when page is loaded.
michael@0 33 * - displaysource, when user wants to display source
michael@0 34 * @param object data (optional)
michael@0 35 * Additional data to send to the parent page.
michael@0 36 */
michael@0 37 function notifyParent(status, data={}) {
michael@0 38 if (!gInstanceUID) {
michael@0 39 gInstanceUID = getParam("uid");
michael@0 40 }
michael@0 41
michael@0 42 window.parent.postMessage({
michael@0 43 uid: gInstanceUID,
michael@0 44 status: status,
michael@0 45 data: data
michael@0 46 }, "*");
michael@0 47 }
michael@0 48
michael@0 49 /**
michael@0 50 * A listener for incoming messages from the parent
michael@0 51 * page. All incoming messages must be stringified
michael@0 52 * JSON objects to be compatible with Cleopatra's
michael@0 53 * format:
michael@0 54 *
michael@0 55 * {
michael@0 56 * task: string,
michael@0 57 * ...
michael@0 58 * }
michael@0 59 *
michael@0 60 * This listener recognizes two tasks: onStarted and
michael@0 61 * onStopped.
michael@0 62 *
michael@0 63 * @param object event
michael@0 64 * PostMessage event object.
michael@0 65 */
michael@0 66 function onParentMessage(event) {
michael@0 67 var start = document.getElementById("startWrapper");
michael@0 68 var stop = document.getElementById("stopWrapper");
michael@0 69 var profilerMessage = document.getElementById("profilerMessage");
michael@0 70 var msg = JSON.parse(event.data);
michael@0 71
michael@0 72 if (msg.task !== "receiveProfileData" && !msg.isCurrent) {
michael@0 73 return;
michael@0 74 }
michael@0 75
michael@0 76 switch (msg.task) {
michael@0 77 case "onStarted":
michael@0 78 start.style.display = "none";
michael@0 79 start.querySelector("button").removeAttribute("disabled");
michael@0 80 stop.style.display = "inline";
michael@0 81 break;
michael@0 82 case "onStopped":
michael@0 83 stop.style.display = "none";
michael@0 84 stop.querySelector("button").removeAttribute("disabled");
michael@0 85 start.style.display = "inline";
michael@0 86 break;
michael@0 87 case "receiveProfileData":
michael@0 88 loadProfile(JSON.stringify(msg.rawProfile));
michael@0 89 }
michael@0 90 }
michael@0 91
michael@0 92 window.addEventListener("message", onParentMessage);
michael@0 93
michael@0 94 /**
michael@0 95 * Main entry point. This function initializes Cleopatra
michael@0 96 * in the light mode and creates all the UI we need.
michael@0 97 */
michael@0 98 function initUI() {
michael@0 99 gHideSourceLinks = getParam("ext") === "true";
michael@0 100 gFileList = { profileParsingFinished: function () {} };
michael@0 101 gInfoBar = { display: function () {} };
michael@0 102
michael@0 103 var container = document.createElement("div");
michael@0 104 container.id = "ui";
michael@0 105
michael@0 106 gMainArea = document.createElement("div");
michael@0 107 gMainArea.id = "mainarea";
michael@0 108
michael@0 109 container.appendChild(gMainArea);
michael@0 110 document.body.appendChild(container);
michael@0 111 }
michael@0 112
michael@0 113 /**
michael@0 114 * Modified copy of Cleopatra's enterFinishedProfileUI.
michael@0 115 * By overriding the function we don't need to modify ui.js which helps
michael@0 116 * with updating from upstream.
michael@0 117 */
michael@0 118 function enterFinishedProfileUI() {
michael@0 119 var cover = document.createElement("div");
michael@0 120 cover.className = "finishedProfilePaneBackgroundCover";
michael@0 121
michael@0 122 var pane = document.createElement("table");
michael@0 123 var rowIndex = 0;
michael@0 124 var currRow;
michael@0 125
michael@0 126 pane.style.width = "100%";
michael@0 127 pane.style.height = "100%";
michael@0 128 pane.border = "0";
michael@0 129 pane.cellPadding = "0";
michael@0 130 pane.cellSpacing = "0";
michael@0 131 pane.borderCollapse = "collapse";
michael@0 132 pane.className = "finishedProfilePane";
michael@0 133
michael@0 134 gBreadcrumbTrail = new BreadcrumbTrail();
michael@0 135 currRow = pane.insertRow(rowIndex++);
michael@0 136 currRow.insertCell(0).appendChild(gBreadcrumbTrail.getContainer());
michael@0 137
michael@0 138 gHistogramView = new HistogramView();
michael@0 139 currRow = pane.insertRow(rowIndex++);
michael@0 140 currRow.insertCell(0).appendChild(gHistogramView.getContainer());
michael@0 141
michael@0 142 if (gMeta && gMeta.videoCapture) {
michael@0 143 gVideoPane = new VideoPane(gMeta.videoCapture);
michael@0 144 gVideoPane.onTimeChange(videoPaneTimeChange);
michael@0 145 currRow = pane.insertRow(rowIndex++);
michael@0 146 currRow.insertCell(0).appendChild(gVideoPane.getContainer());
michael@0 147 }
michael@0 148
michael@0 149 var tree = document.createElement("div");
michael@0 150 tree.className = "treeContainer";
michael@0 151 tree.style.width = "100%";
michael@0 152 tree.style.height = "100%";
michael@0 153
michael@0 154 gTreeManager = new ProfileTreeManager();
michael@0 155 gTreeManager.treeView.setColumns([
michael@0 156 { name: "sampleCount", title: gStrings["Running Time"] },
michael@0 157 { name: "selfSampleCount", title: gStrings["Self"] },
michael@0 158 { name: "resource", title: "" }
michael@0 159 ]);
michael@0 160
michael@0 161 currRow = pane.insertRow(rowIndex++);
michael@0 162 currRow.style.height = "100%";
michael@0 163
michael@0 164 var cell = currRow.insertCell(0);
michael@0 165 cell.appendChild(tree);
michael@0 166 tree.appendChild(gTreeManager.getContainer());
michael@0 167
michael@0 168 gPluginView = new PluginView();
michael@0 169 tree.appendChild(gPluginView.getContainer());
michael@0 170
michael@0 171 gMainArea.appendChild(cover);
michael@0 172 gMainArea.appendChild(pane);
michael@0 173
michael@0 174 var currentBreadcrumb = gSampleFilters;
michael@0 175 gBreadcrumbTrail.add({
michael@0 176 title: gStrings["Complete Profile"],
michael@0 177 enterCallback: function () {
michael@0 178 gSampleFilters = [];
michael@0 179 filtersChanged();
michael@0 180 }
michael@0 181 });
michael@0 182
michael@0 183 if (currentBreadcrumb == null || currentBreadcrumb.length == 0) {
michael@0 184 gTreeManager.restoreSerializedSelectionSnapshot(gRestoreSelection);
michael@0 185 viewOptionsChanged();
michael@0 186 }
michael@0 187
michael@0 188 for (var i = 0; i < currentBreadcrumb.length; i++) {
michael@0 189 var filter = currentBreadcrumb[i];
michael@0 190 var forceSelection = null;
michael@0 191 if (gRestoreSelection != null && i == currentBreadcrumb.length - 1) {
michael@0 192 forceSelection = gRestoreSelection;
michael@0 193 }
michael@0 194 switch (filter.type) {
michael@0 195 case "FocusedFrameSampleFilter":
michael@0 196 focusOnSymbol(filter.name, filter.symbolName);
michael@0 197 gBreadcrumbTrail.enterLastItem(forceSelection);
michael@0 198 case "FocusedCallstackPrefixSampleFilter":
michael@0 199 focusOnCallstack(filter.focusedCallstack, filter.name, false);
michael@0 200 gBreadcrumbTrail.enterLastItem(forceSelection);
michael@0 201 case "FocusedCallstackPostfixSampleFilter":
michael@0 202 focusOnCallstack(filter.focusedCallstack, filter.name, true);
michael@0 203 gBreadcrumbTrail.enterLastItem(forceSelection);
michael@0 204 case "RangeSampleFilter":
michael@0 205 gHistogramView.selectRange(filter.start, filter.end);
michael@0 206 gBreadcrumbTrail.enterLastItem(forceSelection);
michael@0 207 }
michael@0 208 }
michael@0 209
michael@0 210 // Show platform data?
michael@0 211 if (getParam("spd") !== "true")
michael@0 212 toggleJavascriptOnly();
michael@0 213 }
michael@0 214
michael@0 215 function enterProgressUI() {
michael@0 216 var pane = document.createElement("div");
michael@0 217 var label = document.createElement("a");
michael@0 218 var bar = document.createElement("progress");
michael@0 219 var string = gStrings.getStr("profiler.loading");
michael@0 220
michael@0 221 pane.className = "profileProgressPane";
michael@0 222 pane.appendChild(label);
michael@0 223 pane.appendChild(bar);
michael@0 224
michael@0 225 var reporter = new ProgressReporter();
michael@0 226 reporter.addListener(function (rep) {
michael@0 227 var progress = rep.getProgress();
michael@0 228
michael@0 229 if (label.textContent !== string) {
michael@0 230 label.textContent = string;
michael@0 231 }
michael@0 232
michael@0 233 if (isNaN(progress)) {
michael@0 234 bar.removeAttribute("value");
michael@0 235 } else {
michael@0 236 bar.value = progress;
michael@0 237 }
michael@0 238 });
michael@0 239
michael@0 240 gMainArea.appendChild(pane);
michael@0 241 Parser.updateLogSetting();
michael@0 242
michael@0 243 return reporter;
michael@0 244 }

mercurial