Bug 1233835 - Fix TaskTracer double init assert. r=mconley draft
authorBenoit Girard <b56girard@gmail.com>
Fri, 18 Dec 2015 16:12:47 -0500
changeset 316431 4e734a428bf22863e5ee6fa44191752c9a8cec77
parent 316430 7cb86451e2c3d98500949ae3bce048e4a07f69ed
child 512167 cecea5409c555c9968dbfb2df62cfd778ee0337d
push id8554
push userb56girard@gmail.com
push dateFri, 18 Dec 2015 21:12:56 +0000
reviewersmconley
bugs1233835
milestone46.0a1
Bug 1233835 - Fix TaskTracer double init assert. r=mconley
tools/profiler/core/platform.cpp
tools/profiler/public/GeckoProfilerImpl.h
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -26,16 +26,20 @@
 #include "nsDirectoryServiceDefs.h"
 #include "nsXULAppAPI.h"
 #include "nsProfilerStartParams.h"
 #include "mozilla/Services.h"
 #include "nsThreadUtils.h"
 #endif
 #include "ProfilerMarkers.h"
 
+#ifdef MOZ_TASK_TRACER
+#include "GeckoTaskTracer.h"
+#endif
+
 #if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
   #include "AndroidBridge.h"
 #endif
 
 #if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
 #include "GeneratedJNINatives.h"
 #endif
 
@@ -453,16 +457,20 @@ mozilla_sampler_log(const char *fmt, va_
 
 void mozilla_sampler_init(void* stackTop)
 {
   sInitCount++;
 
   if (stack_key_initialized)
     return;
 
+#ifdef MOZ_TASK_TRACER
+  mozilla::tasktracer::InitTaskTracer();
+#endif
+
 #ifdef SPS_STANDALONE
   mozilla::TimeStamp::Startup();
 #endif
 
   LOG("BEGIN mozilla_sampler_init");
   if (!tlsPseudoStack.init() || !tlsTicker.init() || !tlsStackTop.init()) {
     LOG("Failed to init.");
     return;
@@ -559,16 +567,20 @@ void mozilla_sampler_shutdown()
 
 #ifdef SPS_STANDALONE
   mozilla::TimeStamp::Shutdown();
 #endif
 
   PseudoStack *stack = tlsPseudoStack.get();
   stack->deref();
   tlsPseudoStack.set(nullptr);
+
+#ifdef MOZ_TASK_TRACER
+  mozilla::tasktracer::ShutdownTaskTracer();
+#endif
 }
 
 void mozilla_sampler_save()
 {
   GeckoSampler *t = tlsTicker.get();
   if (!t) {
     return;
   }
--- a/tools/profiler/public/GeckoProfilerImpl.h
+++ b/tools/profiler/public/GeckoProfilerImpl.h
@@ -17,20 +17,16 @@
 #ifndef SPS_STANDALONE
 #include "nscore.h"
 #include "nsISupports.h"
 #endif
 #include "GeckoProfilerFunc.h"
 #include "PseudoStack.h"
 #include "ProfilerBacktrace.h"
 
-#ifdef MOZ_TASK_TRACER
-#include "GeckoTaskTracer.h"
-#endif
-
 /* QT has a #define for the word "slots" and jsfriendapi.h has a struct with
  * this variable name, causing compilation problems. Alleviate this for now by
  * removing this #define */
 #ifdef MOZ_WIDGET_QT
 #undef slots
 #endif
 
 // Make sure that we can use std::min here without the Windows headers messing with us.
@@ -57,28 +53,22 @@ extern bool stack_key_initialized;
 # else
 #  define SAMPLE_FUNCTION_NAME __func__  // defined in C99, supported in various C++ compilers. Just raw function name.
 # endif
 #endif
 
 static inline
 void profiler_init(void* stackTop)
 {
-#ifdef MOZ_TASK_TRACER
-  mozilla::tasktracer::InitTaskTracer();
-#endif
   mozilla_sampler_init(stackTop);
 }
 
 static inline
 void profiler_shutdown()
 {
-#ifdef MOZ_TASK_TRACER
-  mozilla::tasktracer::ShutdownTaskTracer();
-#endif
   mozilla_sampler_shutdown();
 }
 
 static inline
 void profiler_start(int aProfileEntries, double aInterval,
                     const char** aFeatures, uint32_t aFeatureCount,
                     const char** aThreadNameFilters, uint32_t aFilterCount)
 {