Bug 1620549 - Set stack size of profiler sampler thread to N_STACK_BYTES + 20 KiB r=gerald,mstange
☠☠ backed out by b4599809c6e0 ☠ ☠
authorMichael Forney <mforney@mforney.org>
Mon, 09 Mar 2020 20:23:16 +0000
changeset 517673 4074abe0bef932f76574a45ae15f21775a87fca5
parent 517672 1692426a9549efd97f3241b8fc314eac0786a750
child 517674 b0b0c424297681bebd3df504952795358b0be628
push id37199
push useropoprus@mozilla.com
push dateTue, 10 Mar 2020 03:43:44 +0000
treeherdermozilla-central@6f21f98dcfcd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, mstange
bugs1620549
milestone75.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 1620549 - Set stack size of profiler sampler thread to N_STACK_BYTES + 20 KiB r=gerald,mstange N_STACK_BYTES are needed to store backtrace information, so use that plus some extra as the minimum stack size for the sampler thread to ensure that it doesn't overflow. Differential Revision: https://phabricator.services.mozilla.com/D65705
tools/profiler/core/platform-linux-android.cpp
--- a/tools/profiler/core/platform-linux-android.cpp
+++ b/tools/profiler/core/platform-linux-android.cpp
@@ -377,16 +377,21 @@ static void* ThreadEntry(void* aArg) {
 }
 
 SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
                              double aIntervalMilliseconds)
     : mSampler(aLock),
       mActivityGeneration(aActivityGeneration),
       mIntervalMicroseconds(
           std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5)))) {
+  pthread_attr_t attr;
+  if (pthread_attr_init(&attr) != 0) {
+    MOZ_CRASH("pthread_attr_init failed");
+  }
+
 #if defined(USE_LUL_STACKWALK)
   lul::LUL* lul = CorePS::Lul(aLock);
   if (!lul) {
     CorePS::SetLul(aLock, MakeUnique<lul::LUL>(logging_sink_for_LUL));
     // Read all the unwind info currently available.
     lul = CorePS::Lul(aLock);
     read_procmaps(lul);
 
@@ -396,24 +401,32 @@ SamplerThread::SamplerThread(PSLockRef a
     lul->EnableUnwinding();
 
     // Has a test been requested?
     if (PR_GetEnv("MOZ_PROFILER_LUL_TEST")) {
       int nTests = 0, nTestsPassed = 0;
       RunLulUnitTests(&nTests, &nTestsPassed, lul);
     }
   }
+
+  // N_STACK_BYTES are needed to store backtrace information, so use that plus
+  // some extra as the minimum stack size for the sampler thread to ensure that
+  // it doesn't overflow.
+  if (pthread_attr_setstacksize(&attr, lul::N_STACK_BYTES + 20 * 1024) != 0) {
+    MOZ_CRASH("pthread_attr_setstacksize failed");
+  }
 #endif
 
   // Start the sampling thread. It repeatedly sends a SIGPROF signal. Sending
   // the signal ourselves instead of relying on itimer provides much better
   // accuracy.
-  if (pthread_create(&mThread, nullptr, ThreadEntry, this) != 0) {
+  if (pthread_create(&mThread, &attr, ThreadEntry, this) != 0) {
     MOZ_CRASH("pthread_create failed");
   }
+  pthread_attr_destroy(&attr);
 }
 
 SamplerThread::~SamplerThread() {
   pthread_join(mThread, nullptr);
   // Just in the unlikely case some callbacks were added between the end of the
   // thread and now.
   InvokePostSamplingCallbacks(std::move(mPostSamplingCallbackList),
                               SamplingState::JustStopped);