Bug 1336326 (part 1) - Remove Sampler::GetRegisteredThreads(). r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 03 Feb 2017 11:27:14 +1100
changeset 479269 dfcd7fa37af1a07dbe2d221735bcb192ad4c43e7
parent 479180 ca7ec2dd740d65b6f65a7f9d3802c2494871833a
child 479270 32550b42266999359049ab671fce22fdb5dc4f7b
push id44211
push userbmo:hskupin@gmail.com
push dateMon, 06 Feb 2017 12:18:11 +0000
reviewersmstange
bugs1336326
milestone54.0a1
Bug 1336326 (part 1) - Remove Sampler::GetRegisteredThreads(). r=mstange. Sampler::sRegisteredThreadsMutex is public. Might as well make Sampler::sRegisteredThreads public too. This allows the getter to be removed, and makes the code a little easier to read.
tools/profiler/core/platform-linux.cc
tools/profiler/core/platform-macos.cc
tools/profiler/core/platform-win32.cc
tools/profiler/core/platform.cpp
tools/profiler/core/platform.h
--- a/tools/profiler/core/platform-linux.cc
+++ b/tools/profiler/core/platform-linux.cc
@@ -305,22 +305,20 @@ static void* SignalSender(void* arg) {
   TimeDuration lastSleepOverhead = 0;
   TimeStamp sampleStart = TimeStamp::Now();
   while (SamplerRegistry::sampler->IsActive()) {
 
     SamplerRegistry::sampler->DeleteExpiredMarkers();
 
     if (!SamplerRegistry::sampler->IsPaused()) {
       MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
-      const std::vector<ThreadInfo*>& threads =
-        SamplerRegistry::sampler->GetRegisteredThreads();
 
       bool isFirstProfiledThread = true;
-      for (uint32_t i = 0; i < threads.size(); i++) {
-        ThreadInfo* info = threads[i];
+      for (uint32_t i = 0; i < Sampler::sRegisteredThreads->size(); i++) {
+        ThreadInfo* info = (*Sampler::sRegisteredThreads)[i];
 
         // This will be null if we're not interested in profiling this thread.
         if (!info->hasProfile() || info->IsPendingDelete()) {
           continue;
         }
 
         PseudoStack::SleepState sleeping = info->Stack()->observeSleeping();
         if (sleeping == PseudoStack::SLEEPING_AGAIN) {
--- a/tools/profiler/core/platform-macos.cc
+++ b/tools/profiler/core/platform-macos.cc
@@ -172,21 +172,19 @@ public:
 
   void Run() {
     TimeDuration lastSleepOverhead = 0;
     TimeStamp sampleStart = TimeStamp::Now();
     while (SamplerRegistry::sampler->IsActive()) {
       SamplerRegistry::sampler->DeleteExpiredMarkers();
       if (!SamplerRegistry::sampler->IsPaused()) {
         MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
-        const std::vector<ThreadInfo*>& threads =
-          SamplerRegistry::sampler->GetRegisteredThreads();
         bool isFirstProfiledThread = true;
-        for (uint32_t i = 0; i < threads.size(); i++) {
-          ThreadInfo* info = threads[i];
+        for (uint32_t i = 0; i < Sampler::sRegisteredThreads->size(); i++) {
+          ThreadInfo* info = (*Sampler::sRegisteredThreads)[i];
 
           // This will be null if we're not interested in profiling this thread.
           if (!info->hasProfile() || info->IsPendingDelete()) {
             continue;
           }
 
           PseudoStack::SleepState sleeping = info->Stack()->observeSleeping();
           if (sleeping == PseudoStack::SLEEPING_AGAIN) {
--- a/tools/profiler/core/platform-win32.cc
+++ b/tools/profiler/core/platform-win32.cc
@@ -162,21 +162,19 @@ class SamplerThread
     if (mInterval < 10)
         ::timeBeginPeriod(mInterval);
 
     while (mSampler->IsActive()) {
       mSampler->DeleteExpiredMarkers();
 
       if (!mSampler->IsPaused()) {
         mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
-        const std::vector<ThreadInfo*>& threads =
-          mSampler->GetRegisteredThreads();
         bool isFirstProfiledThread = true;
-        for (uint32_t i = 0; i < threads.size(); i++) {
-          ThreadInfo* info = threads[i];
+        for (uint32_t i = 0; i < Sampler::sRegisteredThreads->size(); i++) {
+          ThreadInfo* info = (*Sampler::sRegisteredThreads)[i];
 
           // This will be null if we're not interested in profiling this thread.
           if (!info->hasProfile() || info->IsPendingDelete()) {
             continue;
           }
 
           PseudoStack::SleepState sleeping = info->Stack()->observeSleeping();
           if (sleeping == PseudoStack::SLEEPING_AGAIN) {
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -740,20 +740,19 @@ profiler_start(int aProfileEntries, doub
   gSampler =
     new Sampler(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL,
                 aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY,
                 aFeatures, aFeatureCount, aThreadNameFilters, aFilterCount);
 
   gSampler->Start();
   if (gSampler->ProfileJS() || gSampler->InPrivacyMode()) {
     mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
-    const std::vector<ThreadInfo*>& threads = gSampler->GetRegisteredThreads();
 
-    for (uint32_t i = 0; i < threads.size(); i++) {
-      ThreadInfo* info = threads[i];
+    for (uint32_t i = 0; i < Sampler::sRegisteredThreads->size(); i++) {
+      ThreadInfo* info = (*Sampler::sRegisteredThreads)[i];
       if (info->IsPendingDelete() || !info->hasProfile()) {
         continue;
       }
       info->Stack()->reinitializeOnResume();
       if (gSampler->ProfileJS()) {
         info->Stack()->enableJSSampling();
       }
       if (gSampler->InPrivacyMode()) {
--- a/tools/profiler/core/platform.h
+++ b/tools/profiler/core/platform.h
@@ -292,30 +292,27 @@ public:
 
   // If we move the backtracing code into the platform files we won't
   // need to have these hacks
 #ifdef XP_WIN
   // xxxehsan sucky hack :(
   static uintptr_t GetThreadHandle(PlatformData*);
 #endif
 
-  static const std::vector<ThreadInfo*>& GetRegisteredThreads() {
-    return *sRegisteredThreads;
-  }
-
   static bool RegisterCurrentThread(const char* aName,
                                     PseudoStack* aPseudoStack,
                                     bool aIsMainThread, void* stackTop);
   static void UnregisterCurrentThread();
 
   static void Startup();
   // Should only be called on shutdown
   static void Shutdown();
 
   static mozilla::UniquePtr<mozilla::Mutex> sRegisteredThreadsMutex;
+  static std::vector<ThreadInfo*>* sRegisteredThreads;
 
   static bool CanNotifyObservers() {
 #ifdef MOZ_WIDGET_GONK
     // We use profile.sh on b2g to manually select threads and options per process.
     return false;
 #elif defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
     // Android ANR reporter uses the profiler off the main thread
     return NS_IsMainThread();
@@ -360,18 +357,16 @@ private:
 
   void StreamJSON(SpliceableJSONWriter& aWriter, double aSinceTime);
 
   // Called within a signal. This function must be reentrant
   void InplaceTick(TickSample* sample);
 
   void SetActive(bool value) { NoBarrier_Store(&active_, value); }
 
-  static std::vector<ThreadInfo*>* sRegisteredThreads;
-
   const double interval_;
   Atomic32 paused_;
   Atomic32 active_;
   const int entrySize_;
 
   // Refactor me!
 #if defined(SPS_OS_linux) || defined(SPS_OS_android)
   bool signal_handler_installed_;