Bug 702300 (part 9) - Remove the unnecessary safe/unsafe distinction for report descriptions. r=jlebar.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 16 Feb 2012 22:10:39 -0800
changeset 87265 ec21e7e02464f60cabd31bdedb126fd9962dd4a1
parent 87264 17927137a6993f35d7d97a19997112214d191ed2
child 87266 621528be5df8c9862d390918d3fb2b214c373d32
push id22103
push userbmo@edmorley.co.uk
push dateTue, 21 Feb 2012 12:01:45 +0000
treeherdermozilla-central@4038ffaa5d82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs702300
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 702300 (part 9) - Remove the unnecessary safe/unsafe distinction for report descriptions. r=jlebar.
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -61,19 +61,18 @@ const UNITS_PERCENTAGE       = Ci.nsIMem
 const gVerbose = location.href === "about:memory?verbose" ||
                  location.href === "about:compartments?verbose";
 
 let gChildMemoryListener = undefined;
 
 //---------------------------------------------------------------------------
 
 // 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".
+// being mistaken for path separators.  Paths/names where this hasn't been
+// undone are prefixed with "unsafe"; the rest are prefixed with "safe".
 function flipBackslashes(aUnsafeStr)
 {
   return aUnsafeStr.replace(/\\/g, '/');
 }
 
 function assert(aCond, aMsg)
 {
   if (!aCond) {
@@ -249,17 +248,17 @@ function appendElementWithText(aP, aTagN
 }
 
 //---------------------------------------------------------------------------
 // Code specific to about:memory
 //---------------------------------------------------------------------------
 
 const kUnknown = -1;    // used for an unknown _amount
 
-const kTreeUnsafeDescriptions = {
+const kTreeDescriptions = {
   'explicit' :
 "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[]).\
 \n\n\
 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 \
@@ -420,23 +419,23 @@ function updateAboutMemory()
                     "to see a description of what it measures.";
 
   appendElementWithText(body, "div", "legend", legendText1);
   appendElementWithText(body, "div", "legend", legendText2);
 }
 
 //---------------------------------------------------------------------------
 
-function Report(aUnsafePath, aKind, aUnits, aAmount, aUnsafeDesc)
+function Report(aUnsafePath, aKind, aUnits, aAmount, aDescription)
 {
   this._unsafePath  = aUnsafePath;
   this._kind        = aKind;
   this._units       = aUnits;
   this._amount      = aAmount;
-  this._unsafeDescription = aUnsafeDesc;
+  this._description = aDescription;
   // this._nMerged is only defined if > 1
   // this._done is defined and set to true when the Report's amount is read
 }
 
 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 report is
   // duplicated;  it might be worth investigating and splitting up to have
@@ -475,20 +474,20 @@ function getReportsByProcess(aMgr)
   {
     return ((aName === "smaps" && !gVerbose) ||
             (aName === "compartments"));
   }
 
   let reportsByProcess = {};
 
   function handleReport(aProcess, aUnsafePath, aKind, aUnits, aAmount,
-                        aUnsafeDesc)
+                        aDescription)
   {
     let process = aProcess === "" ? "Main" : aProcess;
-    let r = new Report(aUnsafePath, aKind, aUnits, aAmount, aUnsafeDesc);
+    let r = new Report(aUnsafePath, aKind, aUnits, aAmount, aDescription);
     if (!reportsByProcess[process]) {
       reportsByProcess[process] = {};
     }
     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.
@@ -511,24 +510,24 @@ function getReportsByProcess(aMgr)
 //   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:
   // - _amount (which is never |kUnknown|)
-  // - _unsafeDescription
+  // - _description
   // - _kind
   // - _nMerged (only defined if > 1)
   // - _isUnknown (only defined if true)
   //
   // Non-leaf TreeNodes have these properties added later:
   // - _amount (which is never |kUnknown|)
-  // - _unsafeDescription
+  // - _description
   // - _hideKids (only defined if true)
 }
 
 TreeNode.prototype = {
   findKid: function(aUnsafeName) {
     for (let i = 0; i < this._kids.length; i++) {
       if (this._kids[i]._unsafeName === aUnsafeName) {
         return this._kids[i];
@@ -600,17 +599,17 @@ function buildTree(aReports, aTreeName)
       }
       // 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._description = r._description;
       u._kind = r._kind;
       if (r._nMerged) {
         u._nMerged = r._nMerged;
       }
       r._done = true;
     }
   }
 
@@ -621,26 +620,26 @@ function buildTree(aReports, aTreeName)
   // Next, fill in the remaining properties bottom-up.
   // Note that this function never returns kUnknown.
   function fillInNonLeafNodes(aT)
   {
     if (aT._kids.length === 0) {
       // Leaf node.  Has already been filled in.
       assert(aT._kind !== undefined, "aT._kind is undefined for leaf node");
     } else {
-      // Non-leaf node.  Derive its _amount and _unsafeDescription entirely
+      // Non-leaf node.  Derive its _amount and _description entirely
       // from its children.
       assert(aT._kind === undefined, "aT._kind is defined for non-leaf node");
       let childrenBytes = 0;
       for (let i = 0; i < aT._kids.length; i++) {
         childrenBytes += fillInNonLeafNodes(aT._kids[i]);
       }
       aT._amount = childrenBytes;
-      aT._unsafeDescription =
-        "The sum of all entries below '" + aT._unsafeName + "'.";
+      aT._description = "The sum of all entries below '" +
+                        flipBackslashes(aT._unsafeName) + "'.";
     }
     assert(aT._amount !== kUnknown, "aT._amount !== kUnknown");
     return aT._amount;
   }
 
   fillInNonLeafNodes(t);
 
   // Reduce the depth of the tree by the number of occurrences of '/' in
@@ -649,17 +648,17 @@ function buildTree(aReports, aTreeName)
   for (let i = 0; i < aTreeName.length; i++) {
     if (aTreeName[i] == '/') {
       assert(t._kids.length == 1, "Not expecting multiple kids here.");
       t = t._kids[0];
     }
   }
 
   // Set the (unsafe) description on the root node.
-  t._unsafeDescription = kTreeUnsafeDescriptions[t._unsafeName];
+  t._description = kTreeDescriptions[t._unsafeName];
 
   return t;
 }
 
 /**
  * Ignore all the memory reports that belong to a "smaps" tree;  this involves
  * explicitly marking them as done.
  *
@@ -716,17 +715,17 @@ function fixUpExplicitTree(aT, aReports)
       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
   // Report object for this TreeNode object (which isn't true)
-  heapUnclassifiedT._unsafeDescription = kindToString(KIND_HEAP) +
+  heapUnclassifiedT._description = 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;
 
   return hasKnownHeapAllocated;
@@ -781,17 +780,17 @@ function sortTreeAndInsertAggregateNodes
       let aggT = new TreeNode("(" + nAgg + " tiny)");
       let aggBytes = 0;
       for ( ; i < aT._kids.length; i++) {
         aggBytes += aT._kids[i]._amount;
         aggT._kids.push(aT._kids[i]);
       }
       aggT._hideKids = true;
       aggT._amount = aggBytes;
-      aggT._unsafeDescription =
+      aggT._description =
         nAgg + " sub-trees that are below the " + kSignificanceThresholdPerc +
         "% significance threshold.";
       aT._kids.splice(i0, nAgg, aggT);
       aT._kids.sort(TreeNode.compare);
 
       // Process the moved children.
       for (i = 0; i < aggT._kids.length; i++) {
         sortTreeAndInsertAggregateNodes(aTotalBytes, aggT._kids[i]);
@@ -1068,17 +1067,17 @@ function kindToString(aKind)
   }
 }
 
 // Possible states for kids.
 const kNoKids   = 0;
 const kHideKids = 1;
 const kShowKids = 2;
 
-function appendMrNameSpan(aP, aKind, aKidsState, aUnsafeDesc, aUnsafeName,
+function appendMrNameSpan(aP, aKind, aKidsState, aDescription, aUnsafeName,
                           aIsUnknown, aIsInvalid, aNMerged)
 {
   let text = "";
   if (aKidsState === kNoKids) {
     appendElementWithText(aP, "span", "mrSep", kDoubleHorizontalSep);
   } else if (aKidsState === kHideKids) {
     appendElementWithText(aP, "span", "mrSep",        " ++ ");
     appendElementWithText(aP, "span", "mrSep hidden", " -- ");
@@ -1086,17 +1085,17 @@ function appendMrNameSpan(aP, aKind, aKi
     appendElementWithText(aP, "span", "mrSep hidden", " ++ ");
     appendElementWithText(aP, "span", "mrSep",        " -- ");
   } else {
     assert(false, "bad aKidsState");
   }
 
   let nameSpan = appendElementWithText(aP, "span", "mrName",
                                        flipBackslashes(aUnsafeName));
-  nameSpan.title = kindToString(aKind) + flipBackslashes(aUnsafeDesc);
+  nameSpan.title = kindToString(aKind) + aDescription;
 
   if (aIsUnknown) {
     let noteSpan = appendElementWithText(aP, "span", "mrNote", " [*]");
     noteSpan.title =
       "Warning: this memory reporter was unable to compute a useful value. ";
   }
   if (aIsInvalid) {
     let noteSpan = appendElementWithText(aP, "span", "mrNote", " [?!]");
@@ -1286,17 +1285,17 @@ function appendTreeElements(aPOuter, aT,
     }
 
     appendMrValueSpan(d, tString, tIsInvalid);
     appendElementWithText(d, "span", "mrPerc", percText);
 
     // We don't want to show '(nonheap)' on a tree like 'smaps/vsize', since
     // the whole tree is non-heap.
     let kind = isExplicitTree ? aT._kind : undefined;
-    appendMrNameSpan(d, kind, kidsState, aT._unsafeDescription, aT._unsafeName,
+    appendMrNameSpan(d, kind, kidsState, aT._description, aT._unsafeName,
                      aT._isUnknown, tIsInvalid, aT._nMerged);
     appendTextNode(d, "\n");
 
     // In non-verbose mode, invalid nodes can be hidden in collapsed sub-trees.
     // But it's good to always see them, so force this.
     if (!gVerbose && tIsInvalid) {
       expandPathToThisElement(d);
     }
@@ -1334,28 +1333,28 @@ function appendTreeElements(aPOuter, aT,
  
   let pre = appendElement(aPOuter, "pre", "entries");
   appendTreeElements2(pre, /* prePath = */"", aT, [], "", rootStringLength);
   appendTextNode(aPOuter, "\n");  // gives nice spacing when we cut and paste
 }
 
 //---------------------------------------------------------------------------
 
-function OtherReport(aUnsafePath, aUnits, aAmount, aUnsafeDesc, aNMerged)
+function OtherReport(aUnsafePath, aUnits, aAmount, aDescription, 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._description = aDescription;
   this._asString = this.toString();
 }
 
 OtherReport.prototype = {
   toString: function() {
     switch (this._units) {
       case UNITS_BYTES:            return formatBytes(this._amount);
       case UNITS_COUNT:
@@ -1410,17 +1409,17 @@ function appendOtherElements(aP, aReport
   let otherReports = [];
   for (let unsafePath in aReportsByProcess) {
     let r = aReportsByProcess[unsafePath];
     if (!r._done) {
       assert(r._kind === KIND_OTHER,
              "_kind !== KIND_OTHER for " + flipBackslashes(r._unsafePath));
       assert(r._nMerged === undefined);  // we don't allow dup'd OTHER Reports
       let o = new OtherReport(r._unsafePath, r._units, r._amount,
-                              r._unsafeDescription);
+                              r._description);
       otherReports.push(o);
       if (o._asString.length > maxStringLength) {
         maxStringLength = o._asString.length;
       }
     }
   }
   otherReports.sort(OtherReport.compare);
 
@@ -1428,18 +1427,18 @@ function appendOtherElements(aP, aReport
   let text = "";
   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);
+    appendMrNameSpan(pre, KIND_OTHER, kNoKids, o._description, o._unsafePath,
+                     o._isUnknown, oIsInvalid);
     appendTextNode(pre, "\n");
   }
 
   appendTextNode(aP, "\n");  // gives nice spacing when we cut and paste
 }
 
 function appendSectionHeader(aP, aText)
 {
@@ -1531,24 +1530,25 @@ function getCompartmentsByProcess(aMgr)
 
   function ignoreMulti(aName)
   {
     return aName !== "compartments";
   }
 
   let compartmentsByProcess = {};
 
-  function handleReport(aProcess, aUnsafePath, aKind, aUnits, aAmount, aDesc)
+  function handleReport(aProcess, aUnsafePath, aKind, aUnits, aAmount,
+                        aDescription)
   {
     let process = aProcess === "" ? "Main" : aProcess;
 
-    assert(aKind   === KIND_OTHER, "bad kind");
-    assert(aUnits  === UNITS_COUNT, "bad units");
-    assert(aAmount === 1, "bad amount");
-    assert(aDesc   === "", "bad description");
+    assert(aKind        === KIND_OTHER, "bad kind");
+    assert(aUnits       === UNITS_COUNT, "bad units");
+    assert(aAmount      === 1, "bad amount");
+    assert(aDescription === "", "bad description");
 
     let unsafeNames = aUnsafePath.split('/');
 
     let isSystemCompartment;
     if (unsafeNames[0] === "compartments" && unsafeNames[1] == "system" &&
         unsafeNames.length == 3)
     {
       isSystemCompartment = true;