diff --git a/xpcom/tests/gtest/TestThreadUtils.cpp b/xpcom/tests/gtest/TestThreadUtils.cpp index d9eecce911eb..bc973ca2a50c 100644 --- a/xpcom/tests/gtest/TestThreadUtils.cpp +++ b/xpcom/tests/gtest/TestThreadUtils.cpp @@ -170,11 +170,9 @@ static void Expect(const char* aContext, int aCounter, int aMaxExpected) static void ExpectRunnableName(Runnable* aRunnable, const char* aExpectedName) { +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY nsAutoCString name; EXPECT_TRUE(NS_SUCCEEDED(aRunnable->GetName(name))) << "Runnable::GetName()"; -#ifdef RELEASE_OR_BETA - EXPECT_TRUE(name.IsEmpty()) << "Runnable name shall be empty in RELEASE or BETA!"; -#else EXPECT_TRUE(name.EqualsASCII(aExpectedName)) << "Verify Runnable name"; #endif } diff --git a/xpcom/threads/AbstractThread.cpp b/xpcom/threads/AbstractThread.cpp index d38c3170fd40..8567fc913800 100644 --- a/xpcom/threads/AbstractThread.cpp +++ b/xpcom/threads/AbstractThread.cpp @@ -173,6 +173,7 @@ private: return rv; } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHOD GetName(nsACString& aName) override { aName.AssignLiteral("AbstractThread::Runner"); @@ -186,6 +187,7 @@ private: } return NS_OK; } +#endif private: RefPtr mThread; diff --git a/xpcom/threads/SchedulerGroup.cpp b/xpcom/threads/SchedulerGroup.cpp index a395f9d880f5..467b4a05d221 100644 --- a/xpcom/threads/SchedulerGroup.cpp +++ b/xpcom/threads/SchedulerGroup.cpp @@ -384,6 +384,7 @@ SchedulerGroup::Runnable::DocGroup() const return mDocGroup; } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHODIMP SchedulerGroup::Runnable::GetName(nsACString& aName) { @@ -398,6 +399,7 @@ SchedulerGroup::Runnable::GetName(nsACString& aName) return NS_OK; } +#endif NS_IMETHODIMP SchedulerGroup::Runnable::Run() diff --git a/xpcom/threads/SchedulerGroup.h b/xpcom/threads/SchedulerGroup.h index 39e016acde77..69d50776f7c4 100644 --- a/xpcom/threads/SchedulerGroup.h +++ b/xpcom/threads/SchedulerGroup.h @@ -122,7 +122,9 @@ public: SchedulerGroup* Group() const { return mGroup; } dom::DocGroup* DocGroup() const; +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHOD GetName(nsACString& aName) override; +#endif bool IsBackground() const { return mGroup->IsBackground(); } diff --git a/xpcom/threads/ThrottledEventQueue.cpp b/xpcom/threads/ThrottledEventQueue.cpp index ec15d657b681..4698b9e73ac7 100644 --- a/xpcom/threads/ThrottledEventQueue.cpp +++ b/xpcom/threads/ThrottledEventQueue.cpp @@ -80,11 +80,13 @@ class ThrottledEventQueue::Inner final : public nsIObserver return NS_OK; } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHODIMP GetName(nsACString& aName) override { return mInner->CurrentName(aName); } +#endif }; mutable Mutex mMutex; diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index 38e1a1d451ad..c70b3d479551 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -145,7 +145,9 @@ public: return NS_OK; } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHOD GetName(nsACString& aName) override; +#endif nsTimerEvent() : mozilla::CancelableRunnable("nsTimerEvent") @@ -263,6 +265,7 @@ nsTimerEvent::DeleteAllocatorIfNeeded() } } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHODIMP nsTimerEvent::GetName(nsACString& aName) { @@ -272,6 +275,7 @@ nsTimerEvent::GetName(nsACString& aName) mTimer->GetName(aName); return NS_OK; } +#endif NS_IMETHODIMP nsTimerEvent::Run() diff --git a/xpcom/threads/nsProxyRelease.h b/xpcom/threads/nsProxyRelease.h index a0129c0df2f5..98d44ac93577 100644 --- a/xpcom/threads/nsProxyRelease.h +++ b/xpcom/threads/nsProxyRelease.h @@ -44,19 +44,17 @@ public: return Run(); } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHOD GetName(nsACString& aName) override { -#ifdef RELEASE_OR_BETA - aName.Truncate(); -#else if (mName) { aName.Append(nsPrintfCString("ProxyReleaseEvent for %s", mName)); } else { aName.AssignLiteral("ProxyReleaseEvent"); } -#endif return NS_OK; } +#endif private: T* MOZ_OWNING_REF mDoomed; diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index 5544337b2ab3..bfc1c639aa3c 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -900,7 +900,7 @@ void canary_alarm_handler(int signum) } \ } while(0) -#ifndef RELEASE_OR_BETA +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY static bool GetLabeledRunnableName(nsIRunnable* aEvent, nsACString& aName, @@ -1011,7 +1011,7 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult) HangMonitor::NotifyActivity(); } -#ifndef RELEASE_OR_BETA +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY bool schedulerLoggingEnabled = GetSchedulerLoggingEnabled(); if (schedulerLoggingEnabled && mNestedEventLoopDepth > mCurrentEventLoopDepth diff --git a/xpcom/threads/nsThreadUtils.cpp b/xpcom/threads/nsThreadUtils.cpp index e5827cc8e276..478d5710aaeb 100644 --- a/xpcom/threads/nsThreadUtils.cpp +++ b/xpcom/threads/nsThreadUtils.cpp @@ -43,8 +43,8 @@ IdlePeriod::GetIdlePeriodHint(TimeStamp* aIdleDeadline) // NS_IMPL_NAMED_* relies on the mName field, which is not present on // release or beta. Instead, fall back to using "Runnable" for all // runnables. -#ifdef RELEASE_OR_BETA -NS_IMPL_ISUPPORTS(Runnable, nsIRunnable, nsINamed) +#ifndef MOZ_COLLECTING_RUNNABLE_TELEMETRY +NS_IMPL_ISUPPORTS(Runnable, nsIRunnable) #else NS_IMPL_NAMED_ADDREF(Runnable, mName) NS_IMPL_NAMED_RELEASE(Runnable, mName) @@ -58,20 +58,18 @@ Runnable::Run() return NS_OK; } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHODIMP Runnable::GetName(nsACString& aName) { -#ifdef RELEASE_OR_BETA - aName.Truncate(); -#else if (mName) { aName.AssignASCII(mName); } else { aName.Truncate(); } -#endif return NS_OK; } +#endif NS_IMPL_ISUPPORTS_INHERITED(CancelableRunnable, Runnable, nsICancelableRunnable) @@ -102,6 +100,7 @@ PrioritizableRunnable::PrioritizableRunnable(already_AddRefed&& aRu #endif } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHODIMP PrioritizableRunnable::GetName(nsACString& aName) { @@ -112,6 +111,7 @@ PrioritizableRunnable::GetName(nsACString& aName) } return NS_OK; } +#endif NS_IMETHODIMP PrioritizableRunnable::Run() @@ -364,6 +364,7 @@ public: aTarget); } +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHOD GetName(nsACString& aName) override { aName.AssignLiteral("IdleRunnableWrapper"); @@ -377,6 +378,7 @@ public: } return NS_OK; } +#endif private: ~IdleRunnableWrapper() diff --git a/xpcom/threads/nsThreadUtils.h b/xpcom/threads/nsThreadUtils.h index 1bda41cb1ba3..1dfdd06dea20 100644 --- a/xpcom/threads/nsThreadUtils.h +++ b/xpcom/threads/nsThreadUtils.h @@ -425,26 +425,39 @@ enum RunnableKind IdleWithTimer }; +// Implementing nsINamed on Runnable bloats vtables for the hundreds of +// Runnable subclasses that we have, so we want to avoid that overhead +// when we're not using nsINamed for anything. +#ifndef RELEASE_OR_BETA +#define MOZ_COLLECTING_RUNNABLE_TELEMETRY +#endif + // This class is designed to be subclassed. -class Runnable : public nsIRunnable, public nsINamed +class Runnable + : public nsIRunnable +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY + , public nsINamed +#endif { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIRUNNABLE +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_DECL_NSINAMED +#endif Runnable() = delete; -#ifdef RELEASE_OR_BETA - explicit Runnable(const char* aName) {} -#else +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY explicit Runnable(const char* aName) : mName(aName) {} +#else + explicit Runnable(const char* aName) {} #endif protected: virtual ~Runnable() {} -#ifndef RELEASE_OR_BETA +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY const char* mName = nullptr; #endif @@ -503,7 +516,9 @@ public: PrioritizableRunnable(already_AddRefed&& aRunnable, uint32_t aPriority); +#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY NS_IMETHOD GetName(nsACString& aName) override; +#endif NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIRUNNABLE