Bug 1559000 - Enable/disable mozglue's AutoProfilerLabel when Base Profiler starts/stops - r=mstange
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 04 Jul 2019 04:39:08 +0000
changeset 481233 c52f0346e63018272764bcfd879c8390c40a12ac
parent 481232 cb011f546027671fffd2305ad6cadc76fa140828
child 481234 0eaeadceac4798e21105de46acf38ab027c51e4a
push id89173
push usergsquelart@mozilla.com
push dateThu, 04 Jul 2019 09:01:43 +0000
treeherderautoland@c52f0346e630 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1559000
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1559000 - Enable/disable mozglue's AutoProfilerLabel when Base Profiler starts/stops - r=mstange Now that Gecko Profiler only registers its entry&exit functions when running, and it ensures that Base Profiler is stopped beforehand, Base Profiler can now register its own entry&exit functions to capture labels before xpcom starts. Differential Revision: https://phabricator.services.mozilla.com/D34810
mozglue/baseprofiler/core/platform.cpp
--- a/mozglue/baseprofiler/core/platform.cpp
+++ b/mozglue/baseprofiler/core/platform.cpp
@@ -40,16 +40,17 @@
 #  include "RegisteredThread.h"
 #  include "BaseProfilerSharedLibraries.h"
 #  include "ThreadInfo.h"
 #  include "VTuneProfiler.h"
 
 // #include "memory_hooks.h"
 #  include "mozilla/ArrayUtils.h"
 #  include "mozilla/Atomics.h"
+#  include "mozilla/AutoProfilerLabel.h"
 #  include "mozilla/Printf.h"
 #  include "mozilla/Services.h"
 #  include "mozilla/StackWalk.h"
 #  include "mozilla/StaticPtr.h"
 #  include "mozilla/ThreadLocal.h"
 #  include "mozilla/TimeStamp.h"
 #  include "mozilla/Tuple.h"
 #  include "mozilla/UniquePtr.h"
@@ -2614,16 +2615,34 @@ Maybe<ProfilerBufferInfo> profiler_get_b
     return Nothing();
   }
 
   return Some(ProfilerBufferInfo{ActivePS::Buffer(lock).mRangeStart,
                                  ActivePS::Buffer(lock).mRangeEnd,
                                  ActivePS::Capacity(lock).Value()});
 }
 
+// This basically duplicates AutoProfilerLabel's constructor.
+static void* MozGlueBaseLabelEnter(const char* aLabel,
+                                   const char* aDynamicString, void* aSp) {
+  ProfilingStack* profilingStack = AutoProfilerLabel::sProfilingStack.get();
+  if (profilingStack) {
+    profilingStack->pushLabelFrame(aLabel, aDynamicString, aSp,
+                                   ProfilingCategoryPair::OTHER);
+  }
+  return profilingStack;
+}
+
+// This basically duplicates AutoProfilerLabel's destructor.
+static void MozGlueBaseLabelExit(void* sProfilingStack) {
+  if (sProfilingStack) {
+    reinterpret_cast<ProfilingStack*>(sProfilingStack)->pop();
+  }
+}
+
 static void locked_profiler_start(PSLockRef aLock, PowerOfTwo32 aCapacity,
                                   double aInterval, uint32_t aFeatures,
                                   const char** aFilters, uint32_t aFilterCount,
                                   const Maybe<double>& aDuration) {
   if (LOG_TEST) {
     LOG("locked_profiler_start");
     LOG("- capacity  = %d", int(aCapacity.Value()));
     LOG("- duration  = %.2f", aDuration ? *aDuration : -1);
@@ -2673,16 +2692,19 @@ static void locked_profiler_start(PSLock
     if (ActivePS::ShouldProfileThread(aLock, info)) {
       registeredThread->RacyRegisteredThread().SetIsBeingProfiled(true);
       ActivePS::AddLiveProfiledThread(aLock, registeredThread.get(),
                                       MakeUnique<ProfiledThreadData>(info));
       registeredThread->RacyRegisteredThread().ReinitializeOnResume();
     }
   }
 
+  // Setup support for pushing/popping labels in mozglue.
+  RegisterProfilerLabelEnterExit(MozGlueBaseLabelEnter, MozGlueBaseLabelExit);
+
   // At the very end, set up RacyFeatures.
   RacyFeatures::SetActive(ActivePS::Features(aLock));
 }
 
 void profiler_start(PowerOfTwo32 aCapacity, double aInterval,
                     uint32_t aFeatures, const char** aFilters,
                     uint32_t aFilterCount, const Maybe<double>& aDuration) {
   LOG("profiler_start");
@@ -2777,16 +2799,19 @@ static MOZ_MUST_USE SamplerThread* locke
   // At the very start, clear RacyFeatures.
   RacyFeatures::SetInactive();
 
   // TODO: Uninstall memory counter if it is possible from mozglue.
   // #if defined(MOZ_REPLACE_MALLOC) && defined(MOZ_PROFILER_MEMORY)
   //   mozilla::profiler::install_memory_counter(false);
   // #endif
 
+  // Remove support for pushing/popping labels in mozglue.
+  RegisterProfilerLabelEnterExit(nullptr, nullptr);
+
   // Stop sampling live threads.
   const Vector<LiveProfiledThreadData>& liveProfiledThreads =
       ActivePS::LiveProfiledThreads(aLock);
   for (auto& thread : liveProfiledThreads) {
     RegisteredThread* registeredThread = thread.mRegisteredThread;
     registeredThread->RacyRegisteredThread().SetIsBeingProfiled(false);
   }