--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -49,17 +49,17 @@ let gAddedObserver = false;
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;
const UNITS_PERCENTAGE = Ci.nsIMemoryReporter.UNITS_PERCENTAGE;
-const kUnknown = -1; // used for _amount if a memory reporter failed
+const kUnknown = -1; // used for an unknown _amount
// Forward slashes in URLs in paths are represented with backslashes to avoid
// being mistaken for path separators. Paths/names/descriptions where this
// hasn't been undone are prefixed with "unsafe"; the rest are prefixed with
// "safe".
function makeSafe(aUnsafeStr)
{
return aUnsafeStr.replace(/\\/g, '/');
@@ -200,30 +200,30 @@ function sendHeapMinNotifications()
else
runSoon(update);
}
let j = 0;
sendHeapMinNotificationsInner();
}
-function Reporter(aUnsafePath, aKind, aUnits, aAmount, aUnsafeDesc)
+function Report(aUnsafePath, aKind, aUnits, aAmount, aUnsafeDesc)
{
this._unsafePath = aUnsafePath;
this._kind = aKind;
this._units = aUnits;
this._amount = aAmount;
this._unsafeDescription = aUnsafeDesc;
// this._nMerged is only defined if > 1
- // this._done is defined and set to true when the reporter's amount is read
+ // this._done is defined and set to true when the Report's amount is read
}
-Reporter.prototype = {
+Report.prototype = {
// Sum the values (accounting for possible kUnknown amounts), and mark |this|
- // as a dup. We mark dups because it's useful to know when a reporter is
+ // as a dup. We mark dups because it's useful to know when a report is
// duplicated; it might be worth investigating and splitting up to have
// non-duplicated names.
merge: function(r) {
if (this._amount !== kUnknown && r._amount !== kUnknown) {
this._amount += r._amount;
} else if (this._amount === kUnknown && r._amount !== kUnknown) {
this._amount = r._amount;
}
@@ -233,79 +233,79 @@ Reporter.prototype = {
treeNameMatches: function(aTreeName) {
// Nb: the '/' must be present, because we have a KIND_OTHER reporter
// called "explicit" which is not part of the "explicit" tree.
return this._unsafePath.indexOf(aTreeName) === 0 &&
this._unsafePath.charAt(aTreeName.length) === '/';
}
};
-function getReportersByProcess(aMgr)
+function getReportsByProcess(aMgr)
{
// Process each memory reporter:
- // - Make a copy of it into a sub-table indexed by its process. Each copy
- // is a Reporter object. After this point we never use the original memory
- // reporter again.
+ // - Put a copy of its report(s) into a sub-table indexed by its process.
+ // Each copy is a Report object. After this point we never use the
+ // original memory reporter again.
//
// - Note that copying rOrig.amount (which calls a C++ function under the
- // IDL covers) to r._amount for every reporter now means that the
+ // IDL covers) to r._amount for every report now means that the
// results as consistent as possible -- measurements are made all at
// once before most of the memory required to generate this page is
// allocated.
- let reportersByProcess = {};
+ let reportsByProcess = {};
- function addReporter(aProcess, aUnsafePath, aKind, aUnits, aAmount,
- aUnsafeDesc)
+ function handleReport(aProcess, aUnsafePath, aKind, aUnits, aAmount,
+ aUnsafeDesc)
{
let process = aProcess === "" ? "Main" : aProcess;
- let r = new Reporter(aUnsafePath, aKind, aUnits, aAmount, aUnsafeDesc);
- if (!reportersByProcess[process]) {
- reportersByProcess[process] = {};
+ let r = new Report(aUnsafePath, aKind, aUnits, aAmount, aUnsafeDesc);
+ if (!reportsByProcess[process]) {
+ reportsByProcess[process] = {};
}
- let reporters = reportersByProcess[process];
- let reporter = reporters[r._unsafePath];
- if (reporter) {
- // Already an entry; must be a duplicated reporter. This can happen
+ let reports = reportsByProcess[process];
+ let rOld = reports[r._unsafePath];
+ if (rOld) {
+ // Already an entry; must be a duplicated report. This can happen
// legitimately. Merge them.
- reporter.merge(r);
+ rOld.merge(r);
} else {
- reporters[r._unsafePath] = r;
+ reports[r._unsafePath] = r;
}
}
// Process vanilla reporters first, then multi-reporters.
let e = aMgr.enumerateReporters();
while (e.hasMoreElements()) {
let rOrig = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
try {
- addReporter(rOrig.process, rOrig.path, rOrig.kind, rOrig.units,
- rOrig.amount, rOrig.description);
+ handleReport(rOrig.process, rOrig.path, rOrig.kind, rOrig.units,
+ rOrig.amount, rOrig.description);
}
catch(e) {
debug("An error occurred when collecting results from the memory reporter " +
rOrig.path + ": " + e);
}
}
let e = aMgr.enumerateMultiReporters();
while (e.hasMoreElements()) {
let mrOrig = e.getNext().QueryInterface(Ci.nsIMemoryMultiReporter);
- // Ignore the "smaps" reporters in non-verbose mode.
+ // Ignore the "smaps" reports in non-verbose mode.
if (!gVerbose && mrOrig.name === "smaps") {
continue;
}
try {
- mrOrig.collectReports(addReporter, null);
+ mrOrig.collectReports(handleReport, null);
}
catch(e) {
debug("An error occurred when collecting a multi-reporter's results: " + e);
}
}
- return reportersByProcess;
+ return reportsByProcess;
}
function appendTextNode(aP, aText)
{
let e = document.createTextNode(aText);
aP.appendChild(e);
return e;
}
@@ -339,23 +339,23 @@ function update()
oldContent.parentNode.replaceChild(content, oldContent);
content.classList.add(gVerbose ? 'verbose' : 'non-verbose');
let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
getService(Ci.nsIMemoryReporterManager);
// Generate output for one process at a time. Always start with the
// Main process.
- let reportersByProcess = getReportersByProcess(mgr);
+ let reportsByProcess = getReportsByProcess(mgr);
let hasMozMallocUsableSize = mgr.hasMozMallocUsableSize;
- appendProcessElements(content, "Main", reportersByProcess["Main"],
+ appendProcessElements(content, "Main", reportsByProcess["Main"],
hasMozMallocUsableSize);
- for (let process in reportersByProcess) {
+ for (let process in reportsByProcess) {
if (process !== "Main") {
- appendProcessElements(content, process, reportersByProcess[process],
+ appendProcessElements(content, process, reportsByProcess[process],
hasMozMallocUsableSize);
}
}
appendElement(content, "hr");
// Memory-related actions.
const UpDesc = "Re-measure.";
@@ -394,25 +394,25 @@ function update()
let div2 = appendElement(content, "div");
let a = appendElementWithText(div2, "a", "option",
"Troubleshooting information");
a.href = "about:support";
let legendText1 = "Click on a non-leaf node in a tree to expand ('++') " +
"or collapse ('--') its children.";
- let legendText2 = "Hover the pointer over the name of a memory reporter " +
+ let legendText2 = "Hover the pointer over the name of a memory report " +
"to see a description of what it measures.";
appendElementWithText(content, "div", "legend", legendText1);
appendElementWithText(content, "div", "legend", legendText2);
}
// There are two kinds of TreeNode.
-// - Leaf TreeNodes correspond to Reporters and have more properties.
+// - Leaf TreeNodes correspond to Reports and have more properties.
// - Non-leaf TreeNodes are just scaffolding nodes for the tree; their values
// are derived from their children.
function TreeNode(aUnsafeName)
{
// Nb: _units is not needed, it's always UNITS_BYTES.
this._unsafeName = aUnsafeName;
this._kids = [];
// Leaf TreeNodes have these properties added immediately after construction:
@@ -443,68 +443,68 @@ TreeNode.prototype = {
}
};
TreeNode.compare = function(a, b) {
return b._amount - a._amount;
};
/**
- * From a list of memory reporters, builds a tree that mirrors the tree
- * structure that will be shown as output.
+ * From a table of Reports, builds a tree that mirrors the tree structure that
+ * will be shown as output.
*
- * @param aReporters
- * The table of Reporters, indexed by _unsafePath.
+ * @param aReports
+ * The table of Reports, indexed by _unsafePath.
* @param aTreeName
* The name of the tree being built.
* @return The built tree.
*/
-function buildTree(aReporters, aTreeName)
+function buildTree(aReports, aTreeName)
{
- // We want to process all reporters that begin with |aTreeName|. First we
+ // We want to process all reports that begin with |aTreeName|. First we
// build the tree but only fill the properties that we can with a top-down
// traversal.
- // There should always be at least one matching reporter when |aTreeName| is
- // "explicit". But there may be zero for "smaps" trees; if that happens,
- // bail.
- let foundReporter = false;
- for (let unsafePath in aReporters) {
- if (aReporters[unsafePath].treeNameMatches(aTreeName)) {
- foundReporter = true;
+ // There should always be at least one matching Report object when
+ // |aTreeName| is "explicit". But there may be zero for "smaps" trees; if
+ // that happens, bail.
+ let foundReport = false;
+ for (let unsafePath in aReports) {
+ if (aReports[unsafePath].treeNameMatches(aTreeName)) {
+ foundReport = true;
break;
}
}
- if (!foundReporter) {
+ if (!foundReport) {
assert(aTreeName !== 'explicit');
return null;
}
let t = new TreeNode("falseRoot");
- for (let unsafePath in aReporters) {
+ for (let unsafePath in aReports) {
// Add any missing nodes in the tree implied by the unsafePath.
- let r = aReporters[unsafePath];
+ let r = aReports[unsafePath];
if (r.treeNameMatches(aTreeName)) {
assert(r._kind === KIND_HEAP || r._kind === KIND_NONHEAP,
- "reporters in the tree must have KIND_HEAP or KIND_NONHEAP");
+ "reports in the tree must have KIND_HEAP or KIND_NONHEAP");
assert(r._units === UNITS_BYTES, "r._units === UNITS_BYTES");
let unsafeNames = r._unsafePath.split('/');
let u = t;
for (let i = 0; i < unsafeNames.length; i++) {
let unsafeName = unsafeNames[i];
let uMatch = u.findKid(unsafeName);
if (uMatch) {
u = uMatch;
} else {
let v = new TreeNode(unsafeName);
u._kids.push(v);
u = v;
}
}
- // Fill in extra details in the leaf node from the Reporter.
+ // Fill in extra details in the leaf node from the Report object.
if (r._amount !== kUnknown) {
u._amount = r._amount;
} else {
u._amount = 0;
u._isUnknown = true;
}
u._unsafeDescription = r._unsafeDescription;
u._kind = r._kind;
@@ -559,41 +559,41 @@ function buildTree(aReporters, aTreeName
return t;
}
/**
* Ignore all the memory reports that belong to a "smaps" tree; this involves
* explicitly marking them as done.
*
- * @param aReporters
- * The table of Reporters, indexed by _unsafePath.
+ * @param aReports
+ * The table of Reports, indexed by _unsafePath.
*/
-function ignoreSmapsTrees(aReporters)
+function ignoreSmapsTrees(aReports)
{
- for (let unsafePath in aReporters) {
- let r = aReporters[unsafePath];
+ for (let unsafePath in aReports) {
+ let r = aReports[unsafePath];
if (r.treeNameMatches("smaps")) {
r._done = true;
}
}
}
/**
* Do some work which only makes sense for the 'explicit' tree.
*
* @param aT
* The tree.
- * @param aReporters
- * Table of Reporters for this process, indexed by _unsafePath.
+ * @param aReports
+ * Table of Reports for this process, indexed by _unsafePath.
* @return A boolean indicating if "heap-allocated" is known for the process.
*/
-function fixUpExplicitTree(aT, aReporters)
+function fixUpExplicitTree(aT, aReports)
{
- // Determine how many bytes are reported by heap reporters.
+ // Determine how many bytes are in heap reports.
function getKnownHeapUsedBytes(aT)
{
let n = 0;
if (aT._kids.length === 0) {
// Leaf node.
assert(aT._kind !== undefined, "aT._kind is undefined for leaf node");
n = aT._kind === KIND_HEAP ? aT._amount : 0;
} else {
@@ -602,31 +602,31 @@ function fixUpExplicitTree(aT, aReporter
}
}
return n;
}
// 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.
- let heapAllocatedReporter = aReporters["heap-allocated"];
- assert(heapAllocatedReporter, "no 'heap-allocated' reporter");
- let heapAllocatedBytes = heapAllocatedReporter._amount;
+ let heapAllocatedReport = aReports["heap-allocated"];
+ assert(heapAllocatedReport, "no 'heap-allocated' report");
+ let heapAllocatedBytes = heapAllocatedReport._amount;
let heapUnclassifiedT = new TreeNode("heap-unclassified");
let hasKnownHeapAllocated = heapAllocatedBytes !== kUnknown;
if (hasKnownHeapAllocated) {
heapUnclassifiedT._amount =
heapAllocatedBytes - getKnownHeapUsedBytes(aT);
} else {
heapUnclassifiedT._amount = 0;
heapUnclassifiedT._isUnknown = true;
}
// This kindToString() ensures the "(Heap)" prefix is set without having to
// set the _kind property, which would mean that there is a corresponding
- // Reporter for this TreeNode (which isn't true)
+ // Report object for this TreeNode object (which isn't true)
heapUnclassifiedT._unsafeDescription = kindToString(KIND_HEAP) +
"Memory not classified by a more specific reporter. This includes " +
"slop bytes due to internal fragmentation in the heap allocator " +
"(caused when the allocator rounds up request sizes).";
aT._kids.push(heapUnclassifiedT);
aT._amount += heapUnclassifiedT._amount;
@@ -705,17 +705,17 @@ function sortTreeAndInsertAggregateNodes
// The first n-1 children were significant. Don't consider if the last child
// is significant; there's no point creating an aggregate node that only has
// one child. Just process it.
sortTreeAndInsertAggregateNodes(aTotalBytes, aT._kids[i]);
}
// Global variable indicating if we've seen any invalid values for this
-// process; it holds the unsafePaths of any such reporters. It is reset for
+// process; it holds the unsafePaths of any such reports. It is reset for
// each new process.
let gUnsafePathsWithInvalidValuesForThisProcess = [];
function appendWarningElements(aP, aHasKnownHeapAllocated,
aHasMozMallocUsableSize)
{
if (!aHasKnownHeapAllocated && !aHasMozMallocUsableSize) {
appendElementWithText(aP, "p", "",
@@ -768,59 +768,58 @@ function appendWarningElements(aP, aHasK
/**
* Appends the elements for a single process.
*
* @param aP
* The parent DOM node.
* @param aProcess
* The name of the process.
- * @param aReporters
- * Table of Reporters for this process, indexed by _unsafePath.
+ * @param aReports
+ * Table of Reports for this process, indexed by _unsafePath.
* @param aHasMozMallocUsableSize
* Boolean indicating if moz_malloc_usable_size works.
* @return The generated text.
*/
-function appendProcessElements(aP, aProcess, aReporters,
- aHasMozMallocUsableSize)
+function appendProcessElements(aP, aProcess, aReports, aHasMozMallocUsableSize)
{
appendElementWithText(aP, "h1", "", aProcess + " Process");
appendTextNode(aP, "\n\n"); // gives nice spacing when we cut and paste
// We'll fill this in later.
let warningsDiv = appendElement(aP, "div", "accuracyWarning");
- let explicitTree = buildTree(aReporters, 'explicit');
- let hasKnownHeapAllocated = fixUpExplicitTree(explicitTree, aReporters);
+ let explicitTree = buildTree(aReports, 'explicit');
+ let hasKnownHeapAllocated = fixUpExplicitTree(explicitTree, aReports);
sortTreeAndInsertAggregateNodes(explicitTree._amount, explicitTree);
appendTreeElements(aP, explicitTree, aProcess);
// We only show these breakdown trees in verbose mode.
if (gVerbose) {
kMapTreePaths.forEach(function(t) {
- let tree = buildTree(aReporters, t);
+ let tree = buildTree(aReports, t);
- // |tree| will be null if we don't have any reporters for the given
+ // |tree| will be null if we don't have any reports for the given
// unsafePath.
if (tree) {
sortTreeAndInsertAggregateNodes(tree._amount, tree);
tree._hideKids = true; // smaps trees are always initially collapsed
appendTreeElements(aP, tree, aProcess);
}
});
} else {
- // Although we skip the "smaps" multi-reporter in getReportersByProcess(),
+ // Although we skip the "smaps" multi-reporter in getReportsByProcess(),
// we might get some smaps reports from a child process, and they must be
// explicitly ignored.
- ignoreSmapsTrees(aReporters);
+ ignoreSmapsTrees(aReports);
}
// We have to call appendOtherElements after we process all the trees,
- // because it looks at all the reporters which aren't part of a tree.
- appendOtherElements(aP, aReporters);
+ // because it looks at all the reports which aren't part of a tree.
+ appendOtherElements(aP, aReports);
// Add any warnings about inaccuracies due to platform limitations.
// These must be computed after generating all the text. The newlines give
// nice spacing if we cut+paste into a text buffer.
appendWarningElements(warningsDiv, hasKnownHeapAllocated,
aHasMozMallocUsableSize);
}
@@ -1233,105 +1232,105 @@ function appendTreeElements(aPOuter, aT,
appendSectionHeader(aPOuter, kTreeNames[aT._unsafeName]);
let pre = appendElement(aPOuter, "pre", "tree");
appendTreeElements2(pre, /* prePath = */"", aT, [], "", rootStringLength);
appendTextNode(aPOuter, "\n"); // gives nice spacing when we cut and paste
}
-function OtherReporter(aUnsafePath, aUnits, aAmount, aUnsafeDesc, aNMerged)
+function OtherReport(aUnsafePath, aUnits, aAmount, aUnsafeDesc, aNMerged)
{
// Nb: _kind is not needed, it's always KIND_OTHER.
this._unsafePath = aUnsafePath;
this._units = aUnits;
if (aAmount === kUnknown) {
this._amount = 0;
this._isUnknown = true;
} else {
this._amount = aAmount;
}
this._unsafeDescription = aUnsafeDesc;
this._asString = this.toString();
}
-OtherReporter.prototype = {
+OtherReport.prototype = {
toString: function() {
switch (this._units) {
case UNITS_BYTES: return formatBytes(this._amount);
case UNITS_COUNT:
case UNITS_COUNT_CUMULATIVE: return formatInt(this._amount);
case UNITS_PERCENTAGE: return formatPercentage(this._amount);
default:
- assert(false, "bad units in OtherReporter.toString");
+ assert(false, "bad units in OtherReport.toString");
}
},
isInvalid: function() {
let n = this._amount;
switch (this._units) {
case UNITS_BYTES:
case UNITS_COUNT:
case UNITS_COUNT_CUMULATIVE: return (n !== kUnknown && n < 0);
case UNITS_PERCENTAGE: return (n !== kUnknown &&
!(0 <= n && n <= 10000));
default:
- assert(false, "bad units in OtherReporter.isInvalid");
+ assert(false, "bad units in OtherReport.isInvalid");
}
}
};
-OtherReporter.compare = function(a, b) {
+OtherReport.compare = function(a, b) {
return a._unsafePath < b._unsafePath ? -1 :
a._unsafePath > b._unsafePath ? 1 :
0;
};
/**
* Appends the elements for the "Other Measurements" section.
*
* @param aP
* The parent DOM node.
- * @param aReportersByProcess
- * Table of Reporters for this process, indexed by _unsafePath.
+ * @param aReportsByProcess
+ * Table of Reports for this process, indexed by _unsafePath.
* @param aProcess
- * The process these reporters correspond to.
+ * The process these Reports correspond to.
* @return The generated text.
*/
-function appendOtherElements(aP, aReportersByProcess)
+function appendOtherElements(aP, aReportsByProcess)
{
appendSectionHeader(aP, kTreeNames['other']);
let pre = appendElement(aP, "pre", "tree");
- // Generate an array of Reporter-like elements, stripping out all the
- // Reporters that have already been handled. Also find the width of the
+ // Generate an array of Report-like elements, stripping out all the
+ // Reports that have already been handled. Also find the width of the
// widest element, so we can format things nicely.
let maxStringLength = 0;
- let otherReporters = [];
- for (let unsafePath in aReportersByProcess) {
- let r = aReportersByProcess[unsafePath];
+ let otherReports = [];
+ for (let unsafePath in aReportsByProcess) {
+ let r = aReportsByProcess[unsafePath];
if (!r._done) {
assert(r._kind === KIND_OTHER,
"_kind !== KIND_OTHER for " + makeSafe(r._unsafePath));
- assert(r._nMerged === undefined); // we don't allow dup'd OTHER reporters
- let o = new OtherReporter(r._unsafePath, r._units, r._amount,
- r._unsafeDescription);
- otherReporters.push(o);
+ assert(r._nMerged === undefined); // we don't allow dup'd OTHER Reports
+ let o = new OtherReport(r._unsafePath, r._units, r._amount,
+ r._unsafeDescription);
+ otherReports.push(o);
if (o._asString.length > maxStringLength) {
maxStringLength = o._asString.length;
}
}
}
- otherReporters.sort(OtherReporter.compare);
+ otherReports.sort(OtherReport.compare);
// Generate text for the not-yet-printed values.
let text = "";
- for (let i = 0; i < otherReporters.length; i++) {
- let o = otherReporters[i];
+ for (let i = 0; i < otherReports.length; i++) {
+ let o = otherReports[i];
let oIsInvalid = o.isInvalid();
if (oIsInvalid) {
gUnsafePathsWithInvalidValuesForThisProcess.push(o._unsafePath);
}
appendMrValueSpan(pre, pad(o._asString, maxStringLength, ' '), oIsInvalid);
appendMrNameSpan(pre, KIND_OTHER, kNoKids, o._unsafeDescription,
o._unsafePath, o._isUnknown, oIsInvalid);
appendTextNode(pre, "\n");