Bug 830990 - Stop dispatching CheckResponsivenessEvents when the profiler is stopped. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Sun, 16 Apr 2017 14:48:24 -0400
changeset 563916 9d9af6e88e90eded3d77f2577fcf008222dd52d5
parent 563915 9426626addf4276e56ab2e7c00a5edf5246ea74c
child 624620 29ec117b2e372e27f2194d24938f70bea383a12e
push id54466
push userbmo:mstange@themasta.com
push dateTue, 18 Apr 2017 03:07:55 +0000
reviewersnjn
bugs830990
milestone55.0a1
Bug 830990 - Stop dispatching CheckResponsivenessEvents when the profiler is stopped. r?njn MozReview-Commit-ID: 4MnRGqE2sEK
tools/profiler/core/ThreadInfo.cpp
tools/profiler/core/ThreadInfo.h
--- a/tools/profiler/core/ThreadInfo.cpp
+++ b/tools/profiler/core/ThreadInfo.cpp
@@ -33,20 +33,16 @@ ThreadInfo::ThreadInfo(const char* aName
   MOZ_COUNT_CTOR(ThreadInfo);
 
   // We don't have to guess on mac
 #if defined(GP_OS_darwin)
   pthread_t self = pthread_self();
   mStackTop = pthread_get_stackaddr_np(self);
 #endif
 
-  if (aIsMainThread) {
-    mResponsiveness.emplace();
-  }
-
   // I don't know if we can assert this. But we should warn.
   MOZ_ASSERT(aThreadId >= 0, "native thread ID is < 0");
   MOZ_ASSERT(aThreadId <= INT32_MAX, "native thread ID is > INT32_MAX");
 }
 
 ThreadInfo::~ThreadInfo()
 {
   MOZ_COUNT_DTOR(ThreadInfo);
@@ -54,21 +50,25 @@ ThreadInfo::~ThreadInfo()
   delete mPseudoStack;
 }
 
 void
 ThreadInfo::StartProfiling()
 {
   mIsBeingProfiled = true;
   mPseudoStack->reinitializeOnResume();
+  if (mIsMainThread) {
+    mResponsiveness.emplace();
+  }
 }
 
 void
 ThreadInfo::StopProfiling()
 {
+  mResponsiveness.reset();
   mIsBeingProfiled = false;
 }
 
 void
 ThreadInfo::StreamJSON(ProfileBuffer* aBuffer, SpliceableJSONWriter& aWriter,
                        const TimeStamp& aStartTime, double aSinceTime)
 {
   // mUniqueStacks may already be emplaced from FlushSamplesAndMarkers.
--- a/tools/profiler/core/ThreadInfo.h
+++ b/tools/profiler/core/ThreadInfo.h
@@ -62,21 +62,22 @@ public:
   void StreamJSON(ProfileBuffer* aBuffer, SpliceableJSONWriter& aWriter,
                   const mozilla::TimeStamp& aStartTime, double aSinceTime);
 
   // Call this method when the JS entries inside the buffer are about to
   // become invalid, i.e., just before JS shutdown.
   void FlushSamplesAndMarkers(ProfileBuffer* aBuffer,
                               const mozilla::TimeStamp& aStartTime);
 
-  // Returns nullptr if this is not the main thread.
+  // Returns nullptr if this is not the main thread or if this thread is not
+  // being profiled.
   ThreadResponsiveness* GetThreadResponsiveness()
   {
     ThreadResponsiveness* responsiveness = mResponsiveness.ptrOr(nullptr);
-    MOZ_ASSERT(!!responsiveness == mIsMainThread);
+    MOZ_ASSERT(!!responsiveness == (mIsMainThread && mIsBeingProfiled));
     return responsiveness;
   }
 
 private:
   bool mIsBeingProfiled;
 
   // JS frames in the buffer may require a live JSRuntime to stream (e.g.,
   // stringifying JIT frames). In the case of JSRuntime destruction,