mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1572337: ensure MainThread is registered with the profiler properly r=gerald
Differential Revision: https://phabricator.services.mozilla.com/D41619 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
6566d92dd4
commit
48ca7ca3d8
@ -6,7 +6,7 @@
|
||||
|
||||
#include "RegisteredThread.h"
|
||||
|
||||
RegisteredThread::RegisteredThread(ThreadInfo* aInfo, nsIEventTarget* aThread,
|
||||
RegisteredThread::RegisteredThread(ThreadInfo* aInfo, nsIThread* aThread,
|
||||
void* aStackTop)
|
||||
: mRacyRegisteredThread(aInfo->ThreadId()),
|
||||
mPlatformData(AllocPlatformData(aInfo->ThreadId())),
|
||||
@ -18,6 +18,9 @@ RegisteredThread::RegisteredThread(ThreadInfo* aInfo, nsIEventTarget* aThread,
|
||||
mJSFlags(0) {
|
||||
MOZ_COUNT_CTOR(RegisteredThread);
|
||||
|
||||
// NOTE: aThread can be null for the first thread, before the ThreadManager
|
||||
// is initialized.
|
||||
|
||||
// We don't have to guess on mac
|
||||
#if defined(GP_OS_darwin)
|
||||
pthread_t self = pthread_self();
|
||||
|
@ -140,7 +140,7 @@ class RacyRegisteredThread final {
|
||||
// protected by the profiler state lock.
|
||||
class RegisteredThread final {
|
||||
public:
|
||||
RegisteredThread(ThreadInfo* aInfo, nsIEventTarget* aThread, void* aStackTop);
|
||||
RegisteredThread(ThreadInfo* aInfo, nsIThread* aThread, void* aStackTop);
|
||||
~RegisteredThread();
|
||||
|
||||
class RacyRegisteredThread& RacyRegisteredThread() {
|
||||
@ -179,6 +179,7 @@ class RegisteredThread final {
|
||||
|
||||
const RefPtr<ThreadInfo> Info() const { return mThreadInfo; }
|
||||
const nsCOMPtr<nsIEventTarget> GetEventTarget() const { return mThread; }
|
||||
void ResetMainThread(nsIThread* aThread) { mThread = aThread; }
|
||||
|
||||
// Request that this thread start JS sampling. JS sampling won't actually
|
||||
// start until a subsequent PollJSSampling() call occurs *and* mContext has
|
||||
@ -254,7 +255,7 @@ class RegisteredThread final {
|
||||
const void* mStackTop;
|
||||
|
||||
const RefPtr<ThreadInfo> mThreadInfo;
|
||||
const nsCOMPtr<nsIEventTarget> mThread;
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
|
||||
// If this is a JS thread, this is its JSContext, which is required for any
|
||||
// JS sampling.
|
||||
|
@ -3222,6 +3222,17 @@ static Vector<const char*> SplitAtCommas(const char* aString,
|
||||
return array;
|
||||
}
|
||||
|
||||
void profiler_init_threadmanager() {
|
||||
LOG("profiler_init_threadmanager");
|
||||
|
||||
PSAutoLock lock(gPSMutex);
|
||||
RegisteredThread* registeredThread =
|
||||
TLSRegisteredThread::RegisteredThread(lock);
|
||||
if (!registeredThread->GetEventTarget()) {
|
||||
registeredThread->ResetMainThread(NS_GetCurrentThreadNoCreate());
|
||||
}
|
||||
}
|
||||
|
||||
void profiler_init(void* aStackTop) {
|
||||
LOG("profiler_init");
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
// avoid the need for many #ifdefs.
|
||||
|
||||
# define AUTO_PROFILER_INIT
|
||||
# define AUTO_PROFILER_INIT2
|
||||
|
||||
# define PROFILER_REGISTER_THREAD(name)
|
||||
# define PROFILER_UNREGISTER_THREAD()
|
||||
@ -300,8 +301,12 @@ static constexpr mozilla::PowerOfTwo32 PROFILER_DEFAULT_STARTUP_ENTRIES =
|
||||
// (except profiler_start(), which will call profiler_init() if it hasn't
|
||||
// already run).
|
||||
void profiler_init(void* stackTop);
|
||||
void profiler_init_threadmanager();
|
||||
|
||||
// Call this as early as possible
|
||||
# define AUTO_PROFILER_INIT mozilla::AutoProfilerInit PROFILER_RAII
|
||||
// Call this after the nsThreadManager is Init()ed
|
||||
# define AUTO_PROFILER_INIT2 mozilla::AutoProfilerInit2 PROFILER_RAII
|
||||
|
||||
// Clean up the profiler module, stopping it if required. This function may
|
||||
// also save a shutdown profile if requested. No profiler calls should happen
|
||||
@ -960,6 +965,17 @@ class MOZ_RAII AutoProfilerInit {
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
class MOZ_RAII AutoProfilerInit2 {
|
||||
public:
|
||||
explicit AutoProfilerInit2(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) {
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
profiler_init_threadmanager();
|
||||
}
|
||||
|
||||
private:
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
// Convenience class to register and unregister a thread with the profiler.
|
||||
// Needs to be the first object on the stack of the thread.
|
||||
class MOZ_RAII AutoProfilerRegisterThread final {
|
||||
|
@ -92,11 +92,14 @@ class BaseProfilerCount {
|
||||
# endif
|
||||
// Can't call profiler_* here since this may be non-xul-library
|
||||
}
|
||||
# ifdef DEBUG
|
||||
~BaseProfilerCount() { mCanary = 0; }
|
||||
# endif
|
||||
|
||||
void Sample(int64_t& aCounter, uint64_t& aNumber) {
|
||||
virtual ~BaseProfilerCount() {
|
||||
# ifdef DEBUG
|
||||
mCanary = 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
virtual void Sample(int64_t& aCounter, uint64_t& aNumber) {
|
||||
MOZ_ASSERT(mCanary == COUNTER_CANARY);
|
||||
|
||||
aCounter = *mCounter;
|
||||
|
@ -324,6 +324,7 @@ NS_InitXPCOM(nsIServiceManager** aResult, nsIFile* aBinDirectory,
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
AUTO_PROFILER_INIT2;
|
||||
|
||||
// Init the SystemGroup for dispatching main thread runnables.
|
||||
SystemGroup::InitStatic();
|
||||
|
Loading…
Reference in New Issue
Block a user