Bug 1439168 - Return profiled threads sorted by registration time. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Mon, 12 Feb 2018 01:07:59 -0500
changeset 756755 3189a947197e2cabbb56963a288ace0af4d042ef
parent 756635 af6c4ba0c376b0d24c231ac9bf14985250913bf5
child 756756 e21a6914987df58cb0a19ed317982d41ec073f6e
child 760749 41271abe2b68328470b3f3db0ff8796466612505
push id99539
push userbmo:mstange@themasta.com
push dateSun, 18 Feb 2018 00:09:25 +0000
reviewersnjn
bugs1439168
milestone60.0a1
Bug 1439168 - Return profiled threads sorted by registration time. r?njn MozReview-Commit-ID: 6grx6eSLteQ
tools/profiler/core/platform.cpp
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -520,27 +520,44 @@ public:
   }
 
   // Returns an array containing (RegisteredThread*, ProfiledThreadData*) pairs
   // for all threads that should be included in a profile, both for threads
   // that are still registered, and for threads that have been unregistered but
   // still have data in the buffer.
   // For threads that have already been unregistered, the RegisteredThread
   // pointer will be null.
+  // The returned array is sorted by thread register time.
   // Do not hold on to the return value across thread registration or profiler
   // restarts.
   static nsTArray<Pair<RegisteredThread*, ProfiledThreadData*>> ProfiledThreads(PSLockRef)
   {
     nsTArray<Pair<RegisteredThread*, ProfiledThreadData*>> array;
     for (auto& t : sInstance->mLiveProfiledThreads) {
       array.AppendElement(MakePair(t.mRegisteredThread, t.mProfiledThreadData.get()));
     }
     for (auto& t : sInstance->mDeadProfiledThreads) {
       array.AppendElement(MakePair((RegisteredThread*)nullptr, t.get()));
     }
+
+    class ThreadRegisterTimeComparator {
+    public:
+      bool Equals(const Pair<RegisteredThread*, ProfiledThreadData*>& a,
+                  const Pair<RegisteredThread*, ProfiledThreadData*>& b) const
+      {
+        return a.second()->Info()->RegisterTime() == b.second()->Info()->RegisterTime();
+      }
+
+      bool LessThan(const Pair<RegisteredThread*, ProfiledThreadData*>& a,
+                    const Pair<RegisteredThread*, ProfiledThreadData*>& b) const
+      {
+        return a.second()->Info()->RegisterTime() < b.second()->Info()->RegisterTime();
+      }
+    };
+    array.Sort(ThreadRegisterTimeComparator());
     return array;
   }
 
   // Do a linear search through mLiveProfiledThreads to find the
   // ProfiledThreadData object for a RegisteredThread.
   static ProfiledThreadData* GetProfiledThreadData(PSLockRef,
                                                    RegisteredThread* aRegisteredThread)
   {