Bug 1323100 - Register named threads with the profiler. r?froydnj draft
authorMarkus Stange <mstange@themasta.com>
Wed, 14 Dec 2016 19:50:11 -0500
changeset 456887 538c90d86790431b7b96d99a7a32b317c7cc86d0
parent 456886 16f75b1ed9f65b89a4b8418b7e4a14240a35331d
child 456888 eed035cb94dbbe2d31341c45250cfd41b9e5d9bf
push id40636
push userbmo:mstange@themasta.com
push dateFri, 06 Jan 2017 12:38:48 +0000
reviewersfroydnj
bugs1323100
milestone53.0a1
Bug 1323100 - Register named threads with the profiler. r?froydnj MozReview-Commit-ID: FbE4BTcnfEh
xpcom/threads/nsThread.cpp
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -33,16 +33,17 @@
 #include "mozilla/ChaosMode.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "nsIIdlePeriod.h"
 #include "nsIIncrementalRunnable.h"
 #include "nsThreadSyncDispatch.h"
 #include "LeakRefPtr.h"
+#include "GeckoProfiler.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsServiceManagerUtils.h"
 #include "nsICrashReporter.h"
 #include "mozilla/dom/ContentChild.h"
 #endif
 
 #ifdef XP_LINUX
@@ -441,24 +442,28 @@ struct ThreadInitData {
 
 }
 
 /*static*/ void
 nsThread::ThreadFunc(void* aArg)
 {
   using mozilla::ipc::BackgroundChild;
 
+  char stackTop;
+
   ThreadInitData* initData = static_cast<ThreadInitData*>(aArg);
   nsThread* self = initData->thread;  // strong reference
 
   self->mThread = PR_GetCurrentThread();
   SetupCurrentThreadForChaosMode();
 
   if (initData->name.Length() > 0) {
     PR_SetCurrentThreadName(initData->name.BeginReading());
+
+    profiler_register_thread(initData->name.BeginReading(), &stackTop);
   }
 
   // Inform the ThreadManager
   nsThreadManager::get().RegisterCurrentThread(*self);
 
   mozilla::IOInterposer::RegisterCurrentThread();
 
   // Wait for and process startup event
@@ -514,16 +519,18 @@ nsThread::ThreadFunc(void* aArg)
     }
   }
 
   mozilla::IOInterposer::UnregisterCurrentThread();
 
   // Inform the threadmanager that this thread is going away
   nsThreadManager::get().UnregisterCurrentThread(*self);
 
+  profiler_unregister_thread();
+
   // Dispatch shutdown ACK
   NotNull<nsThreadShutdownContext*> context =
     WrapNotNull(self->mShutdownContext);
   MOZ_ASSERT(context->mTerminatingThread == self);
   event = do_QueryObject(new nsThreadShutdownAckEvent(context));
   context->mJoiningThread->Dispatch(event, NS_DISPATCH_NORMAL);
 
   // Release any observer of the thread here.