Bug 1447338 - Add thread "responsiveness" as a configurable feature to the Gecko Profiler; r=mstange
☠☠ backed out by 8cc35753ba0d ☠ ☠
authorGreg Tatum <gtatum@mozilla.com>
Wed, 28 Mar 2018 15:28:54 -0500
changeset 796252 134bf057ca613680cff5cf3c97e3d702a3adcb75
parent 796251 e4cdaab8e5c7b6e78c4f32bb1694e47c257ba363
child 796253 51cd668c0e87946b6163f71ac0f527460aefa2da
push id110198
push userbmo:rcaliman@mozilla.com
push dateThu, 17 May 2018 12:04:52 +0000
reviewersmstange
bugs1447338
milestone62.0a1
Bug 1447338 - Add thread "responsiveness" as a configurable feature to the Gecko Profiler; r=mstange MozReview-Commit-ID: KTJRvQzUwsf
browser/components/extensions/schemas/geckoProfiler.json
devtools/client/performance-new/components/Settings.js
devtools/client/performance-new/store/reducers.js
devtools/server/actors/perf.js
tools/profiler/core/ProfiledThreadData.cpp
tools/profiler/core/ProfiledThreadData.h
tools/profiler/core/platform.cpp
tools/profiler/public/GeckoProfiler.h
--- a/browser/components/extensions/schemas/geckoProfiler.json
+++ b/browser/components/extensions/schemas/geckoProfiler.json
@@ -24,16 +24,17 @@
         "type": "string",
         "enum": [
           "java",
           "js",
           "leaf",
           "mainthreadio",
           "memory",
           "privacy",
+          "responsiveness",
           "restyle",
           "screenshots",
           "stackwalk",
           "tasktracer",
           "threads",
           "trackopts"
         ]
       }
--- a/devtools/client/performance-new/components/Settings.js
+++ b/devtools/client/performance-new/components/Settings.js
@@ -91,16 +91,22 @@ const featureCheckboxes = [
   },
   {
     name: "JavaScript",
     value: "js",
     title: "Record JavaScript stack information, and interleave it with native stacks.",
     recommended: true
   },
   {
+    name: "Responsiveness",
+    value: "responsiveness",
+    title: "Collect thread responsiveness information.",
+    recommended: true
+  },
+  {
     name: "Java",
     value: "java",
     title: "Profile Java code (Android only)."
   },
   {
     name: "Native Leaf Stack",
     value: "leaf",
     title: "Record the native memory address of the leaf-most stack. This could be " +
--- a/devtools/client/performance-new/store/reducers.js
+++ b/devtools/client/performance-new/store/reducers.js
@@ -83,17 +83,17 @@ function entries(state = 10000000, actio
       return state;
   }
 }
 
 /**
  * The features that are enabled for the profiler.
  * @param {array} state
  */
-function features(state = ["js", "stackwalk"], action) {
+function features(state = ["js", "stackwalk", "responsiveness"], action) {
   switch (action.type) {
     case "CHANGE_FEATURES":
       return action.features;
     case "INITIALIZE_STORE":
       return action.recordingSettingsFromPreferences.features;
     default:
       return state;
   }
--- a/devtools/server/actors/perf.js
+++ b/devtools/server/actors/perf.js
@@ -50,17 +50,18 @@ exports.PerfActor = ActorClassWithSpec(p
       return false;
     }
 
     // For a quick implementation, decide on some default values. These may need
     // to be tweaked or made configurable as needed.
     const settings = {
       entries: options.entries || 1000000,
       interval: options.interval || 1,
-      features: options.features || ["js", "stackwalk", "threads", "leaf"],
+      features: options.features ||
+        ["js", "stackwalk", "responsiveness", "threads", "leaf"],
       threads: options.threads || ["GeckoMain", "Compositor"]
     };
 
     try {
       // This can throw an error if the profiler is in the wrong state.
       Services.profiler.StartProfiler(
         settings.entries,
         settings.interval,
--- a/tools/profiler/core/ProfiledThreadData.cpp
+++ b/tools/profiler/core/ProfiledThreadData.cpp
@@ -13,21 +13,24 @@
 #ifdef XP_WIN
 #include <process.h>
 #define getpid _getpid
 #else
 #include <unistd.h> // for getpid()
 #endif
 
 ProfiledThreadData::ProfiledThreadData(ThreadInfo* aThreadInfo,
-                                       nsIEventTarget* aEventTarget)
+                                       nsIEventTarget* aEventTarget,
+                                       bool aIncludeResponsiveness)
   : mThreadInfo(aThreadInfo)
 {
   MOZ_COUNT_CTOR(ProfiledThreadData);
-  mResponsiveness.emplace(aEventTarget, aThreadInfo->IsMainThread());
+  if (aIncludeResponsiveness) {
+    mResponsiveness.emplace(aEventTarget, aThreadInfo->IsMainThread());
+  }
 }
 
 ProfiledThreadData::~ProfiledThreadData()
 {
   MOZ_COUNT_DTOR(ProfiledThreadData);
 }
 
 void
--- a/tools/profiler/core/ProfiledThreadData.h
+++ b/tools/profiler/core/ProfiledThreadData.h
@@ -37,17 +37,18 @@
 // If that happens, NotifyUnregistered() is called.
 //
 // This class is the right place to store buffer positions. Profiler buffer
 // positions become invalid if the profiler buffer is destroyed, which happens
 // when the profiler is stopped.
 class ProfiledThreadData final
 {
 public:
-  ProfiledThreadData(ThreadInfo* aThreadInfo, nsIEventTarget* aEventTarget);
+  ProfiledThreadData(ThreadInfo* aThreadInfo, nsIEventTarget* aEventTarget,
+                     bool aIncludeResponsiveness);
   ~ProfiledThreadData();
 
   void NotifyUnregistered(uint64_t aBufferPosition)
   {
     mResponsiveness.reset();
     mLastSample = mozilla::Nothing();
     MOZ_ASSERT(!mBufferPositionWhenReceivedJSContext,
                "JSContext should have been cleared before the thread was unregistered");
@@ -58,18 +59,18 @@ public:
 
   mozilla::Maybe<uint64_t>& LastSample() { return mLastSample; }
 
   void StreamJSON(const ProfileBuffer& aBuffer, JSContext* aCx,
                   SpliceableJSONWriter& aWriter,
                   const mozilla::TimeStamp& aProcessStartTime,
                   double aSinceTime);
 
-  // Returns nullptr if this is not the main thread or if this thread is not
-  // being profiled.
+  // Returns nullptr if this is not the main thread, the responsiveness
+  // feature is not turned on, or if this thread is not being profiled.
   ThreadResponsiveness* GetThreadResponsiveness()
   {
     ThreadResponsiveness* responsiveness = mResponsiveness.ptrOr(nullptr);
     return responsiveness;
   }
 
   const RefPtr<ThreadInfo> Info() const { return mThreadInfo; }
 
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -2084,17 +2084,20 @@ SamplerThread::Run()
               ActivePS::Buffer(lock).DuplicateLastSample(
                 info->ThreadId(), CorePS::ProcessStartTime(),
                 profiledThreadData->LastSample());
             if (dup_ok) {
               continue;
             }
           }
 
-          profiledThreadData->GetThreadResponsiveness()->Update();
+          ThreadResponsiveness* resp = profiledThreadData->GetThreadResponsiveness();
+          if (resp) {
+            resp->Update();
+          }
 
           TimeStamp now = TimeStamp::Now();
           SuspendAndSampleAndResumeThread(lock, *registeredThread,
                                           [&](const Registers& aRegs) {
             DoPeriodicSample(lock, *registeredThread, *profiledThreadData, now,
                              aRegs, rssMemory, ussMemory);
           });
         }
@@ -2264,17 +2267,18 @@ locked_register_thread(PSLockRef aLock, 
 
   TLSRegisteredThread::SetRegisteredThread(aLock, registeredThread.get());
 
   if (ActivePS::Exists(aLock) &&
       ActivePS::ShouldProfileThread(aLock, info)) {
     nsCOMPtr<nsIEventTarget> eventTarget = registeredThread->GetEventTarget();
     ProfiledThreadData* profiledThreadData =
       ActivePS::AddLiveProfiledThread(aLock, registeredThread.get(),
-        MakeUnique<ProfiledThreadData>(info, eventTarget));
+        MakeUnique<ProfiledThreadData>(info, eventTarget,
+                                       ActivePS::FeatureResponsiveness(aLock)));
 
     if (ActivePS::FeatureJS(aLock)) {
       // This StartJSSampling() call is on-thread, so we can poll manually to
       // start JS sampling immediately.
       registeredThread->StartJSSampling(
         ActivePS::FeatureTrackOptimizations(aLock));
       registeredThread->PollJSSampling();
       if (registeredThread->GetJSContext()) {
@@ -2866,17 +2870,18 @@ locked_profiler_start(PSLockRef aLock, u
     CorePS::RegisteredThreads(aLock);
   for (auto& registeredThread : registeredThreads) {
     RefPtr<ThreadInfo> info = registeredThread->Info();
 
     if (ActivePS::ShouldProfileThread(aLock, info)) {
       nsCOMPtr<nsIEventTarget> eventTarget = registeredThread->GetEventTarget();
       ProfiledThreadData* profiledThreadData =
         ActivePS::AddLiveProfiledThread(aLock, registeredThread.get(),
-          MakeUnique<ProfiledThreadData>(info, eventTarget));
+          MakeUnique<ProfiledThreadData>(info, eventTarget,
+                                         ActivePS::FeatureResponsiveness(aLock)));
       if (ActivePS::FeatureJS(aLock)) {
         registeredThread->StartJSSampling(
           ActivePS::FeatureTrackOptimizations(aLock));
         if (info->ThreadId() == tid) {
           // We can manually poll the current thread so it starts sampling
           // immediately.
           registeredThread->PollJSSampling();
         } else if (info->IsMainThread()) {
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/tools/profiler/public/GeckoProfiler.h
@@ -117,18 +117,21 @@ class TimeStamp;
   macro(3, "mainthreadio", MainThreadIO) \
   \
   /* Add memory measurements (e.g. RSS). */ \
   macro(4, "memory", Memory) \
   \
   /* Do not include user-identifiable information. */ \
   macro(5, "privacy", Privacy) \
   \
+  /* Collect thread responsiveness information. */ \
+  macro(6, "responsiveness", Responsiveness) \
+  \
   /* Restyle profiling. */ \
-  macro(6, "restyle", Restyle) \
+  macro(7, "restyle", Restyle) \
   \
   /* Take a snapshot of the window on every composition. */ \
   macro(7, "screenshots", Screenshots) \
   \
   /* Walk the C++ stack. Not available on all platforms. */ \
   macro(8, "stackwalk", StackWalk) \
   \
   /* Start profiling with feature TaskTracer. */ \