Bug 1016629 - c. Add define for ThreadStackHelper pseudostack support; r=snorp
authorJim Chen <nchen@mozilla.com>
Mon, 28 Jul 2014 13:30:20 -0400
changeset 219319 8e34e09d49a12a4f660a54ab5bf87e8b124bcba5
parent 219318 76bd2f5fa1f03f23a6899cfe30e3f3884cb64adc
child 219320 a47ff1dae6d2c564e43f8263611cb3f8127dc5c9
push id583
push userbhearsum@mozilla.com
push dateMon, 24 Nov 2014 19:04:58 +0000
treeherdermozilla-release@c107e74250f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1016629
milestone34.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 1016629 - c. Add define for ThreadStackHelper pseudostack support; r=snorp
xpcom/threads/ThreadStackHelper.cpp
xpcom/threads/ThreadStackHelper.h
--- a/xpcom/threads/ThreadStackHelper.cpp
+++ b/xpcom/threads/ThreadStackHelper.cpp
@@ -71,21 +71,20 @@ ThreadStackHelper::Shutdown()
     sigact.sa_handler = SIG_DFL;
     MOZ_ALWAYS_TRUE(!::sigaction(sFillStackSignum, &sigact, nullptr));
   }
   sInitialized--;
 #endif
 }
 
 ThreadStackHelper::ThreadStackHelper()
-  :
-#ifdef MOZ_ENABLE_PROFILER_SPS
-    mPseudoStack(mozilla_get_pseudo_stack()),
+  : mStackToFill(nullptr)
+#ifdef MOZ_THREADSTACKHELPER_PSEUDO
+  , mPseudoStack(mozilla_get_pseudo_stack())
 #endif
-    mStackToFill(nullptr)
   , mMaxStackSize(Stack::sMaxInlineStorage)
   , mMaxBufferSize(0)
 {
 #if defined(XP_LINUX)
   MOZ_ALWAYS_TRUE(!::sem_init(&mSem, 0, 0));
   mThreadID = ::syscall(SYS_gettid);
 #elif defined(XP_WIN)
   mInitialized = !!::DuplicateHandle(
@@ -191,17 +190,17 @@ ThreadStackHelper::FillStackHandler(int 
 
 #endif // XP_LINUX
 
 bool
 ThreadStackHelper::PrepareStackBuffer(Stack& aStack)
 {
   // Return false to skip getting the stack and return an empty stack
   aStack.clear();
-#ifdef MOZ_ENABLE_PROFILER_SPS
+#ifdef MOZ_THREADSTACKHELPER_PSEUDO
   /* Normally, provided the profiler is enabled, it would be an error if we
      don't have a pseudostack here (the thread probably forgot to call
      profiler_register_thread). However, on B2G, profiling secondary threads
      may be disabled despite profiler being enabled. This is by-design and
      is not an error. */
 #ifdef MOZ_WIDGET_GONK
   if (!mPseudoStack) {
     return false;
@@ -214,17 +213,17 @@ ThreadStackHelper::PrepareStackBuffer(St
     return false;
   }
   return true;
 #else
   return false;
 #endif
 }
 
-#ifdef MOZ_ENABLE_PROFILER_SPS
+#ifdef MOZ_THREADSTACKHELPER_PSEUDO
 
 namespace {
 
 bool
 IsChromeJSScript(JSScript* aScript)
 {
   // May be called from another thread or inside a signal handler.
   // We assume querying the script is safe but we must not manipulate it.
@@ -282,24 +281,24 @@ ThreadStackHelper::AppendJSEntry(const v
 
   if (mStackToFill->IsSameAsEntry(aPrevLabel, label)) {
     return aPrevLabel;
   }
   mStackToFill->infallibleAppend(label);
   return label;
 }
 
-#endif // MOZ_ENABLE_PROFILER_SPS
+#endif // MOZ_THREADSTACKHELPER_PSEUDO
 
 void
 ThreadStackHelper::FillStackBuffer()
 {
   MOZ_ASSERT(mStackToFill->empty());
 
-#ifdef MOZ_ENABLE_PROFILER_SPS
+#ifdef MOZ_THREADSTACKHELPER_PSEUDO
   size_t reservedSize = mStackToFill->capacity();
   size_t reservedBufferSize = mStackToFill->AvailableBufferSize();
   intptr_t availableBufferSize = intptr_t(reservedBufferSize);
 
   // Go from front to back
   const volatile StackEntry* entry = mPseudoStack->mStack;
   const volatile StackEntry* end = entry + mPseudoStack->stackSize();
   // Deduplicate identical, consecutive frames
--- a/xpcom/threads/ThreadStackHelper.h
+++ b/xpcom/threads/ThreadStackHelper.h
@@ -18,16 +18,23 @@
 #include <semaphore.h>
 #include <sys/types.h>
 #elif defined(XP_WIN)
 #include <windows.h>
 #elif defined(XP_MACOSX)
 #include <mach/mach.h>
 #endif
 
+// Support pseudostack on these platforms.
+#if defined(XP_LINUX) || defined(XP_WIN) || defined(XP_MACOSX)
+#  ifdef MOZ_ENABLE_PROFILER_SPS
+#    define MOZ_THREADSTACKHELPER_PSEUDO
+#  endif
+#endif
+
 namespace mozilla {
 
 /**
  * ThreadStackHelper is used to retrieve the profiler pseudo-stack of a
  * thread, as an alternative of using the profiler to take a profile.
  * The target thread first declares an ThreadStackHelper instance;
  * then another thread can call ThreadStackHelper::GetStack to retrieve
  * the pseudo-stack of the target thread at that instant.
@@ -36,26 +43,26 @@ namespace mozilla {
  * with custom text and markers are not included.
  */
 class ThreadStackHelper
 {
 public:
   typedef Telemetry::HangStack Stack;
 
 private:
-#ifdef MOZ_ENABLE_PROFILER_SPS
+  Stack* mStackToFill;
+#ifdef MOZ_THREADSTACKHELPER_PSEUDO
   const PseudoStack* const mPseudoStack;
 #endif
-  Stack* mStackToFill;
   size_t mMaxStackSize;
   size_t mMaxBufferSize;
 
   bool PrepareStackBuffer(Stack& aStack);
   void FillStackBuffer();
-#ifdef MOZ_ENABLE_PROFILER_SPS
+#ifdef MOZ_THREADSTACKHELPER_PSEUDO
   const char* AppendJSEntry(const volatile StackEntry* aEntry,
                             intptr_t& aAvailableBufferSize,
                             const char* aPrevLabel);
 #endif
 
 public:
   /**
    * Initialize ThreadStackHelper. Must be called from main thread.