Bug 1323100 - Register named threads with the profiler. r?froydnj
MozReview-Commit-ID: FbE4BTcnfEh
--- 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.