Bug 798019 - Sort processes in about:memory by resident size. r=njn
authorJustin Lebar <justin.lebar@gmail.com>
Fri, 05 Oct 2012 17:54:54 -0400
changeset 109474 823227b1ffe6fc860c18b39237af98aeab389d0f
parent 109473 6c86cf8e24785024bad0f440d5f59f0dd6d25dc5
child 109475 8bda10a190c2e360c0cb9c503e2c0f045fb3d005
push id23630
push useremorley@mozilla.com
push dateSat, 06 Oct 2012 19:35:27 +0000
treeherdermozilla-central@9f677c2bb33d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs798019
milestone18.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 798019 - Sort processes in about:memory by resident size. r=njn
toolkit/components/aboutmemory/content/aboutMemory.js
toolkit/components/aboutmemory/tests/test_aboutmemory.xul
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -495,33 +495,58 @@ function updateAboutMemoryFromClipboard(
  *        Boolean indicating if moz_malloc_usable_size works.
  */
 function appendAboutMemoryMain(aBody, aProcess, aHasMozMallocUsableSize)
 {
   let treesByProcess = {}, degeneratesByProcess = {}, heapTotalByProcess = {};
   getTreesByProcess(aProcess, treesByProcess, degeneratesByProcess,
                     heapTotalByProcess);
 
-  // Generate output for one process at a time.  Always start with the
-  // Main process.
-  if (treesByProcess[gUnnamedProcessStr]) {
-    appendProcessAboutMemoryElements(aBody, gUnnamedProcessStr,
-                                     treesByProcess[gUnnamedProcessStr],
-                                     degeneratesByProcess[gUnnamedProcessStr],
-                                     heapTotalByProcess[gUnnamedProcessStr],
+  // Sort our list of processes.  Always start with the main process, then sort
+  // by resident size (descending).  Processes with no resident reporter go at
+  // the end of the list.
+  let processes = Object.keys(treesByProcess);
+  processes.sort(function(a, b) {
+    assert(a != b, "Elements of Object.keys() should be unique, but " +
+                   "saw duplicate " + a + " elem.");
+
+    if (a == gUnnamedProcessStr) {
+      return -1;
+    }
+
+    if (b == gUnnamedProcessStr) {
+      return 1;
+    }
+
+    let nodeA = degeneratesByProcess[a]['resident'];
+    let nodeB = degeneratesByProcess[b]['resident'];
+
+    if (nodeA && nodeB) {
+      return TreeNode.compareAmounts(nodeA, nodeB);
+    }
+
+    if (nodeA) {
+      return -1;
+    }
+
+    if (nodeB) {
+      return 1;
+    }
+
+    return 0;
+  });
+
+  // Generate output for each process.
+  for (let i = 0; i < processes.length; i++) {
+    let process = processes[i];
+    appendProcessAboutMemoryElements(aBody, process, treesByProcess[process],
+                                     degeneratesByProcess[process],
+                                     heapTotalByProcess[process],
                                      aHasMozMallocUsableSize);
   }
-  for (let process in treesByProcess) {
-    if (process !== gUnnamedProcessStr) {
-      appendProcessAboutMemoryElements(aBody, process, treesByProcess[process],
-                                       degeneratesByProcess[process],
-                                       heapTotalByProcess[process],
-                                       aHasMozMallocUsableSize);
-    }
-  }
 }
 
 /**
  * Appends the page footer.
  *
  * @param aBody
  *        The DOM body element.
  */
--- a/toolkit/components/aboutmemory/tests/test_aboutmemory.xul
+++ b/toolkit/components/aboutmemory/tests/test_aboutmemory.xul
@@ -176,16 +176,20 @@
   // --enable-trace-malloc build.  Allow for that exception, but *only* that
   // exception.
   try {
     is(mgr.explicit, 500*MB + (100 + 13 + 10)*MB + 599*KB, "mgr.explicit");
   } catch (ex) {
     is(ex.result, Cr.NS_ERROR_NOT_AVAILABLE, "mgr.explicit exception");
   }
  
+  // The main process always comes first when we display about:memory.  The
+  // remaining processes are sorted by their |resident| values (starting with
+  // the largest).  Processes without a |resident| memory reporter are saved
+  // for the end.
   let fakeReporters2 = [
     f("2nd", "heap-allocated",  OTHER,  1000 * MB),
     f("2nd", "heap-unallocated",OTHER,   100 * MB),
     f("2nd", "explicit/a/b/c",  HEAP,    497 * MB),
     f("2nd", "explicit/a/b/c",  HEAP,      1 * MB), // dup: merge
     f("2nd", "explicit/a/b/c",  HEAP,      1 * MB), // dup: merge
     f("2nd", "explicit/flip\\the\\backslashes",
                                 HEAP,    200 * MB),
@@ -199,28 +203,30 @@
     // process won't cause these to be skipped;  the fall-back skipping will
     // be hit instead.
     f("2nd", "size/e",          NONHEAP, 24*4*KB),
     f("2nd", "size/f",          NONHEAP, 24*4*KB),
 
     // Check that we can handle "heap-allocated" not being present.
     f("3rd", "explicit/a/b",    HEAP,    333 * MB),
     f("3rd", "explicit/a/c",    HEAP,    444 * MB),
-    f2("3rd", "other1",         OTHER,   BYTES, 1 * MB),
+    f("3rd", "other1",          OTHER,     1 * MB),
+    f("3rd", "resident",        OTHER,   100 * MB),
 
     // Invalid values (negative, too-big) should be identified.
     f("4th", "heap-allocated",   OTHER,   100 * MB),
+    f("4th", "resident",         OTHER,   200 * MB),
     f("4th", "explicit/js/compartment(http:\\\\too-big.com\\)/stuff",
                                  HEAP,    150 * MB),
     f("4th", "explicit/ok",      HEAP,      5 * MB),
     f("4th", "explicit/neg1",    NONHEAP,  -2 * MB),
     // -111 becomes "-0.00MB" in non-verbose mode, and getting the negative
     // sign in there correctly is non-trivial.
-    f2("4th", "other1",          OTHER,   BYTES, -111),
-    f2("4th", "other2",          OTHER,   BYTES, -222 * MB),
+    f("4th",  "other1",          OTHER,   -111),
+    f("4th",  "other2",          OTHER,   -222 * MB),
     f2("4th", "other3",          OTHER,   COUNT, -333),
     f2("4th", "other4",          OTHER,   COUNT_CUMULATIVE, -444),
     f2("4th", "other5",          OTHER,   PERCENTAGE, -555),
     f2("4th", "other6",          OTHER,   PERCENTAGE, 66666),
 
     // If a negative value is within a collapsed sub-tree in non-verbose mode,
     // we should get the warning at the top and the relevant sub-trees should
     // be expanded, even in non-verbose mode.
@@ -294,44 +300,16 @@ 888.00 MB ── explicit\n\
 500.00 MB ── heap-allocated\n\
 100.00 MB ── heap-unallocated\n\
 222.00 MB ── other2\n\
       777 ── other3\n\
       888 ── other4 [2]\n\
    45.67% ── perc1\n\
   100.00% ── perc2\n\
 \n\
-2nd\n\
-\n\
-Explicit Allocations\n\
-1,000.00 MB (100.0%) -- explicit\n\
-├────499.00 MB (49.90%) ── a/b/c [3]\n\
-├────200.00 MB (20.00%) ── flip/the/backslashes\n\
-├────200.00 MB (20.00%) ── compartment(compartment-url)\n\
-└────101.00 MB (10.10%) ── heap-unclassified\n\
-\n\
-Other Measurements\n\
-1,000.00 MB ── heap-allocated\n\
-  100.00 MB ── heap-unallocated\n\
-  666.00 MB ── other0\n\
-  111.00 MB ── other1\n\
-\n\
-3rd\n\
-\n\
-WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is not shown and the 'explicit' tree shows less memory than it should.\n\
-\n\
-Explicit Allocations\n\
-777.00 MB (100.0%) -- explicit\n\
-└──777.00 MB (100.0%) -- a\n\
-   ├──444.00 MB (57.14%) ── c\n\
-   └──333.00 MB (42.86%) ── b\n\
-\n\
-Other Measurements\n\
-1.00 MB ── other1\n\
-\n\
 4th\n\
 \n\
 WARNING: the following values are negative or unreasonably large.\n\
  explicit/js/compartment(http://too-big.com/)/stuff\n\
  explicit/(2 tiny)\n\
  explicit/(2 tiny)/neg1\n\
  explicit/(2 tiny)/heap-unclassified\n\
  other1\n\
@@ -352,16 +330,46 @@ 98.00 MB (100.0%) -- explicit\n\
 Other Measurements\n\
  100.00 MB ── heap-allocated\n\
   -0.00 MB ── other1 [?!]\n\
 -222.00 MB ── other2 [?!]\n\
       -333 ── other3 [?!]\n\
       -444 ── other4 [?!]\n\
     -5.55% ── other5 [?!]\n\
    666.66% ── other6\n\
+ 200.00 MB ── resident\n\
+\n\
+3rd\n\
+\n\
+WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is not shown and the 'explicit' tree shows less memory than it should.\n\
+\n\
+Explicit Allocations\n\
+777.00 MB (100.0%) -- explicit\n\
+└──777.00 MB (100.0%) -- a\n\
+   ├──444.00 MB (57.14%) ── c\n\
+   └──333.00 MB (42.86%) ── b\n\
+\n\
+Other Measurements\n\
+  1.00 MB ── other1\n\
+100.00 MB ── resident\n\
+\n\
+2nd\n\
+\n\
+Explicit Allocations\n\
+1,000.00 MB (100.0%) -- explicit\n\
+├────499.00 MB (49.90%) ── a/b/c [3]\n\
+├────200.00 MB (20.00%) ── flip/the/backslashes\n\
+├────200.00 MB (20.00%) ── compartment(compartment-url)\n\
+└────101.00 MB (10.10%) ── heap-unclassified\n\
+\n\
+Other Measurements\n\
+1,000.00 MB ── heap-allocated\n\
+  100.00 MB ── heap-unallocated\n\
+  666.00 MB ── other0\n\
+  111.00 MB ── other1\n\
 \n\
 5th\n\
 \n\
 WARNING: the following values are negative or unreasonably large.\n\
  explicit/(3 tiny)/a/neg2\n\
  explicit/(3 tiny)/a/neg1\n\
  explicit/(3 tiny)/b/c\n\
  explicit/(3 tiny)/b/c/d\n\
@@ -453,47 +461,16 @@ 931,135,488 B ── explicit\n\
 524,288,000 B ── heap-allocated\n\
 104,857,600 B ── heap-unallocated\n\
 232,783,872 B ── other2\n\
           777 ── other3\n\
           888 ── other4 [2]\n\
        45.67% ── perc1\n\
       100.00% ── perc2\n\
 \n\
-2nd\n\
-\n\
-Explicit Allocations\n\
-1,048,576,000 B (100.0%) -- explicit\n\
-├────523,239,424 B (49.90%) ── a/b/c [3]\n\
-├────209,715,200 B (20.00%) ── flip/the/backslashes\n\
-├────209,715,200 B (20.00%) ── compartment(compartment-url)\n\
-└────105,906,176 B (10.10%) ── heap-unclassified\n\
-\n\
-Virtual Size Breakdown\n\
-196,608 B (100.0%) ++ size\n\
-\n\
-Other Measurements\n\
-1,048,576,000 B ── heap-allocated\n\
-  104,857,600 B ── heap-unallocated\n\
-  698,351,616 B ── other0\n\
-  116,391,936 B ── other1\n\
-\n\
-3rd\n\
-\n\
-WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is not shown and the 'explicit' tree shows less memory than it should.\n\
-\n\
-Explicit Allocations\n\
-814,743,552 B (100.0%) -- explicit\n\
-└──814,743,552 B (100.0%) -- a\n\
-   ├──465,567,744 B (57.14%) ── c\n\
-   └──349,175,808 B (42.86%) ── b\n\
-\n\
-Other Measurements\n\
-1,048,576 B ── other1\n\
-\n\
 4th\n\
 \n\
 WARNING: the following values are negative or unreasonably large.\n\
  explicit/js/compartment(http://too-big.com/)/stuff\n\
  explicit/neg1\n\
  explicit/heap-unclassified\n\
  other1\n\
  other2\n\
@@ -512,16 +489,49 @@ 102,760,448 B (100.0%) -- explicit\n\
 Other Measurements\n\
  104,857,600 B ── heap-allocated\n\
         -111 B ── other1 [?!]\n\
 -232,783,872 B ── other2 [?!]\n\
           -333 ── other3 [?!]\n\
           -444 ── other4 [?!]\n\
         -5.55% ── other5 [?!]\n\
        666.66% ── other6\n\
+ 209,715,200 B ── resident\n\
+\n\
+3rd\n\
+\n\
+WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is not shown and the 'explicit' tree shows less memory than it should.\n\
+\n\
+Explicit Allocations\n\
+814,743,552 B (100.0%) -- explicit\n\
+└──814,743,552 B (100.0%) -- a\n\
+   ├──465,567,744 B (57.14%) ── c\n\
+   └──349,175,808 B (42.86%) ── b\n\
+\n\
+Other Measurements\n\
+  1,048,576 B ── other1\n\
+104,857,600 B ── resident\n\
+\n\
+2nd\n\
+\n\
+Explicit Allocations\n\
+1,048,576,000 B (100.0%) -- explicit\n\
+├────523,239,424 B (49.90%) ── a/b/c [3]\n\
+├────209,715,200 B (20.00%) ── flip/the/backslashes\n\
+├────209,715,200 B (20.00%) ── compartment(compartment-url)\n\
+└────105,906,176 B (10.10%) ── heap-unclassified\n\
+\n\
+Virtual Size Breakdown\n\
+196,608 B (100.0%) ++ size\n\
+\n\
+Other Measurements\n\
+1,048,576,000 B ── heap-allocated\n\
+  104,857,600 B ── heap-unallocated\n\
+  698,351,616 B ── other0\n\
+  116,391,936 B ── other1\n\
 \n\
 5th\n\
 \n\
 WARNING: the following values are negative or unreasonably large.\n\
  explicit/a/neg2\n\
  explicit/a/neg1\n\
  explicit/b/c\n\
  explicit/b/c/d\n\