2010-02-20 13:23:25 -08:00
|
|
|
/* -*- Mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is about:memory
|
|
|
|
*
|
2011-05-03 17:12:58 -07:00
|
|
|
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
2010-02-20 13:23:25 -08:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
2011-05-03 17:12:58 -07:00
|
|
|
* Nicholas Nethercote <nnethercote@mozilla.com>
|
2010-02-20 13:23:25 -08:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
"use strict";
|
|
|
|
|
2011-03-31 10:19:30 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2011-05-11 16:09:50 -07:00
|
|
|
const Cu = Components.utils;
|
2011-03-31 10:19:30 -07:00
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
// Must use .href here instead of .search because "about:memory" is a
|
|
|
|
// non-standard URL.
|
|
|
|
var gVerbose = (location.href.split(/[\?,]/).indexOf("verbose") !== -1);
|
2010-02-20 13:23:25 -08:00
|
|
|
|
2011-05-11 16:09:50 -07:00
|
|
|
var gAddedObserver = false;
|
|
|
|
|
2011-07-24 20:56:50 -07:00
|
|
|
const KIND_NONHEAP = Ci.nsIMemoryReporter.KIND_NONHEAP;
|
|
|
|
const KIND_HEAP = Ci.nsIMemoryReporter.KIND_HEAP;
|
|
|
|
const KIND_OTHER = Ci.nsIMemoryReporter.KIND_OTHER;
|
|
|
|
const UNITS_BYTES = Ci.nsIMemoryReporter.UNITS_BYTES;
|
|
|
|
const UNITS_COUNT = Ci.nsIMemoryReporter.UNITS_COUNT;
|
|
|
|
const UNITS_COUNT_CUMULATIVE = Ci.nsIMemoryReporter.UNITS_COUNT_CUMULATIVE;
|
2011-07-20 21:08:24 -07:00
|
|
|
const UNITS_PERCENTAGE = Ci.nsIMemoryReporter.UNITS_PERCENTAGE;
|
2011-05-22 19:49:56 -07:00
|
|
|
|
2011-06-16 11:34:09 -07:00
|
|
|
const kUnknown = -1; // used for _amount if a memory reporter failed
|
2011-05-22 19:49:56 -07:00
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
function onLoad()
|
|
|
|
{
|
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Ci.nsIObserverService);
|
|
|
|
os.notifyObservers(null, "child-memory-reporter-request", null);
|
2010-02-20 13:23:25 -08:00
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
os.addObserver(ChildMemoryListener, "child-memory-reporter-update", false);
|
2011-05-11 16:09:50 -07:00
|
|
|
gAddedObserver = true;
|
2010-02-20 13:23:25 -08:00
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
update();
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
function onUnload()
|
|
|
|
{
|
2011-05-11 16:09:50 -07:00
|
|
|
// We need to check if the observer has been added before removing; in some
|
|
|
|
// circumstances (eg. reloading the page quickly) it might not have because
|
|
|
|
// onLoad might not fire.
|
|
|
|
if (gAddedObserver) {
|
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Ci.nsIObserverService);
|
|
|
|
os.removeObserver(ChildMemoryListener, "child-memory-reporter-update");
|
|
|
|
}
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
function ChildMemoryListener(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
update();
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
function $(n)
|
|
|
|
{
|
|
|
|
return document.getElementById(n);
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
|
|
|
|
2011-05-11 16:09:50 -07:00
|
|
|
function doGlobalGC()
|
|
|
|
{
|
|
|
|
Cu.forceGC();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
function doGlobalGCandCC()
|
|
|
|
{
|
|
|
|
window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.garbageCollect();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// For maximum effect, this returns to the event loop between each
|
|
|
|
// notification. See bug 610166 comment 12 for an explanation.
|
|
|
|
// Ideally a single notification would be enough.
|
|
|
|
function sendHeapMinNotifications()
|
|
|
|
{
|
|
|
|
function runSoon(f)
|
|
|
|
{
|
|
|
|
var tm = Cc["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService(Ci.nsIThreadManager);
|
|
|
|
|
|
|
|
tm.mainThread.dispatch({ run: f }, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendHeapMinNotificationsInner()
|
|
|
|
{
|
|
|
|
var os = Cc["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Ci.nsIObserverService);
|
|
|
|
os.notifyObservers(null, "memory-pressure", "heap-minimize");
|
|
|
|
|
|
|
|
if (++j < 3)
|
|
|
|
runSoon(sendHeapMinNotificationsInner);
|
|
|
|
else
|
|
|
|
runSoon(update);
|
|
|
|
}
|
|
|
|
|
|
|
|
var j = 0;
|
|
|
|
sendHeapMinNotificationsInner();
|
|
|
|
}
|
|
|
|
|
2011-07-25 18:51:38 -07:00
|
|
|
function getReportersByProcess()
|
2011-05-03 17:12:58 -07:00
|
|
|
{
|
|
|
|
var mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
|
|
|
|
getService(Ci.nsIMemoryReporterManager);
|
|
|
|
|
|
|
|
// Process each memory reporter:
|
|
|
|
// - Make a copy of it into a sub-table indexed by its process. Each copy
|
|
|
|
// looks like this:
|
|
|
|
//
|
2011-06-05 18:22:45 -07:00
|
|
|
// interface Reporter {
|
|
|
|
// _path: string;
|
2011-05-22 19:49:56 -07:00
|
|
|
// _kind: number;
|
2011-06-16 11:34:09 -07:00
|
|
|
// _units: number;
|
|
|
|
// _amount: number;
|
2011-05-03 17:12:58 -07:00
|
|
|
// _description: string;
|
2011-07-19 16:59:17 -07:00
|
|
|
// _nMerged: number; (only defined if >= 2)
|
2011-05-03 17:12:58 -07:00
|
|
|
// }
|
|
|
|
//
|
2011-06-05 18:22:45 -07:00
|
|
|
// After this point we never use the original memory reporter again.
|
|
|
|
//
|
2011-06-16 11:34:09 -07:00
|
|
|
// - Note that copying rOrig.amount (which calls a C++ function under the
|
|
|
|
// IDL covers) to r._amount for every reporter now means that the
|
2011-05-03 17:12:58 -07:00
|
|
|
// results as consistent as possible -- measurements are made all at
|
|
|
|
// once before most of the memory required to generate this page is
|
|
|
|
// allocated.
|
2011-06-05 18:22:45 -07:00
|
|
|
var reportersByProcess = {};
|
2011-06-29 16:39:32 -07:00
|
|
|
|
|
|
|
function addReporter(aProcess, aPath, aKind, aUnits, aAmount, aDescription)
|
|
|
|
{
|
|
|
|
var process = aProcess === "" ? "Main" : aProcess;
|
2011-06-05 18:22:45 -07:00
|
|
|
var r = {
|
2011-06-29 16:39:32 -07:00
|
|
|
_path: aPath,
|
|
|
|
_kind: aKind,
|
|
|
|
_units: aUnits,
|
|
|
|
_amount: aAmount,
|
|
|
|
_description: aDescription
|
2011-06-05 18:22:45 -07:00
|
|
|
};
|
|
|
|
if (!reportersByProcess[process]) {
|
|
|
|
reportersByProcess[process] = {};
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
2011-06-05 18:22:45 -07:00
|
|
|
var reporters = reportersByProcess[process];
|
2011-07-19 16:59:17 -07:00
|
|
|
var reporter = reporters[r._path];
|
|
|
|
if (reporter) {
|
2011-05-03 17:12:58 -07:00
|
|
|
// Already an entry; must be a duplicated reporter. This can
|
2011-07-19 16:59:17 -07:00
|
|
|
// happen legitimately. Sum the values (accounting for possible kUnknown
|
|
|
|
// amounts), and mark the reporter as a dup. We mark dups because it's
|
|
|
|
// useful to know when a reporter is duplicated; it might be worth
|
|
|
|
// investigating and splitting up to have non-duplicated names.
|
|
|
|
if (reporter._amount !== kUnknown && r._amount !== kUnknown) {
|
|
|
|
reporter._amount += r._amount;
|
|
|
|
} else if (reporter._amount === kUnknown && r._amount !== kUnknown) {
|
|
|
|
reporter._amount = r._amount;
|
|
|
|
}
|
|
|
|
reporter._nMerged = reporter._nMerged ? reporter._nMerged + 1 : 2;
|
2011-05-03 17:12:58 -07:00
|
|
|
} else {
|
2011-06-05 18:22:45 -07:00
|
|
|
reporters[r._path] = r;
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-29 16:39:32 -07:00
|
|
|
// Process vanilla reporters first, then multi-reporters.
|
|
|
|
var e = mgr.enumerateReporters();
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
var rOrig = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
|
|
|
|
addReporter(rOrig.process, rOrig.path, rOrig.kind, rOrig.units,
|
|
|
|
rOrig.amount, rOrig.description);
|
|
|
|
}
|
|
|
|
var e = mgr.enumerateMultiReporters();
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
var r = e.getNext().QueryInterface(Ci.nsIMemoryMultiReporter);
|
|
|
|
r.collectReports(addReporter, null);
|
|
|
|
}
|
|
|
|
|
2011-07-25 18:51:38 -07:00
|
|
|
return reportersByProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Top-level function that does the work of generating the page.
|
|
|
|
*/
|
|
|
|
function update()
|
|
|
|
{
|
|
|
|
// First, clear the page contents. Necessary because update() might be
|
|
|
|
// called more than once due to ChildMemoryListener.
|
|
|
|
var content = $("content");
|
|
|
|
content.parentNode.replaceChild(content.cloneNode(false), content);
|
|
|
|
content = $("content");
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
// Generate output for one process at a time. Always start with the
|
|
|
|
// Main process.
|
2011-07-25 18:51:38 -07:00
|
|
|
var reportersByProcess = getReportersByProcess();
|
2011-06-05 18:22:45 -07:00
|
|
|
var text = genProcessText("Main", reportersByProcess["Main"]);
|
|
|
|
for (var process in reportersByProcess) {
|
2011-05-03 17:12:58 -07:00
|
|
|
if (process !== "Main") {
|
2011-06-05 18:22:45 -07:00
|
|
|
text += genProcessText(process, reportersByProcess[process]);
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-11 16:09:50 -07:00
|
|
|
// Memory-related actions.
|
|
|
|
const GCDesc = "Do a global garbage collection.";
|
|
|
|
// XXX: once bug 625302 is fixed, should change this button to just do a CC.
|
|
|
|
const CCDesc = "Do a global garbage collection followed by a cycle " +
|
|
|
|
"collection. (It currently is not possible to do a cycle " +
|
|
|
|
"collection on its own, see bug 625302.)";
|
2011-05-22 19:49:56 -07:00
|
|
|
const MPDesc = "Send three \"heap-minimize\" notifications in a " +
|
|
|
|
"row. Each notification triggers a global garbage " +
|
|
|
|
"collection followed by a cycle collection, and causes the " +
|
|
|
|
"process to reduce memory usage in other ways, e.g. by " +
|
|
|
|
"flushing various caches.";
|
2011-05-11 16:09:50 -07:00
|
|
|
|
|
|
|
text += "<div>" +
|
|
|
|
"<button title='" + GCDesc + "' onclick='doGlobalGC()'>GC</button>" +
|
|
|
|
"<button title='" + CCDesc + "' onclick='doGlobalGCandCC()'>GC + CC</button>" +
|
|
|
|
"<button title='" + MPDesc + "' onclick='sendHeapMinNotifications()'>" + "Minimize memory usage</button>" +
|
|
|
|
"</div>";
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
// Generate verbosity option link at the bottom.
|
2011-05-22 19:49:59 -07:00
|
|
|
text += "<div>";
|
2011-05-03 17:12:58 -07:00
|
|
|
text += gVerbose
|
|
|
|
? "<span class='option'><a href='about:memory'>Less verbose</a></span>"
|
|
|
|
: "<span class='option'><a href='about:memory?verbose'>More verbose</a></span>";
|
2011-05-22 19:49:59 -07:00
|
|
|
text += "</div>";
|
|
|
|
|
|
|
|
text += "<div>" +
|
|
|
|
"<span class='legend'>Hover the pointer over the name of a memory " +
|
|
|
|
"reporter to see a detailed description of what it measures.</span>"
|
|
|
|
"</div>";
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
var div = document.createElement("div");
|
|
|
|
div.innerHTML = text;
|
|
|
|
content.appendChild(div);
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
|
|
|
|
2011-07-20 21:08:24 -07:00
|
|
|
// Compare two 'explicit' memory reporter nodes.
|
|
|
|
function cmpExplicitReporters(a, b)
|
2011-05-22 19:49:56 -07:00
|
|
|
{
|
2011-07-20 21:08:24 -07:00
|
|
|
assert(a._units === undefined && b._units === undefined,
|
|
|
|
"'explicit' tree nodes must not have _units defined");
|
2011-07-06 23:37:26 -07:00
|
|
|
return b._amount - a._amount;
|
2011-05-22 19:49:56 -07:00
|
|
|
};
|
|
|
|
|
2011-07-20 21:08:24 -07:00
|
|
|
// Compare two memory reporter nodes from the 'other measurements' list.
|
|
|
|
function cmpOtherReporters(a, b)
|
|
|
|
{
|
|
|
|
return a._path < b._path ? -1 :
|
|
|
|
a._path > b._path ? 1 :
|
|
|
|
0;
|
|
|
|
};
|
|
|
|
|
2011-07-25 18:51:38 -07:00
|
|
|
function findKid(aName, aKids)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < aKids.length; i++) {
|
|
|
|
if (aKids[i]._name === aName) {
|
|
|
|
return aKids[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2011-03-31 10:19:30 -07:00
|
|
|
/**
|
2011-07-25 18:51:38 -07:00
|
|
|
* From a list of memory reporters, builds a tree that mirrors the tree
|
|
|
|
* structure that will be shown as output.
|
2011-05-03 17:12:58 -07:00
|
|
|
*
|
2011-06-05 18:22:45 -07:00
|
|
|
* @param aReporters
|
2011-07-25 18:51:38 -07:00
|
|
|
* The list of memory reporters.
|
|
|
|
* @return The built tree. The tree nodes have this structure:
|
|
|
|
* interface Node {
|
|
|
|
* _name: string;
|
|
|
|
* _kind: number;
|
|
|
|
* _amount: number; (non-negative or 'kUnknown')
|
|
|
|
* _description: string;
|
|
|
|
* _kids: [Node];
|
|
|
|
* _hasReporter: boolean; (only defined if 'true')
|
|
|
|
* _hasProblem: boolean; (only defined if 'true')
|
|
|
|
* _nMerged: number; (only defined if >= 2)
|
|
|
|
* }
|
|
|
|
* _units isn't needed because it's always UNITS_BYTES for 'explicit'
|
|
|
|
* reporters.
|
2011-03-31 10:19:30 -07:00
|
|
|
*/
|
2011-07-25 18:51:38 -07:00
|
|
|
function buildTree(aReporters)
|
2010-02-20 13:23:25 -08:00
|
|
|
{
|
2011-07-25 18:51:38 -07:00
|
|
|
const treeName = "explicit";
|
|
|
|
|
|
|
|
// We want to process all reporters that begin with 'treeName'. First we
|
|
|
|
// build the tree but only fill in '_name', '_kind', '_kids', maybe
|
|
|
|
// '_hasReporter' and maybe '_nMerged'. This is done top-down from the
|
|
|
|
// reporters.
|
|
|
|
var t = {
|
|
|
|
_name: "falseRoot",
|
|
|
|
_kind: KIND_OTHER,
|
|
|
|
_kids: []
|
|
|
|
};
|
|
|
|
for (var path in aReporters) {
|
|
|
|
var r = aReporters[path];
|
|
|
|
if (r._path.slice(0, treeName.length) === treeName) {
|
|
|
|
assert(r._kind === KIND_HEAP || r._kind === KIND_NONHEAP,
|
|
|
|
"reporters in the tree must have KIND_HEAP or KIND_NONHEAP");
|
|
|
|
assert(r._units === UNITS_BYTES);
|
|
|
|
var names = r._path.split('/');
|
|
|
|
var u = t;
|
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var name = names[i];
|
|
|
|
var uMatch = findKid(name, u._kids);
|
|
|
|
if (uMatch) {
|
|
|
|
u = uMatch;
|
|
|
|
} else {
|
|
|
|
var v = {
|
|
|
|
_name: name,
|
|
|
|
_kind: KIND_OTHER,
|
|
|
|
_kids: []
|
|
|
|
};
|
|
|
|
u._kids.push(v);
|
|
|
|
u = v;
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
u._kind = r._kind;
|
|
|
|
u._hasReporter = true;
|
|
|
|
if (r._nMerged) {
|
|
|
|
u._nMerged = r._nMerged;
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
}
|
|
|
|
// Using falseRoot makes the above code simpler. Now discard it, leaving
|
|
|
|
// treeName at the root.
|
|
|
|
t = t._kids[0];
|
|
|
|
|
|
|
|
// Next, fill in '_description' and '_amount', and maybe '_hasProblem'
|
|
|
|
// for each node. This is done bottom-up because for most non-leaf nodes
|
|
|
|
// '_amount' and '_description' are determined from the child nodes.
|
|
|
|
function fillInTree(aT, aPrepath)
|
|
|
|
{
|
|
|
|
var path = aPrepath ? aPrepath + '/' + aT._name : aT._name;
|
|
|
|
if (aT._kids.length === 0) {
|
|
|
|
// Leaf node. Must have a reporter.
|
|
|
|
aT._description = getDescription(aReporters, path);
|
|
|
|
var amount = getBytes(aReporters, path);
|
|
|
|
if (amount !== kUnknown) {
|
|
|
|
aT._amount = amount;
|
|
|
|
} else {
|
|
|
|
aT._amount = 0;
|
|
|
|
aT._hasProblem = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Non-leaf node. Get the size of the children.
|
|
|
|
var childrenBytes = 0;
|
|
|
|
for (var i = 0; i < aT._kids.length; i++) {
|
|
|
|
// Allow for kUnknown, treat it like 0.
|
|
|
|
var b = fillInTree(aT._kids[i], path);
|
|
|
|
childrenBytes += (b === kUnknown ? 0 : b);
|
|
|
|
}
|
|
|
|
if (aT._hasReporter === true) {
|
2011-06-05 18:22:45 -07:00
|
|
|
aT._description = getDescription(aReporters, path);
|
2011-06-16 11:34:09 -07:00
|
|
|
var amount = getBytes(aReporters, path);
|
|
|
|
if (amount !== kUnknown) {
|
2011-07-25 18:51:38 -07:00
|
|
|
// Non-leaf node with its own reporter. Use the reporter and add
|
|
|
|
// an "other" child node.
|
2011-06-16 11:34:09 -07:00
|
|
|
aT._amount = amount;
|
2011-07-25 18:51:38 -07:00
|
|
|
var other = {
|
|
|
|
_name: "other",
|
|
|
|
_kind: KIND_OTHER,
|
|
|
|
_description: "All unclassified " + aT._name + " memory.",
|
|
|
|
_amount: aT._amount - childrenBytes,
|
|
|
|
_kids: []
|
|
|
|
};
|
|
|
|
aT._kids.push(other);
|
2011-05-22 19:49:56 -07:00
|
|
|
} else {
|
2011-07-25 18:51:38 -07:00
|
|
|
// Non-leaf node with a reporter that returns kUnknown.
|
|
|
|
// Use the sum of the children and mark it as problematic.
|
|
|
|
aT._amount = childrenBytes;
|
2011-05-22 19:49:56 -07:00
|
|
|
aT._hasProblem = true;
|
|
|
|
}
|
2011-05-03 17:12:58 -07:00
|
|
|
} else {
|
2011-07-25 18:51:38 -07:00
|
|
|
// Non-leaf node without its own reporter. Derive its size and
|
|
|
|
// description entirely from its children.
|
|
|
|
aT._amount = childrenBytes;
|
|
|
|
aT._description = "The sum of all entries below '" + aT._name + "'.";
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
return aT._amount;
|
|
|
|
}
|
|
|
|
fillInTree(t, "");
|
|
|
|
|
|
|
|
// Determine how many bytes are reported by heap reporters. Be careful
|
|
|
|
// with non-leaf reporters; if we count a non-leaf reporter we don't want
|
|
|
|
// to count any of its child reporters.
|
|
|
|
var s = "";
|
|
|
|
function getKnownHeapUsedBytes(aT)
|
|
|
|
{
|
|
|
|
if (aT._kind === KIND_HEAP) {
|
|
|
|
return aT._amount;
|
|
|
|
} else {
|
|
|
|
var n = 0;
|
|
|
|
for (var i = 0; i < aT._kids.length; i++) {
|
|
|
|
n += getKnownHeapUsedBytes(aT._kids[i]);
|
2011-05-22 19:49:56 -07:00
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
return n;
|
2011-05-22 19:49:56 -07:00
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
}
|
2011-05-22 19:49:56 -07:00
|
|
|
|
2011-07-25 18:51:38 -07:00
|
|
|
// A special case: compute the derived "heap-unclassified" value. Don't
|
|
|
|
// mark "heap-allocated" when we get its size because we want it to appear
|
|
|
|
// in the "Other Measurements" list.
|
|
|
|
var heapUsedBytes = getBytes(aReporters, "heap-allocated", true);
|
|
|
|
var unknownHeapUsedBytes = 0;
|
|
|
|
var hasProblem = true;
|
|
|
|
if (heapUsedBytes !== kUnknown) {
|
|
|
|
unknownHeapUsedBytes = heapUsedBytes - getKnownHeapUsedBytes(t);
|
|
|
|
hasProblem = false;
|
|
|
|
}
|
|
|
|
var heapUnclassified = {
|
|
|
|
_name: "heap-unclassified",
|
|
|
|
_kind: KIND_HEAP,
|
|
|
|
_description:
|
|
|
|
"Memory not classified by a more specific reporter. This includes " +
|
|
|
|
"waste due to internal fragmentation in the heap allocator (caused " +
|
|
|
|
"when the allocator rounds up request sizes).",
|
|
|
|
_amount: unknownHeapUsedBytes,
|
|
|
|
_hasProblem: hasProblem,
|
|
|
|
_kids: []
|
|
|
|
}
|
|
|
|
t._kids.push(heapUnclassified);
|
|
|
|
t._amount += unknownHeapUsedBytes;
|
2010-02-20 13:23:25 -08:00
|
|
|
|
2011-07-25 18:51:38 -07:00
|
|
|
return t;
|
|
|
|
}
|
2011-05-03 17:12:58 -07:00
|
|
|
|
2011-07-25 18:51:38 -07:00
|
|
|
/**
|
|
|
|
* Sort all kid nodes from largest to smallest and aggregate
|
|
|
|
* insignificant nodes.
|
|
|
|
*
|
|
|
|
* @param aTotalBytes
|
|
|
|
* The size of the tree's root node
|
|
|
|
* @param aT
|
|
|
|
* The tree
|
|
|
|
*/
|
|
|
|
function filterTree(aTotalBytes, aT)
|
|
|
|
{
|
|
|
|
const omitThresholdPerc = 0.5; /* percent */
|
|
|
|
|
|
|
|
function shouldOmit(aBytes)
|
|
|
|
{
|
|
|
|
return !gVerbose &&
|
|
|
|
aTotalBytes !== kUnknown &&
|
|
|
|
(100 * aBytes / aTotalBytes) < omitThresholdPerc;
|
|
|
|
}
|
|
|
|
|
|
|
|
aT._kids.sort(cmpExplicitReporters);
|
|
|
|
|
|
|
|
for (var i = 0; i < aT._kids.length; i++) {
|
|
|
|
if (shouldOmit(aT._kids[i]._amount)) {
|
|
|
|
// This sub-tree is below the significance threshold
|
|
|
|
// Remove it and all remaining (smaller) sub-trees, and
|
|
|
|
// replace them with a single aggregate node.
|
|
|
|
var i0 = i;
|
|
|
|
var aggBytes = 0;
|
|
|
|
for ( ; i < aT._kids.length; i++) {
|
|
|
|
aggBytes += aT._kids[i]._amount;
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
aT._kids.splice(i0);
|
|
|
|
var n = i - i0;
|
|
|
|
var rSub = {
|
|
|
|
_name: "(" + n + " omitted)",
|
|
|
|
_kind: KIND_OTHER,
|
|
|
|
_amount: aggBytes,
|
|
|
|
_description: n + " sub-trees that were below the " +
|
|
|
|
omitThresholdPerc + "% significance threshold. " +
|
|
|
|
"Click 'More verbose' at the bottom of this page " +
|
|
|
|
"to see them.",
|
|
|
|
_kids: []
|
|
|
|
};
|
|
|
|
// Add the "omitted" sub-tree at the end and then resort, because the
|
|
|
|
// sum of the omitted sub-trees may be larger than some of the
|
|
|
|
// shown sub-trees.
|
|
|
|
aT._kids[i0] = rSub;
|
|
|
|
aT._kids.sort(cmpExplicitReporters);
|
|
|
|
break;
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
filterTree(aTotalBytes, aT._kids[i]);
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
2011-07-25 18:51:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the text for a single process.
|
|
|
|
*
|
|
|
|
* @param aProcess
|
|
|
|
* The name of the process
|
|
|
|
* @param aReporters
|
|
|
|
* Table of reporters for this process, indexed by _path
|
|
|
|
* @return The generated text
|
|
|
|
*/
|
|
|
|
function genProcessText(aProcess, aReporters)
|
|
|
|
{
|
|
|
|
var tree = buildTree(aReporters);
|
|
|
|
filterTree(tree._amount, tree);
|
2011-05-03 17:12:58 -07:00
|
|
|
|
|
|
|
// Nb: the newlines give nice spacing if we cut+paste into a text buffer.
|
|
|
|
var text = "";
|
|
|
|
text += "<h1>" + aProcess + " Process</h1>\n\n";
|
2011-07-25 18:51:38 -07:00
|
|
|
text += genTreeText(tree);
|
2011-06-05 18:22:45 -07:00
|
|
|
text += genOtherText(aReporters);
|
2011-05-03 17:12:58 -07:00
|
|
|
text += "<hr></hr>";
|
|
|
|
return text;
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
|
|
|
|
2011-06-16 11:34:09 -07:00
|
|
|
/**
|
|
|
|
* Returns the reporter's amount formatted as a human-readable string (with
|
|
|
|
* units, if applicable).
|
|
|
|
*
|
|
|
|
* @param aReporter
|
|
|
|
* The reporter whose usage we're formatting
|
|
|
|
* @return The reporter's amount formatted as a human-readable string
|
|
|
|
*/
|
|
|
|
function formatReporterAmount(aReporter)
|
|
|
|
{
|
|
|
|
switch(aReporter._units) {
|
2011-07-24 20:56:50 -07:00
|
|
|
case UNITS_BYTES:
|
|
|
|
return formatBytes(aReporter._amount);
|
|
|
|
case UNITS_COUNT:
|
|
|
|
case UNITS_COUNT_CUMULATIVE:
|
|
|
|
return formatInt(aReporter._amount);
|
|
|
|
case UNITS_PERCENTAGE:
|
|
|
|
return formatPercentage(aReporter._amount);
|
|
|
|
default: return "(???)"
|
2011-06-16 11:34:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats an int as a human-readable string.
|
|
|
|
*
|
|
|
|
* @param aN
|
|
|
|
* The integer to format
|
|
|
|
* @return A human-readable string representing the int
|
|
|
|
*/
|
|
|
|
function formatInt(aN)
|
|
|
|
{
|
|
|
|
var neg = false;
|
|
|
|
if (aN < 0) {
|
|
|
|
neg = true;
|
|
|
|
aN = -aN;
|
|
|
|
}
|
|
|
|
var s = "";
|
|
|
|
while (true) {
|
|
|
|
var k = aN % 1000;
|
|
|
|
aN = Math.floor(aN / 1000);
|
|
|
|
if (aN > 0) {
|
|
|
|
if (k < 10) {
|
|
|
|
s = ",00" + k + s;
|
|
|
|
} else if (k < 100) {
|
|
|
|
s = ",0" + k + s;
|
|
|
|
} else {
|
|
|
|
s = "," + k + s;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s = k + s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return neg ? "-" + s : s;
|
|
|
|
}
|
|
|
|
|
2011-03-31 10:19:30 -07:00
|
|
|
/**
|
2011-05-03 17:12:58 -07:00
|
|
|
* Converts a byte count to an appropriate string representation.
|
|
|
|
*
|
|
|
|
* @param aBytes
|
|
|
|
* The byte count
|
|
|
|
* @return The string representation
|
2011-03-31 10:19:30 -07:00
|
|
|
*/
|
2011-05-03 17:12:58 -07:00
|
|
|
function formatBytes(aBytes)
|
2010-02-20 13:23:25 -08:00
|
|
|
{
|
2011-05-03 17:12:58 -07:00
|
|
|
var unit = gVerbose ? "B" : "MB";
|
2011-02-16 10:43:23 -08:00
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
var s;
|
|
|
|
if (gVerbose) {
|
|
|
|
s = formatInt(aBytes) + " " + unit;
|
|
|
|
} else {
|
|
|
|
var mbytes = (aBytes / (1024 * 1024)).toFixed(2);
|
|
|
|
var a = String(mbytes).split(".");
|
|
|
|
s = formatInt(a[0]) + "." + a[1] + " " + unit;
|
|
|
|
}
|
|
|
|
return s;
|
2011-02-16 10:43:23 -08:00
|
|
|
}
|
|
|
|
|
2011-07-20 21:08:24 -07:00
|
|
|
/**
|
|
|
|
* Converts a percentage to an appropriate string representation.
|
|
|
|
*
|
|
|
|
* @param aPerc100x
|
|
|
|
* The percentage, multiplied by 100 (see nsIMemoryReporter)
|
|
|
|
* @return The string representation
|
|
|
|
*/
|
|
|
|
function formatPercentage(aPerc100x)
|
|
|
|
{
|
|
|
|
return (aPerc100x / 100).toFixed(2) + "%";
|
|
|
|
}
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
/**
|
|
|
|
* Right-justifies a string in a field of a given width, padding as necessary
|
|
|
|
*
|
|
|
|
* @param aS
|
|
|
|
* The string
|
|
|
|
* @param aN
|
|
|
|
* The field width
|
|
|
|
* @param aC
|
|
|
|
* The char used to pad
|
|
|
|
* @return The string representation
|
|
|
|
*/
|
|
|
|
function pad(aS, aN, aC)
|
|
|
|
{
|
|
|
|
var padding = "";
|
|
|
|
var n2 = aN - aS.length;
|
|
|
|
for (var i = 0; i < n2; i++) {
|
|
|
|
padding += aC;
|
|
|
|
}
|
|
|
|
return padding + aS;
|
2011-02-16 10:43:23 -08:00
|
|
|
}
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
/**
|
2011-05-22 19:49:56 -07:00
|
|
|
* Gets the byte count for a particular memory reporter and sets its _done
|
|
|
|
* property.
|
2011-05-03 17:12:58 -07:00
|
|
|
*
|
2011-06-05 18:22:45 -07:00
|
|
|
* @param aReporters
|
|
|
|
* Table of reporters for this process, indexed by _path
|
|
|
|
* @param aPath
|
|
|
|
* The path of the memory reporter
|
2011-05-22 19:49:56 -07:00
|
|
|
* @param aDoNotMark
|
|
|
|
* If set, the _done property is not set.
|
2011-05-03 17:12:58 -07:00
|
|
|
* @return The byte count
|
|
|
|
*/
|
2011-06-05 18:22:45 -07:00
|
|
|
function getBytes(aReporters, aPath, aDoNotMark)
|
2011-05-03 17:12:58 -07:00
|
|
|
{
|
2011-06-05 18:22:45 -07:00
|
|
|
var r = aReporters[aPath];
|
|
|
|
if (r) {
|
2011-06-16 11:34:09 -07:00
|
|
|
var bytes = r._amount;
|
2011-05-22 19:49:56 -07:00
|
|
|
if (!aDoNotMark) {
|
2011-06-05 18:22:45 -07:00
|
|
|
r._done = true;
|
2011-05-22 19:49:56 -07:00
|
|
|
}
|
2011-05-03 17:12:58 -07:00
|
|
|
return bytes;
|
|
|
|
}
|
2011-06-05 18:22:45 -07:00
|
|
|
// Nb: this should never occur; all paths have been extracted from
|
|
|
|
// the original list of reporters and so the lookup should succeed. Return
|
|
|
|
// an obviously wrong number that will likely be noticed.
|
2011-05-03 17:12:58 -07:00
|
|
|
return -2 * 1024 * 1024;
|
|
|
|
}
|
2010-02-20 13:23:25 -08:00
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
/**
|
|
|
|
* Gets the description for a particular memory reporter.
|
|
|
|
*
|
2011-06-05 18:22:45 -07:00
|
|
|
* @param aReporters
|
|
|
|
* Table of reporters for this process, indexed by _path
|
|
|
|
* @param aPath
|
|
|
|
* The path of the memory reporter
|
2011-05-03 17:12:58 -07:00
|
|
|
* @return The description
|
|
|
|
*/
|
2011-06-05 18:22:45 -07:00
|
|
|
function getDescription(aReporters, aPath)
|
2011-02-16 10:43:23 -08:00
|
|
|
{
|
2011-06-05 18:22:45 -07:00
|
|
|
var r = aReporters[aPath];
|
2011-05-03 17:12:58 -07:00
|
|
|
return r ? r._description : "???";
|
|
|
|
}
|
2011-02-16 10:43:23 -08:00
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
function genMrValueText(aValue)
|
|
|
|
{
|
|
|
|
return "<span class='mrValue'>" + aValue + "</span>";
|
|
|
|
}
|
2011-02-16 10:43:23 -08:00
|
|
|
|
2011-05-22 19:49:56 -07:00
|
|
|
function kindToString(aKind)
|
2011-05-03 17:12:58 -07:00
|
|
|
{
|
2011-05-22 19:49:56 -07:00
|
|
|
switch (aKind) {
|
2011-07-19 07:33:49 -07:00
|
|
|
case KIND_NONHEAP: return "(Non-heap) ";
|
|
|
|
case KIND_HEAP: return "(Heap) ";
|
|
|
|
case KIND_OTHER: return "";
|
|
|
|
default: return "(???) ";
|
2011-05-22 19:49:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function escapeQuotes(aStr)
|
|
|
|
{
|
2011-06-29 22:44:17 -07:00
|
|
|
return aStr.replace(/\&/g, '&').replace(/'/g, ''');
|
|
|
|
}
|
|
|
|
|
|
|
|
// For user-controlled strings.
|
|
|
|
function escapeAll(aStr)
|
|
|
|
{
|
|
|
|
return aStr.replace(/\&/g, '&').replace(/'/g, ''').
|
|
|
|
replace(/\</g, '<').replace(/>/g, '>').
|
|
|
|
replace(/\"/g, '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compartment reporter names are URLs and so can include forward slashes. But
|
|
|
|
// forward slash is the memory reporter path separator. So the memory
|
|
|
|
// reporters change them to backslashes. Undo that here.
|
|
|
|
function flipBackslashes(aStr)
|
|
|
|
{
|
|
|
|
return aStr.replace(/\\/g, '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate the URL in a compartment name if not in verbose mode.
|
|
|
|
function truncateCompartmentName(aStr)
|
|
|
|
{
|
|
|
|
return (gVerbose)
|
|
|
|
? aStr
|
|
|
|
: aStr.replace(/compartment\((.{40}).*\)/, 'compartment($1...)');
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepName(aStr)
|
|
|
|
{
|
|
|
|
return escapeAll(flipBackslashes(truncateCompartmentName(aStr)));
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepDesc(aStr)
|
|
|
|
{
|
|
|
|
return escapeQuotes(flipBackslashes(aStr));
|
2011-05-22 19:49:56 -07:00
|
|
|
}
|
|
|
|
|
2011-07-19 16:59:17 -07:00
|
|
|
function genMrNameText(aKind, aDesc, aName, aHasProblem, aNMerged)
|
2011-05-22 19:49:56 -07:00
|
|
|
{
|
2011-05-22 19:49:59 -07:00
|
|
|
var text = "-- <span class='mrName hasDesc' title='" +
|
2011-06-29 22:44:17 -07:00
|
|
|
kindToString(aKind) + prepDesc(aDesc) +
|
|
|
|
"'>" + prepName(aName) + "</span>";
|
2011-07-19 16:59:17 -07:00
|
|
|
if (aHasProblem) {
|
|
|
|
const problemDesc =
|
|
|
|
"Warning: this memory reporter was unable to compute a useful value. " +
|
|
|
|
"The reported value is the sum of all entries below '" + aName + "', " +
|
|
|
|
"which is probably less than the true value.";
|
|
|
|
text += " <span class='mrStar' title=\"" + problemDesc + "\">[*]</span>";
|
|
|
|
}
|
|
|
|
if (aNMerged) {
|
|
|
|
const dupDesc = "This value is the sum of " + aNMerged +
|
|
|
|
" memory reporters that all have the same path.";
|
|
|
|
text += " <span class='mrStar' title=\"" + dupDesc + "\">[" +
|
|
|
|
aNMerged + "]</span>";
|
|
|
|
}
|
|
|
|
return text + '\n';
|
2010-02-20 13:23:25 -08:00
|
|
|
}
|
|
|
|
|
2011-05-03 17:12:58 -07:00
|
|
|
/**
|
2011-05-22 19:49:56 -07:00
|
|
|
* Generates the text for the tree, including its heading.
|
2011-05-03 17:12:58 -07:00
|
|
|
*
|
|
|
|
* @param aT
|
|
|
|
* The tree
|
|
|
|
* @return The generated text
|
|
|
|
*/
|
2011-05-22 19:49:56 -07:00
|
|
|
function genTreeText(aT)
|
2011-02-16 10:43:23 -08:00
|
|
|
{
|
2011-06-16 11:34:09 -07:00
|
|
|
var treeBytes = aT._amount;
|
2011-05-03 17:12:58 -07:00
|
|
|
var treeBytesLength = formatBytes(treeBytes).length;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the text for a particular tree, without a heading.
|
|
|
|
*
|
|
|
|
* @param aT
|
|
|
|
* The tree
|
|
|
|
* @param aIndentGuide
|
|
|
|
* Records what indentation is required for this tree. It has one
|
|
|
|
* entry per level of indentation. For each entry, ._isLastKid
|
|
|
|
* records whether the node in question is the last child, and
|
|
|
|
* ._depth records how many chars of indentation are required.
|
|
|
|
* @param aParentBytesLength
|
|
|
|
* The length of the formatted byte count of the top node in the tree
|
|
|
|
* @return The generated text
|
|
|
|
*/
|
|
|
|
function genTreeText2(aT, aIndentGuide, aParentBytesLength)
|
|
|
|
{
|
|
|
|
function repeatStr(aC, aN)
|
|
|
|
{
|
|
|
|
var s = "";
|
|
|
|
for (var i = 0; i < aN; i++) {
|
|
|
|
s += aC;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the indent. There's a subset of the Unicode "light"
|
|
|
|
// box-drawing chars that are widely implemented in terminals, and
|
|
|
|
// this code sticks to that subset to maximize the chance that
|
|
|
|
// cutting and pasting about:memory output to a terminal will work
|
|
|
|
// correctly:
|
|
|
|
const kHorizontal = "\u2500",
|
|
|
|
kVertical = "\u2502",
|
|
|
|
kUpAndRight = "\u2514",
|
|
|
|
kVerticalAndRight = "\u251c";
|
|
|
|
var indent = "<span class='treeLine'>";
|
|
|
|
if (aIndentGuide.length > 0) {
|
|
|
|
for (var i = 0; i < aIndentGuide.length - 1; i++) {
|
|
|
|
indent += aIndentGuide[i]._isLastKid ? " " : kVertical;
|
|
|
|
indent += repeatStr(" ", aIndentGuide[i]._depth - 1);
|
|
|
|
}
|
|
|
|
indent += aIndentGuide[i]._isLastKid ? kUpAndRight : kVerticalAndRight;
|
|
|
|
indent += repeatStr(kHorizontal, aIndentGuide[i]._depth - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indent more if this entry is narrower than its parent, and update
|
|
|
|
// aIndentGuide accordingly.
|
2011-06-16 11:34:09 -07:00
|
|
|
var tMemoryUsedStr = formatBytes(aT._amount);
|
2011-05-03 17:12:58 -07:00
|
|
|
var tBytesLength = tMemoryUsedStr.length;
|
|
|
|
var extraIndentLength = Math.max(aParentBytesLength - tBytesLength, 0);
|
|
|
|
if (extraIndentLength > 0) {
|
|
|
|
for (var i = 0; i < extraIndentLength; i++) {
|
|
|
|
indent += kHorizontal;
|
|
|
|
}
|
|
|
|
aIndentGuide[aIndentGuide.length - 1]._depth += extraIndentLength;
|
|
|
|
}
|
|
|
|
indent += "</span>";
|
|
|
|
|
|
|
|
// Generate the percentage.
|
|
|
|
var perc = "";
|
2011-06-16 11:34:09 -07:00
|
|
|
if (aT._amount === treeBytes) {
|
2011-05-22 19:49:56 -07:00
|
|
|
perc = "100.0";
|
|
|
|
} else {
|
2011-06-16 11:34:09 -07:00
|
|
|
perc = (100 * aT._amount / treeBytes).toFixed(2);
|
2011-05-22 19:49:56 -07:00
|
|
|
perc = pad(perc, 5, '0');
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
2011-05-22 19:49:56 -07:00
|
|
|
perc = "<span class='mrPerc'>(" + perc + "%)</span> ";
|
2011-05-03 17:12:58 -07:00
|
|
|
|
|
|
|
var text = indent + genMrValueText(tMemoryUsedStr) + " " + perc +
|
2011-05-22 19:49:56 -07:00
|
|
|
genMrNameText(aT._kind, aT._description, aT._name,
|
2011-07-19 16:59:17 -07:00
|
|
|
aT._hasProblem, aT._nMerged);
|
2011-05-03 17:12:58 -07:00
|
|
|
|
|
|
|
for (var i = 0; i < aT._kids.length; i++) {
|
|
|
|
// 3 is the standard depth, the callee adjusts it if necessary.
|
2011-05-11 16:09:50 -07:00
|
|
|
aIndentGuide.push({ _isLastKid: (i === aT._kids.length - 1), _depth: 3 });
|
2011-05-03 17:12:58 -07:00
|
|
|
text += genTreeText2(aT._kids[i], aIndentGuide, tBytesLength);
|
|
|
|
aIndentGuide.pop();
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
var text = genTreeText2(aT, [], treeBytesLength);
|
|
|
|
// Nb: the newlines give nice spacing if we cut+paste into a text buffer.
|
2011-05-22 19:49:56 -07:00
|
|
|
const desc =
|
|
|
|
"This tree covers explicit memory allocations by the application, " +
|
|
|
|
"both at the operating system level (via calls to functions such as " +
|
|
|
|
"VirtualAlloc, vm_allocate, and mmap), and at the heap allocation level " +
|
|
|
|
"(via functions such as malloc, calloc, realloc, memalign, operator " +
|
|
|
|
"new, and operator new[]). It excludes memory that is mapped implicitly " +
|
|
|
|
"such as code and data segments, and thread stacks. It also excludes " +
|
|
|
|
"heap memory that has been freed by the application but is still being " +
|
|
|
|
"held onto by the heap allocator. It is not guaranteed to cover every " +
|
|
|
|
"explicit allocation, but it does cover most (including the entire " +
|
|
|
|
"heap), and therefore it is the single best number to focus on when " +
|
|
|
|
"trying to reduce memory usage.";
|
|
|
|
|
2011-05-22 19:49:59 -07:00
|
|
|
return "<h2 class='hasDesc' title='" + escapeQuotes(desc) +
|
2011-05-22 19:49:56 -07:00
|
|
|
"'>Explicit Allocations</h2>\n" + "<pre>" + text + "</pre>\n";
|
2011-02-16 10:43:23 -08:00
|
|
|
}
|
2011-05-03 17:12:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the text for the "Other Measurements" section.
|
|
|
|
*
|
2011-06-05 18:22:45 -07:00
|
|
|
* @param aReporters
|
|
|
|
* Table of reporters for this process, indexed by _path
|
2011-05-03 17:12:58 -07:00
|
|
|
* @return The generated text
|
|
|
|
*/
|
2011-06-05 18:22:45 -07:00
|
|
|
function genOtherText(aReporters)
|
2011-05-03 17:12:58 -07:00
|
|
|
{
|
2011-06-05 18:22:45 -07:00
|
|
|
// Generate an array of Reporter-like elements, stripping out all the
|
|
|
|
// reporters that have already been handled. Also find the width of the
|
|
|
|
// widest element, so we can format things nicely.
|
2011-06-16 11:34:09 -07:00
|
|
|
var maxAmountLength = 0;
|
2011-06-05 18:22:45 -07:00
|
|
|
var rArray = [];
|
|
|
|
for (var path in aReporters) {
|
|
|
|
var r = aReporters[path];
|
|
|
|
if (!r._done) {
|
2011-05-22 19:49:56 -07:00
|
|
|
var hasProblem = false;
|
2011-06-16 11:34:09 -07:00
|
|
|
if (r._amount === kUnknown) {
|
2011-05-22 19:49:56 -07:00
|
|
|
hasProblem = true;
|
|
|
|
}
|
|
|
|
var elem = {
|
2011-06-05 18:22:45 -07:00
|
|
|
_path: r._path,
|
|
|
|
_kind: r._kind,
|
2011-06-16 11:34:09 -07:00
|
|
|
_units: r._units,
|
2011-06-29 22:44:17 -07:00
|
|
|
_amount: hasProblem ? 0 : r._amount,
|
2011-06-05 18:22:45 -07:00
|
|
|
_description: r._description,
|
2011-07-19 16:59:17 -07:00
|
|
|
_hasProblem: hasProblem,
|
|
|
|
_nMerged: r._nMerged
|
2011-05-22 19:49:56 -07:00
|
|
|
};
|
2011-06-05 18:22:45 -07:00
|
|
|
rArray.push(elem);
|
2011-06-16 11:34:09 -07:00
|
|
|
var thisAmountLength = formatReporterAmount(elem).length;
|
|
|
|
if (thisAmountLength > maxAmountLength) {
|
|
|
|
maxAmountLength = thisAmountLength;
|
2011-05-22 19:49:56 -07:00
|
|
|
}
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
}
|
2011-07-20 21:08:24 -07:00
|
|
|
rArray.sort(cmpOtherReporters);
|
2011-05-03 17:12:58 -07:00
|
|
|
|
2011-05-22 19:49:56 -07:00
|
|
|
// Generate text for the not-yet-printed values.
|
2011-05-03 17:12:58 -07:00
|
|
|
var text = "";
|
2011-06-05 18:22:45 -07:00
|
|
|
for (var i = 0; i < rArray.length; i++) {
|
|
|
|
var elem = rArray[i];
|
2011-07-20 21:08:24 -07:00
|
|
|
assert(elem._kind === KIND_OTHER,
|
|
|
|
"elem._kind is not KIND_OTHER for " + elem._path);
|
2011-05-22 19:49:56 -07:00
|
|
|
text += genMrValueText(
|
2011-06-16 11:34:09 -07:00
|
|
|
pad(formatReporterAmount(elem), maxAmountLength, ' ')) + " ";
|
2011-06-05 18:22:45 -07:00
|
|
|
text += genMrNameText(elem._kind, elem._description, elem._path,
|
2011-07-19 16:59:17 -07:00
|
|
|
elem._hasProblem, elem._nMerged);
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Nb: the newlines give nice spacing if we cut+paste into a text buffer.
|
2011-05-22 19:49:56 -07:00
|
|
|
const desc = "This list contains other memory measurements that cross-cut " +
|
|
|
|
"the requested memory measurements above."
|
2011-05-22 19:49:59 -07:00
|
|
|
return "<h2 class='hasDesc' title='" + desc + "'>Other Measurements</h2>\n" +
|
2011-05-22 19:49:56 -07:00
|
|
|
"<pre>" + text + "</pre>\n";
|
2011-05-03 17:12:58 -07:00
|
|
|
}
|
|
|
|
|
2011-07-20 21:08:24 -07:00
|
|
|
function assert(aCond, aMsg)
|
|
|
|
{
|
|
|
|
if (!aCond) {
|
|
|
|
throw("assertion failed: " + aMsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:22:45 -07:00
|
|
|
function debug(x)
|
|
|
|
{
|
|
|
|
var content = $("content");
|
|
|
|
var div = document.createElement("div");
|
|
|
|
div.innerHTML = JSON.stringify(x);
|
|
|
|
content.appendChild(div);
|
|
|
|
}
|
|
|
|
|