Bug 1652006 - In default sorting, instead of sorting by pid, group together rows by type;r=florian
authorDavid Teller <dteller@mozilla.com>
Wed, 22 Jul 2020 11:03:46 +0000
changeset 541778 5fffdf68ca3d9d2ca55bfbbbbeb67448c2dc0f27
parent 541777 103d388bac7473c617ddf3c6794ee7651ff86422
child 541779 fdfccf41210646069d39d8b1c131c407af68740f
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1652006
milestone80.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 1652006 - In default sorting, instead of sorting by pid, group together rows by type;r=florian Differential Revision: https://phabricator.services.mozilla.com/D83668
toolkit/components/aboutprocesses/content/aboutProcesses.js
--- a/toolkit/components/aboutprocesses/content/aboutProcesses.js
+++ b/toolkit/components/aboutprocesses/content/aboutProcesses.js
@@ -165,19 +165,16 @@ var State = {
       result.threads = cur.threads.map(data =>
         this._getThreadDelta(data, null, null)
       );
       return result;
     }
     if (prev.pid != cur.pid) {
       throw new Error("Assertion failed: A process cannot change pid.");
     }
-    if (prev.type != cur.type) {
-      throw new Error("Assertion failed: A process cannot change type.");
-    }
     let prevThreads = new Map();
     for (let thread of prev.threads) {
       prevThreads.set(thread.tid, thread);
     }
     let deltaT = (cur.date - prev.date) * MS_PER_NS;
     let threads = cur.threads.map(curThread => {
       let prevThread = prevThreads.get(curThread.tid);
       if (!prevThread) {
@@ -733,33 +730,62 @@ var Control = {
           break;
         case "column-cpu-threads":
           order = b.threads.length - a.threads.length;
           break;
         case "column-memory-resident":
           order = b.totalResidentSize - a.totalResidentSize;
           break;
         case null:
-          // Default order: browser goes first.
-          if (a.type == "browser") {
-            order = -1;
-          } else if (b.type == "browser") {
-            order = 1;
+          // Default order: classify processes by group.
+          order = this._getDisplayGroupRank(a) - this._getDisplayGroupRank(b);
+          if (order == 0) {
+            // Other processes are ordered by origin.
+            order = String(a.name).localeCompare(b.name);
+            if (order == 0) {
+              // If we're running without Fission, many processes will have
+              // the same origin, so differenciate with CPU use.
+              order = b.slopeCpuUser - a.slopeCpuUser;
+            }
           }
-          // Other processes by increasing pid, arbitrarily.
-          order = b.pid - a.pid;
           break;
         default:
           throw new Error("Unsupported order: " + this._sortColumn);
       }
       if (!this._sortAscendent) {
         order = -order;
       }
       return order;
     });
   },
+
+  // Assign a display rank to a process.
+  //
+  // The `browser` process comes first (rank 0).
+  // Then comes web content (rank 1).
+  // Then come special processes (minus preallocated) (rank 2).
+  // Then come preallocated processes (rank 3).
+  _getDisplayGroupRank({ type }) {
+    switch (type) {
+      // Browser comes first.
+      case "browser":
+        return 0;
+      // Web content comes next.
+      case "web":
+      case "webIsolated":
+      case "webLargeAllocation":
+      case "withCoopCoep":
+        return 1;
+      // Preallocated processes come last.
+      case "preallocated":
+        return 3;
+      // Other special processes before preallocated.
+      default:
+        return 2;
+    }
+  },
 };
 
 window.onload = async function() {
   Control.init();
   await Control.update();
   window.setInterval(() => Control.update(), UPDATE_INTERVAL_MS);
 };