Bug 1419679 - Keep track of tabs awakenings in the Scheduler - r?mystor draft
authorTarek Ziadé <tarek@mozilla.com>
Thu, 07 Dec 2017 09:55:23 +0100
changeset 708846 b4e1d9ac18c5bae66a54f89cc86991c6d380c107
parent 707931 f2b3bed28c503dd0b77330646d8cb3e1f0dbbf93
child 724045 7ffbc760b9c8d70b9784d7b0abaaaad235ef9a3b
child 724061 1f633dfd00ad0a1c4a616831361225d783c6a182
child 737860 a970d8013133ba02887bbc6bdf06d8a034b0176f
child 751971 9c13d34cd82ff5be38e281b7ce7d5e2c647538b4
push id92472
push usertziade@mozilla.com
push dateThu, 07 Dec 2017 08:56:34 +0000
reviewersmystor
bugs1419679
milestone59.0a1
Bug 1419679 - Keep track of tabs awakenings in the Scheduler - r?mystor MozReview-Commit-ID: WA0WkQZExO
xpcom/threads/nsThread.cpp
--- 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