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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/profiler/cleopatra/js/devtools.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,244 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +var gInstanceUID;
    1.11 +var gParsedQS;
    1.12 +var gHideSourceLinks;
    1.13 +
    1.14 +function getParam(key) {
    1.15 +  if (gParsedQS)
    1.16 +    return gParsedQS[key];
    1.17 +
    1.18 +  var query = window.location.search.substring(1);
    1.19 +  gParsedQS = {};
    1.20 +
    1.21 +  query.split("&").forEach(function (pair) {
    1.22 +    pair = pair.split("=");
    1.23 +    gParsedQS[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
    1.24 +  });
    1.25 +
    1.26 +  return gParsedQS[key];
    1.27 +}
    1.28 +
    1.29 +/**
    1.30 + * Sends a message to the parent window with a status
    1.31 + * update.
    1.32 + *
    1.33 + * @param string status
    1.34 + *   Status to send to the parent page:
    1.35 + *    - loaded, when page is loaded.
    1.36 + *    - displaysource, when user wants to display source
    1.37 + * @param object data (optional)
    1.38 + *    Additional data to send to the parent page.
    1.39 + */
    1.40 +function notifyParent(status, data={}) {
    1.41 +  if (!gInstanceUID) {
    1.42 +    gInstanceUID = getParam("uid");
    1.43 +  }
    1.44 +
    1.45 +  window.parent.postMessage({
    1.46 +    uid: gInstanceUID,
    1.47 +    status: status,
    1.48 +    data: data
    1.49 +  }, "*");
    1.50 +}
    1.51 +
    1.52 +/**
    1.53 + * A listener for incoming messages from the parent
    1.54 + * page. All incoming messages must be stringified
    1.55 + * JSON objects to be compatible with Cleopatra's
    1.56 + * format:
    1.57 + *
    1.58 + * {
    1.59 + *   task: string,
    1.60 + *   ...
    1.61 + * }
    1.62 + *
    1.63 + * This listener recognizes two tasks: onStarted and
    1.64 + * onStopped.
    1.65 + *
    1.66 + * @param object event
    1.67 + *   PostMessage event object.
    1.68 + */
    1.69 +function onParentMessage(event) {
    1.70 +  var start = document.getElementById("startWrapper");
    1.71 +  var stop = document.getElementById("stopWrapper");
    1.72 +  var profilerMessage = document.getElementById("profilerMessage");
    1.73 +  var msg = JSON.parse(event.data);
    1.74 +
    1.75 +  if (msg.task !== "receiveProfileData" && !msg.isCurrent) {
    1.76 +    return;
    1.77 +  }
    1.78 +
    1.79 +  switch (msg.task) {
    1.80 +    case "onStarted":
    1.81 +      start.style.display = "none";
    1.82 +      start.querySelector("button").removeAttribute("disabled");
    1.83 +      stop.style.display = "inline";
    1.84 +      break;
    1.85 +    case "onStopped":
    1.86 +      stop.style.display = "none";
    1.87 +      stop.querySelector("button").removeAttribute("disabled");
    1.88 +      start.style.display = "inline";
    1.89 +      break;
    1.90 +    case "receiveProfileData":
    1.91 +      loadProfile(JSON.stringify(msg.rawProfile));
    1.92 +  }
    1.93 +}
    1.94 +
    1.95 +window.addEventListener("message", onParentMessage);
    1.96 +
    1.97 +/**
    1.98 + * Main entry point. This function initializes Cleopatra
    1.99 + * in the light mode and creates all the UI we need.
   1.100 + */
   1.101 +function initUI() {
   1.102 +  gHideSourceLinks = getParam("ext") === "true";
   1.103 +  gFileList = { profileParsingFinished: function () {} };
   1.104 +  gInfoBar = { display: function () {} };
   1.105 +
   1.106 +  var container = document.createElement("div");
   1.107 +  container.id = "ui";
   1.108 +
   1.109 +  gMainArea = document.createElement("div");
   1.110 +  gMainArea.id = "mainarea";
   1.111 +
   1.112 +  container.appendChild(gMainArea);
   1.113 +  document.body.appendChild(container);
   1.114 +}
   1.115 +
   1.116 +/**
   1.117 + * Modified copy of Cleopatra's enterFinishedProfileUI.
   1.118 + * By overriding the function we don't need to modify ui.js which helps
   1.119 + * with updating from upstream.
   1.120 + */
   1.121 +function enterFinishedProfileUI() {
   1.122 +  var cover = document.createElement("div");
   1.123 +  cover.className = "finishedProfilePaneBackgroundCover";
   1.124 +
   1.125 +  var pane = document.createElement("table");
   1.126 +  var rowIndex = 0;
   1.127 +  var currRow;
   1.128 +
   1.129 +  pane.style.width = "100%";
   1.130 +  pane.style.height = "100%";
   1.131 +  pane.border = "0";
   1.132 +  pane.cellPadding = "0";
   1.133 +  pane.cellSpacing = "0";
   1.134 +  pane.borderCollapse = "collapse";
   1.135 +  pane.className = "finishedProfilePane";
   1.136 +
   1.137 +  gBreadcrumbTrail = new BreadcrumbTrail();
   1.138 +  currRow = pane.insertRow(rowIndex++);
   1.139 +  currRow.insertCell(0).appendChild(gBreadcrumbTrail.getContainer());
   1.140 +
   1.141 +  gHistogramView = new HistogramView();
   1.142 +  currRow = pane.insertRow(rowIndex++);
   1.143 +  currRow.insertCell(0).appendChild(gHistogramView.getContainer());
   1.144 +
   1.145 +  if (gMeta && gMeta.videoCapture) {
   1.146 +    gVideoPane = new VideoPane(gMeta.videoCapture);
   1.147 +    gVideoPane.onTimeChange(videoPaneTimeChange);
   1.148 +    currRow = pane.insertRow(rowIndex++);
   1.149 +    currRow.insertCell(0).appendChild(gVideoPane.getContainer());
   1.150 +  }
   1.151 +
   1.152 +  var tree = document.createElement("div");
   1.153 +  tree.className = "treeContainer";
   1.154 +  tree.style.width = "100%";
   1.155 +  tree.style.height = "100%";
   1.156 +
   1.157 +  gTreeManager = new ProfileTreeManager();
   1.158 +  gTreeManager.treeView.setColumns([
   1.159 +    { name: "sampleCount", title: gStrings["Running Time"] },
   1.160 +    { name: "selfSampleCount", title: gStrings["Self"] },
   1.161 +    { name: "resource", title: "" }
   1.162 +  ]);
   1.163 +
   1.164 +  currRow = pane.insertRow(rowIndex++);
   1.165 +  currRow.style.height = "100%";
   1.166 +
   1.167 +  var cell = currRow.insertCell(0);
   1.168 +  cell.appendChild(tree);
   1.169 +  tree.appendChild(gTreeManager.getContainer());
   1.170 +
   1.171 +  gPluginView = new PluginView();
   1.172 +  tree.appendChild(gPluginView.getContainer());
   1.173 +
   1.174 +  gMainArea.appendChild(cover);
   1.175 +  gMainArea.appendChild(pane);
   1.176 +
   1.177 +  var currentBreadcrumb = gSampleFilters;
   1.178 +  gBreadcrumbTrail.add({
   1.179 +    title: gStrings["Complete Profile"],
   1.180 +    enterCallback: function () {
   1.181 +      gSampleFilters = [];
   1.182 +      filtersChanged();
   1.183 +    }
   1.184 +  });
   1.185 +
   1.186 +  if (currentBreadcrumb == null || currentBreadcrumb.length == 0) {
   1.187 +    gTreeManager.restoreSerializedSelectionSnapshot(gRestoreSelection);
   1.188 +    viewOptionsChanged();
   1.189 +  }
   1.190 +
   1.191 +  for (var i = 0; i < currentBreadcrumb.length; i++) {
   1.192 +    var filter = currentBreadcrumb[i];
   1.193 +    var forceSelection = null;
   1.194 +    if (gRestoreSelection != null && i == currentBreadcrumb.length - 1) {
   1.195 +      forceSelection = gRestoreSelection;
   1.196 +    }
   1.197 +    switch (filter.type) {
   1.198 +      case "FocusedFrameSampleFilter":
   1.199 +        focusOnSymbol(filter.name, filter.symbolName);
   1.200 +        gBreadcrumbTrail.enterLastItem(forceSelection);
   1.201 +      case "FocusedCallstackPrefixSampleFilter":
   1.202 +        focusOnCallstack(filter.focusedCallstack, filter.name, false);
   1.203 +        gBreadcrumbTrail.enterLastItem(forceSelection);
   1.204 +      case "FocusedCallstackPostfixSampleFilter":
   1.205 +        focusOnCallstack(filter.focusedCallstack, filter.name, true);
   1.206 +        gBreadcrumbTrail.enterLastItem(forceSelection);
   1.207 +      case "RangeSampleFilter":
   1.208 +        gHistogramView.selectRange(filter.start, filter.end);
   1.209 +        gBreadcrumbTrail.enterLastItem(forceSelection);
   1.210 +    }
   1.211 +  }
   1.212 +
   1.213 +  // Show platform data?
   1.214 +  if (getParam("spd") !== "true")
   1.215 +    toggleJavascriptOnly();
   1.216 +}
   1.217 +
   1.218 +function enterProgressUI() {
   1.219 +  var pane = document.createElement("div");
   1.220 +  var label = document.createElement("a");
   1.221 +  var bar = document.createElement("progress");
   1.222 +  var string = gStrings.getStr("profiler.loading");
   1.223 +
   1.224 +  pane.className = "profileProgressPane";
   1.225 +  pane.appendChild(label);
   1.226 +  pane.appendChild(bar);
   1.227 +
   1.228 +  var reporter = new ProgressReporter();
   1.229 +  reporter.addListener(function (rep) {
   1.230 +    var progress = rep.getProgress();
   1.231 +
   1.232 +    if (label.textContent !== string) {
   1.233 +      label.textContent = string;
   1.234 +    }
   1.235 +
   1.236 +    if (isNaN(progress)) {
   1.237 +      bar.removeAttribute("value");
   1.238 +    } else {
   1.239 +      bar.value = progress;
   1.240 +    }
   1.241 +  });
   1.242 +
   1.243 +  gMainArea.appendChild(pane);
   1.244 +  Parser.updateLogSetting();
   1.245 +
   1.246 +  return reporter;
   1.247 +}

mercurial