Bug 1419679 - Keep track of tabs awakenings in the Scheduler - r?mystor
MozReview-Commit-ID: WA0WkQZExO
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -40,16 +40,17 @@
#include "mozilla/dom/ScriptSettings.h"
#include "nsICrashReporter.h"
#include "nsThreadSyncDispatch.h"
#include "nsServiceManagerUtils.h"
#include "GeckoProfiler.h"
#include "InputEventStatistics.h"
#include "ThreadEventTarget.h"
+#include "mozilla/dom/TabGroup.h"
#include "mozilla/dom/ContentChild.h"
#ifdef XP_LINUX
#include <sys/time.h>
#include <sys/resource.h>
#include <sched.h>
#endif
@@ -878,16 +879,30 @@ void canary_alarm_handler(int signum)
while (iter_.HasMore()) { \
obs_ = iter_.GetNext(); \
obs_ -> func_ params_ ; \
} \
} \
} while(0)
#ifndef RELEASE_OR_BETA
+static nsPIDOMWindowOuter* GetTLWindow(nsIRunnable* aEvent) {
+ if (RefPtr<SchedulerGroup::Runnable> groupRunnable = do_QueryObject(aEvent)) {
+ mozilla::dom::TabGroup* group = groupRunnable->Group()->AsTabGroup();
+ if (!group) {
+ return nullptr;
+ }
+ nsTArray<nsPIDOMWindowOuter*> toplevelWindows = group->GetTopLevelWindows();
+ if (toplevelWindows.Length() > 0) {
+ return toplevelWindows[0];
+ }
+ }
+ return nullptr;
+}
+
static bool
GetLabeledRunnableName(nsIRunnable* aEvent, nsACString& aName)
{
bool labeled = false;
if (RefPtr<SchedulerGroup::Runnable> groupRunnable = do_QueryObject(aEvent)) {
labeled = true;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(groupRunnable->GetName(aName)));
} else if (nsCOMPtr<nsINamed> named = do_QueryInterface(aEvent)) {
@@ -972,16 +987,23 @@ nsThread::ProcessNextEvent(bool aMayWait
if (MAIN_THREAD == mIsMainThread) {
HangMonitor::NotifyActivity();
}
#ifndef RELEASE_OR_BETA
Maybe<Telemetry::AutoTimer<Telemetry::MAIN_THREAD_RUNNABLE_MS>> timer;
Maybe<Telemetry::AutoTimer<Telemetry::IDLE_RUNNABLE_BUDGET_OVERUSE_MS>> idleTimer;
+ // looking at which window gets awaken
+ nsPIDOMWindowOuter* win = GetTLWindow(event);
+ if (win) {
+ LOG(("Tab group window id %d\n", win->WindowID()));
+ // XXX here, we want to increment a counter per window ID
+ }
+
nsAutoCString name;
if ((MAIN_THREAD == mIsMainThread) || mNextIdleDeadline) {
bool labeled = GetLabeledRunnableName(event, name);
if (MAIN_THREAD == mIsMainThread) {
timer.emplace(name);
// High-priority runnables are ignored here since they'll run right away