Bug 1435091 - p3. profiler_thread_is_being_profiled() - r=mstange
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 19 Nov 2018 17:41:09 +0000
changeset 503860 46d2f807824a82c2fb104122b98c67547d0bd328
parent 503859 a8d4a90124562be5adad841cd5fbbca834185f9a
child 503861 02d02cae92cd78f17789bba914134955aa7b96c1
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1435091
milestone65.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 1435091 - p3. profiler_thread_is_being_profiled() - r=mstange profiler_thread_is_being_profiled() checks if the profiler is active (quick inline atomic check) and if the current thread is being profiled (function call doing a TLS-atomic check). This may be used instead of profiler_is_active() for thread-specific recordings (e.g.: markers). Differential Revision: https://phabricator.services.mozilla.com/D11307
tools/profiler/core/platform.cpp
tools/profiler/public/GeckoProfiler.h
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -3635,16 +3635,26 @@ profiler_thread_wake()
   if (!racyRegisteredThread) {
     return;
   }
 
   racyRegisteredThread->SetAwake();
 }
 
 bool
+mozilla::profiler::detail::IsThreadBeingProfiled()
+{
+  MOZ_RELEASE_ASSERT(CorePS::Exists());
+
+  const RacyRegisteredThread* racyRegisteredThread =
+    TLSRegisteredThread::RacyRegisteredThread();
+  return racyRegisteredThread && racyRegisteredThread->IsBeingProfiled();
+}
+
+bool
 profiler_thread_is_sleeping()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(CorePS::Exists());
 
   RacyRegisteredThread* racyRegisteredThread =
     TLSRegisteredThread::RacyRegisteredThread();
   if (!racyRegisteredThread) {
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/tools/profiler/public/GeckoProfiler.h
@@ -222,16 +222,18 @@ private:
 
   // We combine the active bit with the feature bits so they can be read or
   // written in a single atomic operation. Accesses to this atomic are not
   // recorded by web replay as they may occur at non-deterministic points.
   static mozilla::Atomic<uint32_t, mozilla::MemoryOrdering::Relaxed,
                          recordreplay::Behavior::DontPreserve> sActiveAndFeatures;
 };
 
+bool IsThreadBeingProfiled();
+
 } // namespace detail
 } // namespace profiler
 } // namespace mozilla
 
 //---------------------------------------------------------------------------
 // Start and stop the profiler
 //---------------------------------------------------------------------------
 
@@ -389,16 +391,24 @@ void profiler_clear_js_context();
 // expensive data will end up being created but not used if another thread
 // stops the profiler between the CreateExpensiveData() and PROFILER_OPERATION
 // calls.
 inline bool profiler_is_active()
 {
   return mozilla::profiler::detail::RacyFeatures::IsActive();
 }
 
+// Is the profiler active, and is the current thread being profiled?
+// (Same caveats and recommented usage as profiler_is_active().)
+inline bool profiler_thread_is_being_profiled()
+{
+  return profiler_is_active() &&
+         mozilla::profiler::detail::IsThreadBeingProfiled();
+}
+
 // Is the profiler active and paused? Returns false if the profiler is inactive.
 bool profiler_is_paused();
 
 // Is the current thread sleeping?
 bool profiler_thread_is_sleeping();
 
 // Get all the features supported by the profiler that are accepted by
 // profiler_start(). The result is the same whether the profiler is active or