Bug 1164338 - Move styles markers to be generated in DoProcessRestyles rather than when the Flush_Style queue is flushed. r=smaug,heycam, a=sledru
authorJordan Santell <jsantell@mozilla.com>
Mon, 18 May 2015 16:03:04 -0700
changeset 262380 668917d1cb31732393efab01fa2583a315c81276
parent 262379 d088567ac3133703e428fb36035b9c48292ffba0
child 262381 903c90590b5da28414551b5ee57ae67c8376511d
push id8059
push userbgrinstead@mozilla.com
push dateThu, 28 May 2015 03:50:58 +0000
treeherdermozilla-aurora@b104a8b24b27 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, heycam, sledru
bugs1164338
milestone40.0a2
Bug 1164338 - Move styles markers to be generated in DoProcessRestyles rather than when the Flush_Style queue is flushed. r=smaug,heycam, a=sledru
dom/webidl/ProfileTimelineMarker.webidl
layout/base/RestyleManager.cpp
layout/base/RestyleManager.h
layout/base/RestyleTracker.cpp
layout/base/nsRefreshDriver.cpp
--- a/dom/webidl/ProfileTimelineMarker.webidl
+++ b/dom/webidl/ProfileTimelineMarker.webidl
@@ -20,9 +20,11 @@ dictionary ProfileTimelineMarker {
   DOMString causeName;
   /* For ConsoleTime markers.  */
   object? endStack = null;
   /* For DOMEvent markers.  */
   DOMString type;
   unsigned short eventPhase;
   /* For Paint markers.  */
   sequence<ProfileTimelineLayerRect> rectangles;
+  /* For Style markers. */
+  DOMString restyleHint;
 };
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -4178,17 +4178,16 @@ RestyleManager::StructsToLog()
       }
     }
     initialized = true;
   }
   return structs;
 }
 #endif
 
-#ifdef DEBUG
 /* static */ nsCString
 RestyleManager::RestyleHintToString(nsRestyleHint aHint)
 {
   nsCString result;
   bool any = false;
   const char* names[] = { "Self", "Subtree", "LaterSiblings", "CSSTransitions",
                           "CSSAnimations", "SVGAttrAnimations", "StyleAttribute",
                           "StyleAttribute_Animations", "Force", "ForceDescendants" };
@@ -4211,16 +4210,17 @@ RestyleManager::RestyleHintToString(nsRe
   } else {
     if (!any) {
       result.AppendLiteral("0");
     }
   }
   return result;
 }
 
+#ifdef DEBUG
 /* static */ nsCString
 RestyleManager::ChangeHintToString(nsChangeHint aHint)
 {
   nsCString result;
   bool any = false;
   const char* names[] = {
     "RepaintFrame", "NeedReflow", "ClearAncestorIntrinsics",
     "ClearDescendantIntrinsics", "NeedDirtyReflow", "SyncFrameView",
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -343,18 +343,19 @@ public:
     PostRestyleEventInternal(true);
   }
 
   void FlushOverflowChangedTracker()
   {
     mOverflowChangedTracker.Flush();
   }
 
+  static nsCString RestyleHintToString(nsRestyleHint aHint);
+
 #ifdef DEBUG
-  static nsCString RestyleHintToString(nsRestyleHint aHint);
   static nsCString ChangeHintToString(nsChangeHint aHint);
 #endif
 
 private:
   void PostRestyleEventInternal(bool aForLazyConstruction);
 
 public:
   /**
--- a/layout/base/RestyleTracker.cpp
+++ b/layout/base/RestyleTracker.cpp
@@ -91,16 +91,40 @@ struct RestyleEnumerateData : RestyleTra
 struct RestyleCollector {
   RestyleTracker* tracker;
   RestyleEnumerateData** restyleArrayPtr;
 #ifdef RESTYLE_LOGGING
   uint32_t count;
 #endif
 };
 
+class RestyleTimelineMarker : public TimelineMarker
+{
+public:
+  RestyleTimelineMarker(nsDocShell* aDocShell,
+                        TracingMetadata aMetaData,
+                        nsRestyleHint aRestyleHint)
+    : TimelineMarker(aDocShell, "Styles", aMetaData)
+  {
+    if (aRestyleHint) {
+      mRestyleHint.AssignWithConversion(RestyleManager::RestyleHintToString(aRestyleHint));
+    }
+  }
+
+  virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker) override
+  {
+    if (GetMetaData() == TRACING_INTERVAL_START) {
+      aMarker.mRestyleHint.Construct(mRestyleHint);
+    }
+  }
+
+private:
+  nsAutoString mRestyleHint;
+};
+
 static PLDHashOperator
 CollectRestyles(nsISupports* aElement,
                 nsAutoPtr<RestyleTracker::RestyleData>& aData,
                 void* aRestyleCollector)
 {
   dom::Element* element =
     static_cast<dom::Element*>(aElement);
   RestyleCollector* collector =
@@ -197,16 +221,23 @@ RestyleTracker::ProcessOneRestyle(Elemen
 }
 
 void
 RestyleTracker::DoProcessRestyles()
 {
   PROFILER_LABEL("RestyleTracker", "ProcessRestyles",
     js::ProfileEntry::Category::CSS);
 
+  bool isTimelineRecording = false;
+  nsDocShell* docShell =
+    static_cast<nsDocShell*>(mRestyleManager->PresContext()->GetDocShell());
+  if (docShell) {
+    docShell->GetRecordProfileTimelineMarkers(&isTimelineRecording);
+  }
+
   // Create a ReframingStyleContexts struct on the stack and put it in our
   // mReframingStyleContexts for almost all of the remaining scope of
   // this function.
   //
   // It needs to be *in* scope during BeginProcessingRestyles, which
   // might (if mDoRebuildAllStyleData is true) do substantial amounts of
   // restyle processing.
   //
@@ -306,24 +337,40 @@ RestyleTracker::DoProcessRestyles()
         }
 
         nsAutoPtr<RestyleData> data;
         if (!GetRestyleData(element, data)) {
           LOG_RESTYLE("skipping, already restyled");
           continue;
         }
 
+        if (isTimelineRecording) {
+          mozilla::UniquePtr<TimelineMarker> marker =
+            MakeUnique<RestyleTimelineMarker>(docShell,
+                                              TRACING_INTERVAL_START,
+                                              data->mRestyleHint);
+          docShell->AddProfileTimelineMarker(Move(marker));
+        }
+
 #if defined(MOZ_ENABLE_PROFILER_SPS) && !defined(MOZILLA_XPCOMRT_API)
         Maybe<GeckoProfilerTracingRAII> profilerRAII;
         if (profiler_feature_active("restyle")) {
           profilerRAII.emplace("Paint", "Styles", Move(data->mBacktrace));
         }
 #endif
         ProcessOneRestyle(element, data->mRestyleHint, data->mChangeHint);
         AddRestyleRootsIfAwaitingRestyle(data->mDescendants);
+
+        if (isTimelineRecording) {
+          mozilla::UniquePtr<TimelineMarker> marker =
+            MakeUnique<RestyleTimelineMarker>(docShell,
+                                              TRACING_INTERVAL_END,
+                                              data->mRestyleHint);
+          docShell->AddProfileTimelineMarker(Move(marker));
+        }
       }
 
       if (mHaveLaterSiblingRestyles) {
         // Keep processing restyles for now
         continue;
       }
 
       // Now we only have entries with change hints left.  To be safe in
@@ -354,19 +401,35 @@ RestyleTracker::DoProcessRestyles()
           LOG_RESTYLE_INDENT();
 
 #if defined(MOZ_ENABLE_PROFILER_SPS) && !defined(MOZILLA_XPCOMRT_API)
           Maybe<GeckoProfilerTracingRAII> profilerRAII;
           if (profiler_feature_active("restyle")) {
             profilerRAII.emplace("Paint", "Styles", Move(currentRestyle->mBacktrace));
           }
 #endif
+          if (isTimelineRecording) {
+            mozilla::UniquePtr<TimelineMarker> marker =
+              MakeUnique<RestyleTimelineMarker>(docShell,
+                                                TRACING_INTERVAL_START,
+                                                currentRestyle->mRestyleHint);
+            docShell->AddProfileTimelineMarker(Move(marker));
+          }
+
           ProcessOneRestyle(currentRestyle->mElement,
                             currentRestyle->mRestyleHint,
                             currentRestyle->mChangeHint);
+
+          if (isTimelineRecording) {
+            mozilla::UniquePtr<TimelineMarker> marker =
+              MakeUnique<RestyleTimelineMarker>(docShell,
+                                                TRACING_INTERVAL_END,
+                                                currentRestyle->mRestyleHint);
+            docShell->AddProfileTimelineMarker(Move(marker));
+          }
         }
       }
     }
   }
 
   mRestyleManager->EndProcessingRestyles();
 }
 
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -1657,21 +1657,16 @@ nsRefreshDriver::Tick(int64_t aNowEpoch,
         for (uint32_t j = observers.Length();
              j && mPresContext && mPresContext->GetPresShell(); --j) {
           // Make sure to not process observers which might have been removed
           // during previous iterations.
           nsIPresShell* shell = observers[j - 1];
           if (!mStyleFlushObservers.Contains(shell))
             continue;
 
-          nsRefPtr<nsDocShell> docShell = GetDocShell(shell->GetPresContext());
-          if (docShell) {
-            docShell->AddProfileTimelineMarker("Styles", TRACING_INTERVAL_START);
-          }
-
           if (!tracingStyleFlush) {
             tracingStyleFlush = true;
             profiler_tracing("Paint", "Styles", mStyleCause, TRACING_INTERVAL_START);
             mStyleCause = nullptr;
           }
 
           NS_ADDREF(shell);
           mStyleFlushObservers.RemoveElement(shell);
@@ -1680,20 +1675,16 @@ nsRefreshDriver::Tick(int64_t aNowEpoch,
           // Inform the FontFaceSet that we ticked, so that it can resolve its
           // ready promise if it needs to (though it might still be waiting on
           // a layout flush).
           nsPresContext* presContext = shell->GetPresContext();
           if (presContext) {
             presContext->NotifyFontFaceSetOnRefresh();
           }
           NS_RELEASE(shell);
-
-          if (docShell) {
-            docShell->AddProfileTimelineMarker("Styles", TRACING_INTERVAL_END);
-          }
         }
 
         if (tracingStyleFlush) {
           profiler_tracing("Paint", "Styles", TRACING_INTERVAL_END);
         }
       }
 
       if (!nsLayoutUtils::AreAsyncAnimationsEnabled()) {