2012-11-08 12:36:06 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
const Telemetry = Services.telemetry;
|
|
|
|
const bundle = Services.strings.createBundle(
|
|
|
|
"chrome://global/locale/aboutTelemetry.properties");
|
2012-11-26 15:21:04 -08:00
|
|
|
const brandBundle = Services.strings.createBundle(
|
|
|
|
"chrome://branding/locale/brand.properties");
|
2012-11-08 12:36:06 -08:00
|
|
|
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].
|
2012-12-03 10:31:00 -08:00
|
|
|
getService(Ci.nsITelemetryPing);
|
2012-11-08 12:36:06 -08:00
|
|
|
|
|
|
|
// Maximum height of a histogram bar (in em)
|
|
|
|
const MAX_BAR_HEIGHT = 18;
|
2012-11-26 15:21:04 -08:00
|
|
|
const PREF_TELEMETRY_SERVER_OWNER = "toolkit.telemetry.server_owner";
|
2012-12-08 09:41:23 -08:00
|
|
|
#ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
|
|
|
|
const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabledPreRelease";
|
|
|
|
#else
|
2012-11-08 12:36:06 -08:00
|
|
|
const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
|
2012-12-08 09:41:23 -08:00
|
|
|
#endif
|
2012-11-08 12:36:06 -08:00
|
|
|
const PREF_DEBUG_SLOW_SQL = "toolkit.telemetry.debugSlowSql";
|
|
|
|
const PREF_SYMBOL_SERVER_URI = "profiler.symbolicationUrl";
|
|
|
|
const DEFAULT_SYMBOL_SERVER_URI = "http://symbolapi.mozilla.org";
|
|
|
|
|
|
|
|
// Cached value of document's RTL mode
|
|
|
|
let documentRTLMode = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for fetching a config pref
|
|
|
|
*
|
|
|
|
* @param aPrefName Name of config pref to fetch.
|
|
|
|
* @param aDefault Default value to return if pref isn't set.
|
|
|
|
* @return Value of pref
|
|
|
|
*/
|
|
|
|
function getPref(aPrefName, aDefault) {
|
|
|
|
let result = aDefault;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let prefType = Services.prefs.getPrefType(aPrefName);
|
|
|
|
if (prefType == Ci.nsIPrefBranch.PREF_BOOL) {
|
|
|
|
result = Services.prefs.getBoolPref(aPrefName);
|
|
|
|
} else if (prefType == Ci.nsIPrefBranch.PREF_STRING) {
|
|
|
|
result = Services.prefs.getCharPref(aPrefName);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// Return default if Prefs service throws exception
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for determining whether the document direction is RTL.
|
|
|
|
* Caches result of check on first invocation.
|
|
|
|
*/
|
|
|
|
function isRTL() {
|
|
|
|
if (!documentRTLMode)
|
|
|
|
documentRTLMode = window.getComputedStyle(document.body).direction;
|
|
|
|
return (documentRTLMode == "rtl");
|
|
|
|
}
|
|
|
|
|
|
|
|
let observer = {
|
|
|
|
|
|
|
|
enableTelemetry: bundle.GetStringFromName("enableTelemetry"),
|
|
|
|
|
|
|
|
disableTelemetry: bundle.GetStringFromName("disableTelemetry"),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Observer is called whenever Telemetry is enabled or disabled
|
|
|
|
*/
|
|
|
|
observe: function observe(aSubject, aTopic, aData) {
|
|
|
|
if (aData == PREF_TELEMETRY_ENABLED) {
|
|
|
|
this.updatePrefStatus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the button & text at the top of the page to reflect Telemetry state.
|
|
|
|
*/
|
|
|
|
updatePrefStatus: function updatePrefStatus() {
|
|
|
|
// Notify user whether Telemetry is enabled
|
|
|
|
let enabledElement = document.getElementById("description-enabled");
|
|
|
|
let disabledElement = document.getElementById("description-disabled");
|
|
|
|
let toggleElement = document.getElementById("toggle-telemetry");
|
|
|
|
if (getPref(PREF_TELEMETRY_ENABLED, false)) {
|
|
|
|
enabledElement.classList.remove("hidden");
|
|
|
|
disabledElement.classList.add("hidden");
|
|
|
|
toggleElement.innerHTML = this.disableTelemetry;
|
|
|
|
} else {
|
|
|
|
enabledElement.classList.add("hidden");
|
|
|
|
disabledElement.classList.remove("hidden");
|
|
|
|
toggleElement.innerHTML = this.enableTelemetry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let SlowSQL = {
|
|
|
|
|
|
|
|
slowSqlHits: bundle.GetStringFromName("slowSqlHits"),
|
|
|
|
|
|
|
|
slowSqlAverage: bundle.GetStringFromName("slowSqlAverage"),
|
|
|
|
|
|
|
|
slowSqlStatement: bundle.GetStringFromName("slowSqlStatement"),
|
|
|
|
|
|
|
|
mainThreadTitle: bundle.GetStringFromName("slowSqlMain"),
|
|
|
|
|
|
|
|
otherThreadTitle: bundle.GetStringFromName("slowSqlOther"),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render slow SQL statistics
|
|
|
|
*/
|
|
|
|
render: function SlowSQL_render() {
|
|
|
|
let debugSlowSql = getPref(PREF_DEBUG_SLOW_SQL, false);
|
|
|
|
let {mainThread, otherThreads} =
|
|
|
|
Telemetry[debugSlowSql ? "debugSlowSQL" : "slowSQL"];
|
|
|
|
|
|
|
|
let mainThreadCount = Object.keys(mainThread).length;
|
|
|
|
let otherThreadCount = Object.keys(otherThreads).length;
|
|
|
|
if (mainThreadCount == 0 && otherThreadCount == 0) {
|
|
|
|
showEmptySectionMessage("slow-sql-section");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debugSlowSql) {
|
|
|
|
document.getElementById("sql-warning").classList.remove("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
let slowSqlDiv = document.getElementById("slow-sql-tables");
|
|
|
|
|
|
|
|
// Main thread
|
|
|
|
if (mainThreadCount > 0) {
|
|
|
|
let table = document.createElement("table");
|
|
|
|
this.renderTableHeader(table, this.mainThreadTitle);
|
|
|
|
this.renderTable(table, mainThread);
|
|
|
|
|
|
|
|
slowSqlDiv.appendChild(table);
|
|
|
|
slowSqlDiv.appendChild(document.createElement("hr"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other threads
|
|
|
|
if (otherThreadCount > 0) {
|
|
|
|
let table = document.createElement("table");
|
|
|
|
this.renderTableHeader(table, this.otherThreadTitle);
|
|
|
|
this.renderTable(table, otherThreads);
|
|
|
|
|
|
|
|
slowSqlDiv.appendChild(table);
|
|
|
|
slowSqlDiv.appendChild(document.createElement("hr"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a header row for a Slow SQL table
|
2013-01-02 18:46:33 -08:00
|
|
|
* Tabs & newlines added to cells to make it easier to copy-paste.
|
2012-11-08 12:36:06 -08:00
|
|
|
*
|
|
|
|
* @param aTable Parent table element
|
|
|
|
* @param aTitle Table's title
|
|
|
|
*/
|
|
|
|
renderTableHeader: function SlowSQL_renderTableHeader(aTable, aTitle) {
|
|
|
|
let caption = document.createElement("caption");
|
2013-01-02 18:46:33 -08:00
|
|
|
caption.appendChild(document.createTextNode(aTitle + "\n"));
|
2012-11-08 12:36:06 -08:00
|
|
|
aTable.appendChild(caption);
|
|
|
|
|
|
|
|
let headings = document.createElement("tr");
|
2013-01-02 18:46:33 -08:00
|
|
|
this.appendColumn(headings, "th", this.slowSqlHits + "\t");
|
|
|
|
this.appendColumn(headings, "th", this.slowSqlAverage + "\t");
|
|
|
|
this.appendColumn(headings, "th", this.slowSqlStatement + "\n");
|
2012-11-08 12:36:06 -08:00
|
|
|
aTable.appendChild(headings);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills out the table body
|
2013-01-02 18:46:33 -08:00
|
|
|
* Tabs & newlines added to cells to make it easier to copy-paste.
|
2012-11-08 12:36:06 -08:00
|
|
|
*
|
|
|
|
* @param aTable Parent table element
|
|
|
|
* @param aSql SQL stats object
|
|
|
|
*/
|
|
|
|
renderTable: function SlowSQL_renderTable(aTable, aSql) {
|
|
|
|
for (let [sql, [hitCount, totalTime]] of Iterator(aSql)) {
|
|
|
|
let averageTime = totalTime / hitCount;
|
|
|
|
|
|
|
|
let sqlRow = document.createElement("tr");
|
|
|
|
|
2013-01-02 18:46:33 -08:00
|
|
|
this.appendColumn(sqlRow, "td", hitCount + "\t");
|
|
|
|
this.appendColumn(sqlRow, "td", averageTime.toFixed(0) + "\t");
|
|
|
|
this.appendColumn(sqlRow, "td", sql + "\n");
|
2012-11-08 12:36:06 -08:00
|
|
|
|
|
|
|
aTable.appendChild(sqlRow);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for appending a column to a Slow SQL table.
|
|
|
|
*
|
|
|
|
* @param aRowElement Parent row element
|
|
|
|
* @param aColType Column's tag name
|
|
|
|
* @param aColText Column contents
|
|
|
|
*/
|
|
|
|
appendColumn: function SlowSQL_appendColumn(aRowElement, aColType, aColText) {
|
|
|
|
let colElement = document.createElement(aColType);
|
2013-01-02 18:46:33 -08:00
|
|
|
let colTextElement = document.createTextNode(aColText);
|
|
|
|
colElement.appendChild(colTextElement);
|
2012-11-08 12:36:06 -08:00
|
|
|
aRowElement.appendChild(colElement);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-24 15:07:17 -08:00
|
|
|
/**
|
|
|
|
* Removes child elements from the supplied div
|
|
|
|
*
|
|
|
|
* @param aDiv Element to be cleared
|
|
|
|
*/
|
|
|
|
function clearDivData(aDiv) {
|
|
|
|
while (aDiv.hasChildNodes()) {
|
|
|
|
aDiv.removeChild(aDiv.lastChild);
|
|
|
|
}
|
|
|
|
};
|
2012-11-08 12:36:06 -08:00
|
|
|
|
2012-12-24 15:07:17 -08:00
|
|
|
let StackRenderer = {
|
2012-11-08 12:36:06 -08:00
|
|
|
|
|
|
|
stackTitle: bundle.GetStringFromName("stackTitle"),
|
|
|
|
|
|
|
|
memoryMapTitle: bundle.GetStringFromName("memoryMapTitle"),
|
|
|
|
|
2012-12-24 15:07:17 -08:00
|
|
|
/**
|
|
|
|
* Outputs the memory map associated with this hang report
|
|
|
|
*
|
|
|
|
* @param aDiv Output div
|
|
|
|
*/
|
|
|
|
renderMemoryMap: function StackRenderer_renderMemoryMap(aDiv, memoryMap) {
|
|
|
|
aDiv.appendChild(document.createTextNode(this.memoryMapTitle));
|
|
|
|
aDiv.appendChild(document.createElement("br"));
|
|
|
|
|
|
|
|
for (let currentModule of memoryMap) {
|
|
|
|
aDiv.appendChild(document.createTextNode(currentModule.join(" ")));
|
|
|
|
aDiv.appendChild(document.createElement("br"));
|
|
|
|
}
|
|
|
|
|
|
|
|
aDiv.appendChild(document.createElement("br"));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the raw PCs from the hang's stack
|
|
|
|
*
|
|
|
|
* @param aDiv Output div
|
|
|
|
* @param aStack Array of PCs from the hang stack
|
|
|
|
*/
|
|
|
|
renderStack: function StackRenderer_renderStack(aDiv, aStack) {
|
|
|
|
aDiv.appendChild(document.createTextNode(this.stackTitle));
|
|
|
|
let stackText = " " + aStack.join(" ");
|
|
|
|
aDiv.appendChild(document.createTextNode(stackText));
|
|
|
|
|
|
|
|
aDiv.appendChild(document.createElement("br"));
|
|
|
|
aDiv.appendChild(document.createElement("br"));
|
2013-01-17 07:25:44 -08:00
|
|
|
},
|
|
|
|
renderStacks: function StackRenderer_renderStacks(aPrefix, aStacks,
|
|
|
|
aMemoryMap, aRenderHeader) {
|
|
|
|
let div = document.getElementById(aPrefix + '-data');
|
|
|
|
clearDivData(div);
|
|
|
|
|
|
|
|
let fetchE = document.getElementById(aPrefix + '-fetch-symbols');
|
|
|
|
if (fetchE) {
|
|
|
|
fetchE.classList.remove("hidden");
|
|
|
|
}
|
|
|
|
let hideE = document.getElementById(aPrefix + '-hide-symbols');
|
|
|
|
if (hideE) {
|
|
|
|
hideE.classList.add("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aStacks.length == 0) {
|
|
|
|
showEmptySectionMessage(aPrefix + '-section');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.renderMemoryMap(div, aMemoryMap);
|
|
|
|
|
|
|
|
for (let i = 0; i < aStacks.length; ++i) {
|
|
|
|
let stack = aStacks[i];
|
|
|
|
aRenderHeader(i);
|
|
|
|
this.renderStack(div, stack)
|
|
|
|
}
|
2013-01-17 11:32:51 -08:00
|
|
|
},
|
2013-02-06 13:41:30 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the title of the stack: e.g. "Late Write #1" or
|
|
|
|
* "Hang Report #1 (6 seconds)".
|
|
|
|
*
|
|
|
|
* @param aFormatArgs formating args to be passed to formatStringFromName.
|
|
|
|
*/
|
|
|
|
renderHeader: function StackRenderer_renderHeader(aPrefix, aFormatArgs) {
|
|
|
|
let div = document.getElementById(aPrefix + "-data");
|
|
|
|
|
|
|
|
let titleElement = document.createElement("span");
|
|
|
|
titleElement.className = "stack-title";
|
|
|
|
|
|
|
|
let titleText = bundle.formatStringFromName(
|
|
|
|
aPrefix + "-title", aFormatArgs, aFormatArgs.length);
|
|
|
|
titleElement.appendChild(document.createTextNode(titleText));
|
|
|
|
|
|
|
|
div.appendChild(titleElement);
|
|
|
|
div.appendChild(document.createElement("br"));
|
|
|
|
}
|
2012-12-24 15:07:17 -08:00
|
|
|
};
|
|
|
|
|
2013-01-19 16:26:05 -08:00
|
|
|
function SymbolicationRequest(aPrefix, aRenderHeader, aMemoryMap, aStacks) {
|
|
|
|
this.prefix = aPrefix;
|
|
|
|
this.renderHeader = aRenderHeader;
|
|
|
|
this.memoryMap = aMemoryMap;
|
|
|
|
this.stacks = aStacks;
|
|
|
|
}
|
2013-02-05 14:04:05 -08:00
|
|
|
/**
|
|
|
|
* A callback for onreadystatechange. It replaces the numeric stack with
|
|
|
|
* the symbolicated one returned by the symbolication server.
|
|
|
|
*/
|
|
|
|
SymbolicationRequest.prototype.handleSymbolResponse =
|
|
|
|
function SymbolicationRequest_handleSymbolResponse() {
|
2013-02-04 13:00:34 -08:00
|
|
|
if (this.symbolRequest.readyState != 4)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let fetchElement = document.getElementById(this.prefix + "-fetch-symbols");
|
|
|
|
fetchElement.classList.add("hidden");
|
|
|
|
let hideElement = document.getElementById(this.prefix + "-hide-symbols");
|
|
|
|
hideElement.classList.remove("hidden");
|
|
|
|
let div = document.getElementById(this.prefix + "-data");
|
|
|
|
clearDivData(div);
|
|
|
|
let errorMessage = bundle.GetStringFromName("errorFetchingSymbols");
|
|
|
|
|
|
|
|
if (this.symbolRequest.status != 200) {
|
|
|
|
div.appendChild(document.createTextNode(errorMessage));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let jsonResponse = {};
|
|
|
|
try {
|
|
|
|
jsonResponse = JSON.parse(this.symbolRequest.responseText);
|
|
|
|
} catch (e) {
|
|
|
|
div.appendChild(document.createTextNode(errorMessage));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < jsonResponse.length; ++i) {
|
|
|
|
let stack = jsonResponse[i];
|
|
|
|
this.renderHeader(i);
|
|
|
|
|
|
|
|
for (let symbol of stack) {
|
|
|
|
div.appendChild(document.createTextNode(symbol));
|
|
|
|
div.appendChild(document.createElement("br"));
|
|
|
|
}
|
|
|
|
div.appendChild(document.createElement("br"));
|
|
|
|
}
|
2013-01-19 16:26:05 -08:00
|
|
|
};
|
2013-02-05 14:04:05 -08:00
|
|
|
/**
|
|
|
|
* Send a request to the symbolication server to symbolicate this stack.
|
|
|
|
*/
|
|
|
|
SymbolicationRequest.prototype.fetchSymbols =
|
|
|
|
function SymbolicationRequest_fetchSymbols() {
|
2013-01-19 16:26:05 -08:00
|
|
|
let symbolServerURI =
|
|
|
|
getPref(PREF_SYMBOL_SERVER_URI, DEFAULT_SYMBOL_SERVER_URI);
|
|
|
|
let request = {"memoryMap" : this.memoryMap, "stacks" : this.stacks,
|
|
|
|
"version" : 3};
|
|
|
|
let requestJSON = JSON.stringify(request);
|
|
|
|
|
|
|
|
this.symbolRequest = XMLHttpRequest();
|
|
|
|
this.symbolRequest.open("POST", symbolServerURI, true);
|
|
|
|
this.symbolRequest.setRequestHeader("Content-type", "application/json");
|
|
|
|
this.symbolRequest.setRequestHeader("Content-length",
|
|
|
|
requestJSON.length);
|
|
|
|
this.symbolRequest.setRequestHeader("Connection", "close");
|
|
|
|
this.symbolRequest.onreadystatechange = this.handleSymbolResponse.bind(this);
|
|
|
|
this.symbolRequest.send(requestJSON);
|
|
|
|
}
|
|
|
|
|
2012-12-24 15:07:17 -08:00
|
|
|
let ChromeHangs = {
|
|
|
|
|
|
|
|
symbolRequest: null,
|
|
|
|
|
2012-11-08 12:36:06 -08:00
|
|
|
/**
|
|
|
|
* Renders raw chrome hang data
|
|
|
|
*/
|
|
|
|
render: function ChromeHangs_render() {
|
|
|
|
let hangs = Telemetry.chromeHangs;
|
2012-11-20 06:45:14 -08:00
|
|
|
let stacks = hangs.stacks;
|
2012-12-24 15:07:17 -08:00
|
|
|
let memoryMap = hangs.memoryMap;
|
2013-01-17 07:25:44 -08:00
|
|
|
|
|
|
|
StackRenderer.renderStacks("chrome-hangs", stacks, memoryMap,
|
2013-01-17 11:32:51 -08:00
|
|
|
this.renderHangHeader);
|
2012-11-08 12:36:06 -08:00
|
|
|
},
|
|
|
|
|
2013-01-17 11:32:51 -08:00
|
|
|
renderHangHeader: function ChromeHangs_renderHangHeader(aIndex) {
|
|
|
|
let durations = Telemetry.chromeHangs.durations;
|
2013-02-06 13:41:30 -08:00
|
|
|
StackRenderer.renderHeader("chrome-hangs", [aIndex + 1, durations[aIndex]]);
|
2012-11-08 12:36:06 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let Histogram = {
|
|
|
|
|
|
|
|
hgramSamplesCaption: bundle.GetStringFromName("histogramSamples"),
|
|
|
|
|
|
|
|
hgramAverageCaption: bundle.GetStringFromName("histogramAverage"),
|
|
|
|
|
|
|
|
hgramSumCaption: bundle.GetStringFromName("histogramSum"),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a single Telemetry histogram
|
|
|
|
*
|
|
|
|
* @param aParent Parent element
|
|
|
|
* @param aName Histogram name
|
|
|
|
* @param aHgram Histogram information
|
|
|
|
*/
|
|
|
|
render: function Histogram_render(aParent, aName, aHgram) {
|
|
|
|
let hgram = this.unpack(aHgram);
|
|
|
|
|
|
|
|
let outerDiv = document.createElement("div");
|
|
|
|
outerDiv.className = "histogram";
|
|
|
|
outerDiv.id = aName;
|
|
|
|
|
|
|
|
let divTitle = document.createElement("div");
|
|
|
|
divTitle.className = "histogram-title";
|
|
|
|
divTitle.appendChild(document.createTextNode(aName));
|
|
|
|
outerDiv.appendChild(divTitle);
|
|
|
|
|
|
|
|
let stats = hgram.sample_count + " " + this.hgramSamplesCaption + ", " +
|
|
|
|
this.hgramAverageCaption + " = " + hgram.pretty_average + ", " +
|
|
|
|
this.hgramSumCaption + " = " + hgram.sum;
|
|
|
|
|
|
|
|
let divStats = document.createElement("div");
|
|
|
|
divStats.appendChild(document.createTextNode(stats));
|
|
|
|
outerDiv.appendChild(divStats);
|
|
|
|
|
|
|
|
if (isRTL())
|
|
|
|
hgram.values.reverse();
|
|
|
|
|
|
|
|
this.renderValues(outerDiv, hgram.values, hgram.max);
|
|
|
|
|
|
|
|
aParent.appendChild(outerDiv);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unpacks histogram values
|
|
|
|
*
|
|
|
|
* @param aHgram Packed histogram
|
|
|
|
*
|
|
|
|
* @return Unpacked histogram representation
|
|
|
|
*/
|
|
|
|
unpack: function Histogram_unpack(aHgram) {
|
|
|
|
let sample_count = aHgram.counts.reduceRight(function (a, b) a + b);
|
|
|
|
let buckets = [0, 1];
|
|
|
|
if (aHgram.histogram_type != Telemetry.HISTOGRAM_BOOLEAN) {
|
|
|
|
buckets = aHgram.ranges;
|
|
|
|
}
|
|
|
|
|
|
|
|
let average = Math.round(aHgram.sum * 10 / sample_count) / 10;
|
|
|
|
let max_value = Math.max.apply(Math, aHgram.counts);
|
|
|
|
|
|
|
|
let first = true;
|
|
|
|
let last = 0;
|
|
|
|
let values = [];
|
|
|
|
for (let i = 0; i < buckets.length; i++) {
|
|
|
|
let count = aHgram.counts[i];
|
|
|
|
if (!count)
|
|
|
|
continue;
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
if (i) {
|
|
|
|
values.push([buckets[i - 1], 0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last = i + 1;
|
|
|
|
values.push([buckets[i], count]);
|
|
|
|
}
|
|
|
|
if (last && last < buckets.length) {
|
|
|
|
values.push([buckets[last], 0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = {
|
|
|
|
values: values,
|
|
|
|
pretty_average: average,
|
|
|
|
max: max_value,
|
|
|
|
sample_count: sample_count,
|
|
|
|
sum: aHgram.sum
|
|
|
|
};
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create histogram bars
|
|
|
|
*
|
|
|
|
* @param aDiv Outer parent div
|
|
|
|
* @param aValues Histogram values
|
|
|
|
* @param aMaxValue Largest histogram value in set
|
|
|
|
*/
|
|
|
|
renderValues: function Histogram_renderValues(aDiv, aValues, aMaxValue) {
|
|
|
|
for (let [label, value] of aValues) {
|
|
|
|
let belowEm = Math.round(MAX_BAR_HEIGHT * (value / aMaxValue) * 10) / 10;
|
|
|
|
let aboveEm = MAX_BAR_HEIGHT - belowEm;
|
|
|
|
|
|
|
|
let barDiv = document.createElement("div");
|
|
|
|
barDiv.className = "bar";
|
|
|
|
barDiv.style.paddingTop = aboveEm + "em";
|
|
|
|
|
|
|
|
// Add value label or an nbsp if no value
|
|
|
|
barDiv.appendChild(document.createTextNode(value ? value : '\u00A0'));
|
|
|
|
|
|
|
|
// Create the blue bar
|
|
|
|
let bar = document.createElement("div");
|
|
|
|
bar.className = "bar-inner";
|
|
|
|
bar.style.height = belowEm + "em";
|
|
|
|
barDiv.appendChild(bar);
|
|
|
|
|
|
|
|
// Add bucket label
|
|
|
|
barDiv.appendChild(document.createTextNode(label));
|
|
|
|
|
|
|
|
aDiv.appendChild(barDiv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let KeyValueTable = {
|
|
|
|
|
|
|
|
keysHeader: bundle.GetStringFromName("keysHeader"),
|
|
|
|
|
|
|
|
valuesHeader: bundle.GetStringFromName("valuesHeader"),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill out a 2-column table with keys and values
|
|
|
|
*/
|
|
|
|
render: function KeyValueTable_render(aTableID, aMeasurements) {
|
|
|
|
let table = document.getElementById(aTableID);
|
|
|
|
this.renderHeader(table);
|
|
|
|
this.renderBody(table, aMeasurements);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the table header
|
2013-01-02 18:46:33 -08:00
|
|
|
* Tabs & newlines added to cells to make it easier to copy-paste.
|
2012-11-08 12:36:06 -08:00
|
|
|
*
|
|
|
|
* @param aTable Table element
|
|
|
|
*/
|
|
|
|
renderHeader: function KeyValueTable_renderHeader(aTable) {
|
|
|
|
let headerRow = document.createElement("tr");
|
|
|
|
aTable.appendChild(headerRow);
|
|
|
|
|
|
|
|
let keysColumn = document.createElement("th");
|
2013-01-02 18:46:33 -08:00
|
|
|
keysColumn.appendChild(document.createTextNode(this.keysHeader + "\t"));
|
2012-11-08 12:36:06 -08:00
|
|
|
let valuesColumn = document.createElement("th");
|
2013-01-02 18:46:33 -08:00
|
|
|
valuesColumn.appendChild(document.createTextNode(this.valuesHeader + "\n"));
|
2012-11-08 12:36:06 -08:00
|
|
|
|
|
|
|
headerRow.appendChild(keysColumn);
|
|
|
|
headerRow.appendChild(valuesColumn);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the table body
|
2013-01-02 18:46:33 -08:00
|
|
|
* Tabs & newlines added to cells to make it easier to copy-paste.
|
2012-11-08 12:36:06 -08:00
|
|
|
*
|
|
|
|
* @param aTable Table element
|
|
|
|
* @param aMeasurements Key/value map
|
|
|
|
*/
|
|
|
|
renderBody: function KeyValueTable_renderBody(aTable, aMeasurements) {
|
|
|
|
for (let [key, value] of Iterator(aMeasurements)) {
|
|
|
|
if (typeof value == "object") {
|
|
|
|
value = JSON.stringify(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
let newRow = document.createElement("tr");
|
|
|
|
aTable.appendChild(newRow);
|
|
|
|
|
|
|
|
let keyField = document.createElement("td");
|
2013-01-02 18:46:33 -08:00
|
|
|
keyField.appendChild(document.createTextNode(key + "\t"));
|
2012-11-08 12:36:06 -08:00
|
|
|
newRow.appendChild(keyField);
|
|
|
|
|
|
|
|
let valueField = document.createElement("td");
|
2013-01-02 18:46:33 -08:00
|
|
|
valueField.appendChild(document.createTextNode(value + "\n"));
|
2012-11-08 12:36:06 -08:00
|
|
|
newRow.appendChild(valueField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for showing "No data collected" message for a section
|
|
|
|
*
|
|
|
|
* @param aSectionID ID of the section element that needs to be changed
|
|
|
|
*/
|
|
|
|
function showEmptySectionMessage(aSectionID) {
|
|
|
|
let sectionElement = document.getElementById(aSectionID);
|
|
|
|
|
|
|
|
// Hide toggle captions
|
|
|
|
let toggleElements = sectionElement.getElementsByClassName("toggle-caption");
|
|
|
|
toggleElements[0].classList.add("hidden");
|
|
|
|
toggleElements[1].classList.add("hidden");
|
|
|
|
|
|
|
|
// Show "No data collected" message
|
|
|
|
let messageElement = sectionElement.getElementsByClassName("empty-caption")[0];
|
|
|
|
messageElement.classList.remove("hidden");
|
|
|
|
|
|
|
|
// Don't allow section to be expanded by clicking on the header text
|
|
|
|
let sectionHeaders = sectionElement.getElementsByClassName("section-name");
|
|
|
|
for (let sectionHeader of sectionHeaders) {
|
|
|
|
sectionHeader.removeEventListener("click", toggleSection);
|
|
|
|
sectionHeader.style.cursor = "auto";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow section to be expanded by clicking on the toggle text
|
|
|
|
let toggleLinks = sectionElement.getElementsByClassName("toggle-caption");
|
|
|
|
for (let toggleLink of toggleLinks) {
|
|
|
|
toggleLink.removeEventListener("click", toggleSection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function that expands and collapses sections +
|
|
|
|
* changes caption on the toggle text
|
|
|
|
*/
|
|
|
|
function toggleSection(aEvent) {
|
|
|
|
let parentElement = aEvent.target.parentElement;
|
|
|
|
let sectionDiv = parentElement.getElementsByTagName("div")[0];
|
|
|
|
sectionDiv.classList.toggle("hidden");
|
|
|
|
|
|
|
|
let toggleLinks = parentElement.getElementsByClassName("toggle-caption");
|
|
|
|
toggleLinks[0].classList.toggle("hidden");
|
|
|
|
toggleLinks[1].classList.toggle("hidden");
|
|
|
|
}
|
|
|
|
|
2012-11-26 15:21:04 -08:00
|
|
|
/**
|
|
|
|
* Sets the text of the page header based on a config pref + bundle strings
|
|
|
|
*/
|
|
|
|
function setupPageHeader()
|
|
|
|
{
|
|
|
|
let serverOwner = getPref(PREF_TELEMETRY_SERVER_OWNER, "Mozilla");
|
|
|
|
let brandName = brandBundle.GetStringFromName("brandFullName");
|
|
|
|
let subtitleText = bundle.formatStringFromName(
|
|
|
|
"pageSubtitle", [serverOwner, brandName], 2);
|
|
|
|
|
|
|
|
let subtitleElement = document.getElementById("page-subtitle");
|
|
|
|
subtitleElement.appendChild(document.createTextNode(subtitleText));
|
|
|
|
}
|
2012-11-08 12:36:06 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes load/unload, pref change and mouse-click listeners
|
|
|
|
*/
|
|
|
|
function setupListeners() {
|
|
|
|
Services.prefs.addObserver(PREF_TELEMETRY_ENABLED, observer, false);
|
|
|
|
observer.updatePrefStatus();
|
|
|
|
|
|
|
|
// Clean up observers when page is closed
|
|
|
|
window.addEventListener("unload",
|
|
|
|
function unloadHandler(aEvent) {
|
|
|
|
window.removeEventListener("unload", unloadHandler);
|
|
|
|
Services.prefs.removeObserver(PREF_TELEMETRY_ENABLED, observer);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
document.getElementById("toggle-telemetry").addEventListener("click",
|
|
|
|
function () {
|
|
|
|
let value = getPref(PREF_TELEMETRY_ENABLED, false);
|
|
|
|
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, !value);
|
|
|
|
}, false);
|
|
|
|
|
2013-01-17 07:25:44 -08:00
|
|
|
document.getElementById("chrome-hangs-fetch-symbols").addEventListener("click",
|
2012-11-08 12:36:06 -08:00
|
|
|
function () {
|
2013-01-19 16:26:05 -08:00
|
|
|
let hangs = Telemetry.chromeHangs;
|
|
|
|
let req = new SymbolicationRequest("chrome-hangs",
|
|
|
|
ChromeHangs.renderHangHeader,
|
|
|
|
hangs.memoryMap, hangs.stacks);
|
|
|
|
req.fetchSymbols();
|
2012-11-08 12:36:06 -08:00
|
|
|
}, false);
|
|
|
|
|
2013-01-17 07:25:44 -08:00
|
|
|
document.getElementById("chrome-hangs-hide-symbols").addEventListener("click",
|
2012-11-08 12:36:06 -08:00
|
|
|
function () {
|
|
|
|
ChromeHangs.render();
|
|
|
|
}, false);
|
|
|
|
|
2013-01-19 16:26:05 -08:00
|
|
|
document.getElementById("late-writes-fetch-symbols").addEventListener("click",
|
|
|
|
function () {
|
|
|
|
let lateWrites = TelemetryPing.getPayload().lateWrites;
|
2013-02-06 13:41:30 -08:00
|
|
|
let req = new SymbolicationRequest("late-writes",
|
|
|
|
LateWritesSingleton.renderHeader,
|
2013-01-19 16:26:05 -08:00
|
|
|
lateWrites.memoryMap,
|
|
|
|
lateWrites.stacks);
|
|
|
|
req.fetchSymbols();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
document.getElementById("late-writes-hide-symbols").addEventListener("click",
|
|
|
|
function () {
|
|
|
|
let ping = TelemetryPing.getPayload();
|
|
|
|
LateWritesSingleton.renderLateWrites(ping.lateWrites);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2012-11-08 12:36:06 -08:00
|
|
|
// Clicking on the section name will toggle its state
|
|
|
|
let sectionHeaders = document.getElementsByClassName("section-name");
|
|
|
|
for (let sectionHeader of sectionHeaders) {
|
|
|
|
sectionHeader.addEventListener("click", toggleSection, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clicking on the "collapse"/"expand" text will also toggle section's state
|
|
|
|
let toggleLinks = document.getElementsByClassName("toggle-caption");
|
|
|
|
for (let toggleLink of toggleLinks) {
|
|
|
|
toggleLink.addEventListener("click", toggleSection, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
window.removeEventListener("load", onLoad);
|
|
|
|
|
2012-11-26 15:21:04 -08:00
|
|
|
// Set the text in the page header
|
|
|
|
setupPageHeader();
|
|
|
|
|
2012-11-08 12:36:06 -08:00
|
|
|
// Set up event listeners
|
|
|
|
setupListeners();
|
|
|
|
|
|
|
|
// Show slow SQL stats
|
|
|
|
SlowSQL.render();
|
|
|
|
|
|
|
|
// Show chrome hang stacks
|
|
|
|
ChromeHangs.render();
|
|
|
|
|
|
|
|
// Show histogram data
|
|
|
|
let histograms = Telemetry.histogramSnapshots;
|
|
|
|
if (Object.keys(histograms).length) {
|
|
|
|
let hgramDiv = document.getElementById("histograms");
|
|
|
|
for (let [name, hgram] of Iterator(histograms)) {
|
|
|
|
Histogram.render(hgramDiv, name, hgram);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showEmptySectionMessage("histograms-section");
|
|
|
|
}
|
|
|
|
|
2012-12-13 20:13:03 -08:00
|
|
|
// Show addon histogram data
|
2012-12-27 09:28:33 -08:00
|
|
|
let addonDiv = document.getElementById("addon-histograms");
|
|
|
|
let addonHistogramsRendered = false;
|
|
|
|
let addonData = Telemetry.addonHistogramSnapshots;
|
|
|
|
for (let [addon, histograms] of Iterator(addonData)) {
|
2012-12-13 20:13:03 -08:00
|
|
|
for (let [name, hgram] of Iterator(histograms)) {
|
2012-12-27 09:28:33 -08:00
|
|
|
addonHistogramsRendered = true;
|
|
|
|
Histogram.render(addonDiv, addon + ": " + name, hgram);
|
2012-12-13 20:13:03 -08:00
|
|
|
}
|
2012-12-27 09:28:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!addonHistogramsRendered) {
|
2012-12-13 20:13:03 -08:00
|
|
|
showEmptySectionMessage("addon-histograms-section");
|
|
|
|
}
|
|
|
|
|
2012-11-08 12:36:06 -08:00
|
|
|
// Get the Telemetry Ping payload
|
2012-12-19 07:29:08 -08:00
|
|
|
Telemetry.asyncFetchTelemetryData(displayPingData);
|
2013-01-08 06:04:37 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
let LateWritesSingleton = {
|
2013-02-06 13:41:30 -08:00
|
|
|
renderHeader: function LateWritesSingleton_renderHeader(aIndex) {
|
|
|
|
StackRenderer.renderHeader("late-writes", [aIndex + 1]);
|
|
|
|
},
|
|
|
|
|
2013-01-08 06:04:37 -08:00
|
|
|
renderLateWrites: function LateWritesSingleton_renderLateWrites(lateWrites) {
|
|
|
|
let stacks = lateWrites.stacks;
|
|
|
|
let memoryMap = lateWrites.memoryMap;
|
2013-02-06 13:41:30 -08:00
|
|
|
StackRenderer.renderStacks('late-writes', stacks, memoryMap,
|
|
|
|
LateWritesSingleton.renderHeader);
|
2013-01-08 06:04:37 -08:00
|
|
|
}
|
|
|
|
};
|
2012-12-13 20:13:03 -08:00
|
|
|
|
2013-01-11 07:26:32 -08:00
|
|
|
/**
|
|
|
|
* Helper function for sorting the startup milestones in the Simple Measurements
|
|
|
|
* section into temporal order.
|
|
|
|
*
|
|
|
|
* @param aSimpleMeasurements Telemetry ping's "Simple Measurements" data
|
|
|
|
* @return Sorted measurements
|
|
|
|
*/
|
|
|
|
function sortStartupMilestones(aSimpleMeasurements) {
|
|
|
|
// List of startup milestones
|
|
|
|
const startupMilestones =
|
|
|
|
["start", "main", "startupCrashDetectionBegin", "createTopLevelWindow",
|
|
|
|
"firstPaint", "delayedStartupStarted", "firstLoadURI",
|
|
|
|
"sessionRestoreInitialized", "sessionRestoreRestoring", "sessionRestored",
|
2013-02-07 13:47:33 -08:00
|
|
|
"delayedStartupFinished", "startupCrashDetectionEnd",
|
|
|
|
"AMI_startup_begin", "AMI_startup_end", "XPI_startup_begin", "XPI_startup_end",
|
|
|
|
"XPI_bootstrap_addons_begin", "XPI_bootstrap_addons_end"];
|
2013-01-11 07:26:32 -08:00
|
|
|
|
|
|
|
let sortedKeys = Object.keys(aSimpleMeasurements);
|
|
|
|
|
|
|
|
// Sort the measurements, with startup milestones at the front + ordered by time
|
|
|
|
sortedKeys.sort(function keyCompare(keyA, keyB) {
|
|
|
|
let isKeyAMilestone = (startupMilestones.indexOf(keyA) > -1);
|
|
|
|
let isKeyBMilestone = (startupMilestones.indexOf(keyB) > -1);
|
|
|
|
|
|
|
|
// First order by startup vs non-startup measurement
|
|
|
|
if (isKeyAMilestone && !isKeyBMilestone)
|
|
|
|
return -1;
|
|
|
|
if (!isKeyAMilestone && isKeyBMilestone)
|
|
|
|
return 1;
|
|
|
|
// Don't change order of non-startup measurements
|
|
|
|
if (!isKeyAMilestone && !isKeyBMilestone)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// If both keys are startup measurements, order them by value
|
|
|
|
return aSimpleMeasurements[keyA] - aSimpleMeasurements[keyB];
|
|
|
|
});
|
|
|
|
|
|
|
|
// Insert measurements into a result object in sort-order
|
|
|
|
let result = {};
|
|
|
|
for (let key of sortedKeys) {
|
|
|
|
result[key] = aSimpleMeasurements[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-12-20 17:04:58 -08:00
|
|
|
function displayPingData() {
|
2012-12-03 10:31:00 -08:00
|
|
|
let ping = TelemetryPing.getPayload();
|
2012-11-08 12:36:06 -08:00
|
|
|
|
|
|
|
// Show simple measurements
|
2013-01-11 07:26:32 -08:00
|
|
|
let simpleMeasurements = sortStartupMilestones(ping.simpleMeasurements);
|
|
|
|
if (Object.keys(simpleMeasurements).length) {
|
|
|
|
KeyValueTable.render("simple-measurements-table", simpleMeasurements);
|
2012-11-08 12:36:06 -08:00
|
|
|
} else {
|
|
|
|
showEmptySectionMessage("simple-measurements-section");
|
|
|
|
}
|
|
|
|
|
2013-01-08 06:04:37 -08:00
|
|
|
LateWritesSingleton.renderLateWrites(ping.lateWrites);
|
|
|
|
|
2012-11-08 12:36:06 -08:00
|
|
|
// Show basic system info gathered
|
|
|
|
if (Object.keys(ping.info).length) {
|
|
|
|
KeyValueTable.render("system-info-table", ping.info);
|
|
|
|
} else {
|
|
|
|
showEmptySectionMessage("system-info-section");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", onLoad, false);
|