Bug 1439168 - Return profiled threads sorted by registration time. r?njn
MozReview-Commit-ID: 6grx6eSLteQ
--- 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)
{