Bug 1184376 - Remove nsDocShell::AddProfileTimelineMarker, r=smaug
authorVictor Porof <vporof@mozilla.com>
Sat, 18 Jul 2015 09:35:59 -0400
changeset 253563 577738eb609739ea893b84bd3421adffad20fc0d
parent 253562 a40f98f08e6b5bb959be8d12fdfd1c2f9824b795
child 253564 7c8dd116e5835d6a6d3760833c59f522b4115a2c
push id29070
push userttaubert@mozilla.com
push dateMon, 20 Jul 2015 07:15:19 +0000
treeherdermozilla-central@202e9233d130 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1184376
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1184376 - Remove nsDocShell::AddProfileTimelineMarker, r=smaug
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/timeline/AutoGlobalTimelineMarker.cpp
docshell/base/timeline/AutoGlobalTimelineMarker.h
docshell/base/timeline/AutoTimelineMarker.cpp
docshell/base/timeline/TimelineConsumers.cpp
docshell/base/timeline/TimelineConsumers.h
dom/base/Console.cpp
dom/events/EventListenerManager.cpp
layout/base/FrameLayerBuilder.cpp
layout/base/RestyleTracker.cpp
layout/base/nsPresShell.cpp
layout/base/nsRefreshDriver.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -2930,20 +2930,20 @@ nsDocShell::HistoryTransactionRemoved(in
 }
 
 NS_IMETHODIMP
 nsDocShell::SetRecordProfileTimelineMarkers(bool aValue)
 {
   bool currentValue = nsIDocShell::GetRecordProfileTimelineMarkers();
   if (currentValue != aValue) {
     if (aValue) {
-      TimelineConsumers::AddConsumer(this, mObserved);
+      TimelineConsumers::AddConsumer(this);
       UseEntryScriptProfiling();
     } else {
-      TimelineConsumers::RemoveConsumer(this, mObserved);
+      TimelineConsumers::RemoveConsumer(this);
       UnuseEntryScriptProfiling();
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -3082,33 +3082,16 @@ nsresult
 nsDocShell::Now(DOMHighResTimeStamp* aWhen)
 {
   bool ignore;
   *aWhen =
     (TimeStamp::Now() - TimeStamp::ProcessCreation(ignore)).ToMilliseconds();
   return NS_OK;
 }
 
-void
-nsDocShell::AddProfileTimelineMarker(const char* aName,
-                                     TracingMetadata aMetaData)
-{
-  if (IsObserved()) {
-    mObserved->AddMarker(aName, aMetaData);
-  }
-}
-
-void
-nsDocShell::AddProfileTimelineMarker(UniquePtr<TimelineMarker>&& aMarker)
-{
-  if (IsObserved()) {
-    mObserved->AddMarker(Move(aMarker));
-  }
-}
-
 NS_IMETHODIMP
 nsDocShell::SetWindowDraggingAllowed(bool aValue)
 {
   nsRefPtr<nsDocShell> parent = GetParentDocshell();
   if (!aValue && mItemType == typeChrome && !parent) {
     // Window dragging is always allowed for top level
     // chrome docshells.
     return NS_ERROR_FAILURE;
@@ -13965,30 +13948,30 @@ nsDocShell::NotifyJSRunToCompletionStart
   bool timelineOn = nsIDocShell::GetRecordProfileTimelineMarkers();
 
   // If first start, mark interval start.
   if (timelineOn && mJSRunToCompletionDepth == 0) {
     mozilla::UniquePtr<TimelineMarker> marker =
       MakeUnique<JavascriptTimelineMarker>(this, "Javascript", aReason,
                                            aFunctionName, aFilename,
                                            aLineNumber);
-    AddProfileTimelineMarker(Move(marker));
+    TimelineConsumers::AddMarkerForDocShell(this, Move(marker));
   }
   mJSRunToCompletionDepth++;
 }
 
 void
 nsDocShell::NotifyJSRunToCompletionStop()
 {
   bool timelineOn = nsIDocShell::GetRecordProfileTimelineMarkers();
 
   // If last stop, mark interval end.
   mJSRunToCompletionDepth--;
   if (timelineOn && mJSRunToCompletionDepth == 0) {
-    AddProfileTimelineMarker("Javascript", TRACING_INTERVAL_END);
+    TimelineConsumers::AddMarkerForDocShell(this, "Javascript", TRACING_INTERVAL_END);
   }
 }
 
 void
 nsDocShell::MaybeNotifyKeywordSearchLoading(const nsString& aProvider,
                                             const nsString& aKeyword)
 {
   if (aProvider.IsEmpty()) {
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -253,27 +253,33 @@ public:
 
   // Notify Scroll observers when an async panning/zooming transform
   // has started being applied
   void NotifyAsyncPanZoomStarted();
   // Notify Scroll observers when an async panning/zooming transform
   // is no longer applied
   void NotifyAsyncPanZoomStopped();
 
-  // Add new profile timeline markers to this docShell. This will only add
-  // markers if the docShell is currently recording profile timeline markers.
-  // See nsIDocShell::recordProfileTimelineMarkers
-  void AddProfileTimelineMarker(const char* aName, TracingMetadata aMetaData);
-  void AddProfileTimelineMarker(mozilla::UniquePtr<TimelineMarker>&& aMarker);
-
 private:
   // An observed docshell wrapper is created when recording markers is enabled.
   mozilla::UniquePtr<mozilla::ObservedDocShell> mObserved;
   bool IsObserved() const { return !!mObserved; }
 
+  // It is necessary to allow adding a timeline marker wherever a docshell
+  // instance is available. This operation happens frequently and needs to
+  // be very fast, so instead of using a Map or having to search for some
+  // docshell-specific markers storage, a pointer to an `ObservedDocShell` is
+  // is stored on docshells directly.
+  friend void mozilla::TimelineConsumers::AddConsumer(nsDocShell* aDocShell);
+  friend void mozilla::TimelineConsumers::RemoveConsumer(nsDocShell* aDocShell);
+  friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
+    nsDocShell* aDocShell, UniquePtr<TimelineMarker>&& aMarker);
+  friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
+    nsDocShell* aDocShell, const char* aName, TracingMetadata aMetaData);
+
 public:
   // Tell the favicon service that aNewURI has the same favicon as aOldURI.
   static void CopyFavicon(nsIURI* aOldURI,
                           nsIURI* aNewURI,
                           bool aInPrivateBrowsing);
 
 protected:
   virtual ~nsDocShell();
--- a/docshell/base/timeline/AutoGlobalTimelineMarker.cpp
+++ b/docshell/base/timeline/AutoGlobalTimelineMarker.cpp
@@ -3,53 +3,35 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/AutoGlobalTimelineMarker.h"
 
 #include "mozilla/TimelineConsumers.h"
 #include "MainThreadUtils.h"
-#include "nsDocShell.h"
 
 namespace mozilla {
 
 AutoGlobalTimelineMarker::AutoGlobalTimelineMarker(const char* aName
                                                    MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
   : mName(aName)
-  , mDocShells()
-  , mDocShellsRetrieved(false)
 {
   MOZ_GUARD_OBJECT_NOTIFIER_INIT;
   MOZ_ASSERT(NS_IsMainThread());
 
   if (TimelineConsumers::IsEmpty()) {
     return;
   }
 
-  mDocShellsRetrieved = TimelineConsumers::GetKnownDocShells(mDocShells);
-  if (!mDocShellsRetrieved) {
-    // If we don't successfully populate our vector with *all* docshells being
-    // observed, don't add markers to *any* of them.
-    return;
-  }
-
-  for (Vector<nsRefPtr<nsDocShell>>::Range range = mDocShells.all();
-       !range.empty();
-       range.popFront()) {
-    range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_START);
-  }
+  TimelineConsumers::AddMarkerToAllObservedDocShells(mName, TRACING_INTERVAL_START);
 }
 
 AutoGlobalTimelineMarker::~AutoGlobalTimelineMarker()
 {
-  if (!mDocShellsRetrieved) {
+  if (TimelineConsumers::IsEmpty()) {
     return;
   }
 
-  for (Vector<nsRefPtr<nsDocShell>>::Range range = mDocShells.all();
-       !range.empty();
-       range.popFront()) {
-    range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_END);
-  }
+  TimelineConsumers::AddMarkerToAllObservedDocShells(mName, TRACING_INTERVAL_END);
 }
 
 } // namespace mozilla
--- a/docshell/base/timeline/AutoGlobalTimelineMarker.h
+++ b/docshell/base/timeline/AutoGlobalTimelineMarker.h
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_AutoGlobalTimelineMarker_h_
 #define mozilla_AutoGlobalTimelineMarker_h_
 
 #include "mozilla/GuardObjects.h"
-#include "mozilla/Vector.h"
 #include "nsRefPtr.h"
 
 class nsDocShell;
 
 namespace mozilla {
 
 // # AutoGlobalTimelineMarker
 //
@@ -32,22 +31,16 @@ namespace mozilla {
 //     }
 class MOZ_STACK_CLASS AutoGlobalTimelineMarker
 {
   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
 
   // The name of the marker we are adding.
   const char* mName;
 
-  // The set of docshells that will get the marker.
-  Vector<nsRefPtr<nsDocShell>> mDocShells;
-
-  // True as long as no operation has failed, eg due to OOM.
-  bool mDocShellsRetrieved;
-
 public:
   explicit AutoGlobalTimelineMarker(const char* aName
                                     MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
   ~AutoGlobalTimelineMarker();
 
   AutoGlobalTimelineMarker(const AutoGlobalTimelineMarker& aOther) = delete;
   void operator=(const AutoGlobalTimelineMarker& aOther) = delete;
 };
--- a/docshell/base/timeline/AutoTimelineMarker.cpp
+++ b/docshell/base/timeline/AutoTimelineMarker.cpp
@@ -1,43 +1,41 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/AutoTimelineMarker.h"
 
+#include "mozilla/TimelineConsumers.h"
 #include "MainThreadUtils.h"
 #include "nsDocShell.h"
 
 namespace mozilla {
 
 AutoTimelineMarker::AutoTimelineMarker(nsIDocShell* aDocShell, const char* aName
                                        MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
   : mName(aName)
   , mDocShell(nullptr)
 {
   MOZ_GUARD_OBJECT_NOTIFIER_INIT;
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aDocShell);
 
   if (TimelineConsumers::IsEmpty()) {
     return;
   }
 
-  bool isRecordingEnabledForDocShell = false;
-  nsDocShell* docShell = static_cast<nsDocShell*>(aDocShell);
-  aDocShell->GetRecordProfileTimelineMarkers(&isRecordingEnabledForDocShell);
-
-  if (isRecordingEnabledForDocShell) {
-    mDocShell = docShell;
-    mDocShell->AddProfileTimelineMarker(mName, TRACING_INTERVAL_START);
-  }
+  mDocShell = static_cast<nsDocShell*>(aDocShell);
+  TimelineConsumers::AddMarkerForDocShell(mDocShell, mName, TRACING_INTERVAL_START);
 }
 
 AutoTimelineMarker::~AutoTimelineMarker()
 {
-  if (mDocShell) {
-    mDocShell->AddProfileTimelineMarker(mName, TRACING_INTERVAL_END);
+  if (TimelineConsumers::IsEmpty()) {
+    return;
   }
+
+  TimelineConsumers::AddMarkerForDocShell(mDocShell, mName, TRACING_INTERVAL_END);
 }
 
 } // namespace mozilla
--- a/docshell/base/timeline/TimelineConsumers.cpp
+++ b/docshell/base/timeline/TimelineConsumers.cpp
@@ -16,34 +16,36 @@ TimelineConsumers::GetOrCreateObservedDo
 {
   if (!sObservedDocShells) {
     sObservedDocShells = new LinkedList<ObservedDocShell>();
   }
   return *sObservedDocShells;
 }
 
 void
-TimelineConsumers::AddConsumer(nsDocShell* aDocShell,
-                               UniquePtr<ObservedDocShell>& aObservedPtr)
+TimelineConsumers::AddConsumer(nsDocShell* aDocShell)
 {
-  MOZ_ASSERT(!aObservedPtr);
+  UniquePtr<ObservedDocShell>& observed = aDocShell->mObserved;
+
+  MOZ_ASSERT(!observed);
   sActiveConsumers++;
-  aObservedPtr.reset(new ObservedDocShell(aDocShell));
-  GetOrCreateObservedDocShellsList().insertFront(aObservedPtr.get());
+  observed.reset(new ObservedDocShell(aDocShell));
+  GetOrCreateObservedDocShellsList().insertFront(observed.get());
 }
 
 void
-TimelineConsumers::RemoveConsumer(nsDocShell* aDocShell,
-                                  UniquePtr<ObservedDocShell>& aObservedPtr)
+TimelineConsumers::RemoveConsumer(nsDocShell* aDocShell)
 {
-  MOZ_ASSERT(aObservedPtr);
+  UniquePtr<ObservedDocShell>& observed = aDocShell->mObserved;
+
+  MOZ_ASSERT(observed);
   sActiveConsumers--;
-  aObservedPtr.get()->ClearMarkers();
-  aObservedPtr.get()->remove();
-  aObservedPtr.reset(nullptr);
+  observed.get()->ClearMarkers();
+  observed.get()->remove();
+  observed.reset(nullptr);
 }
 
 bool
 TimelineConsumers::IsEmpty()
 {
   return sActiveConsumers == 0;
 }
 
@@ -58,9 +60,51 @@ TimelineConsumers::GetKnownDocShells(Vec
     if (!aStore.append(**rds)) {
       return false;
     }
   }
 
   return true;
 }
 
+void
+TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
+                                        UniquePtr<TimelineMarker>&& aMarker)
+{
+  if (aDocShell->IsObserved()) {
+    aDocShell->mObserved->AddMarker(Move(aMarker));
+  }
+}
+
+void
+TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
+                                        const char* aName, TracingMetadata aMetaData)
+{
+  if (aDocShell->IsObserved()) {
+    aDocShell->mObserved->AddMarker(aName, aMetaData);
+  }
+}
+
+void
+TimelineConsumers::AddMarkerToDocShellsList(Vector<nsRefPtr<nsDocShell>>& aDocShells,
+                                            const char* aName, TracingMetadata aMetaData)
+{
+  for (Vector<nsRefPtr<nsDocShell>>::Range range = aDocShells.all();
+       !range.empty();
+       range.popFront()) {
+    AddMarkerForDocShell(range.front(), aName, aMetaData);
+  }
+}
+
+void
+TimelineConsumers::AddMarkerToAllObservedDocShells(const char* aName, TracingMetadata aMetaData)
+{
+  Vector<nsRefPtr<nsDocShell>> docShells;
+  if (!GetKnownDocShells(docShells)) {
+    // If we don't successfully populate our vector with *all* docshells being
+    // observed, don't add the marker to *any* of them.
+    return;
+  }
+
+  AddMarkerToDocShellsList(docShells, aName, aMetaData);
+}
+
 } // namespace mozilla
--- a/docshell/base/timeline/TimelineConsumers.h
+++ b/docshell/base/timeline/TimelineConsumers.h
@@ -2,36 +2,46 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_TimelineConsumers_h_
 #define mozilla_TimelineConsumers_h_
 
+#include "mozilla/UniquePtr.h"
 #include "mozilla/LinkedList.h"
-#include "mozilla/UniquePtr.h"
+#include "mozilla/Vector.h"
 #include "timeline/ObservedDocShell.h"
 
 class nsDocShell;
 
 namespace mozilla {
 
 class TimelineConsumers
 {
 private:
   // Counter for how many timelines are currently interested in markers.
   static unsigned long sActiveConsumers;
   static LinkedList<ObservedDocShell>* sObservedDocShells;
   static LinkedList<ObservedDocShell>& GetOrCreateObservedDocShellsList();
 
 public:
-  static void AddConsumer(nsDocShell* aDocShell,
-                          UniquePtr<ObservedDocShell>& aObservedPtr);
-  static void RemoveConsumer(nsDocShell* aDocShell,
-                             UniquePtr<ObservedDocShell>& aObservedPtr);
+  static void AddConsumer(nsDocShell* aDocShell);
+  static void RemoveConsumer(nsDocShell* aDocShell);
   static bool IsEmpty();
   static bool GetKnownDocShells(Vector<nsRefPtr<nsDocShell>>& aStore);
+
+  // Methods for adding markers to appropriate docshells. These will only add
+  // markers if the docshell is currently being observed by a timeline.
+  // See nsIDocShell::recordProfileTimelineMarkers
+  static void AddMarkerForDocShell(nsDocShell* aDocShell,
+                                   UniquePtr<TimelineMarker>&& aMarker);
+  static void AddMarkerForDocShell(nsDocShell* aDocShell,
+                                   const char* aName, TracingMetadata aMetaData);
+  static void AddMarkerToDocShellsList(Vector<nsRefPtr<nsDocShell>>& aDocShells,
+                                       const char* aName, TracingMetadata aMetaData);
+  static void AddMarkerToAllObservedDocShells(const char* aName, TracingMetadata aMetaData);
 };
 
 } // namespace mozilla
 
 #endif /* mozilla_TimelineConsumers_h_ */
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -1180,30 +1180,30 @@ Console::Method(JSContext* aCx, MethodNa
         JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
         nsAutoJSString key;
         if (jsString) {
           key.init(aCx, jsString);
         }
 
         mozilla::UniquePtr<TimelineMarker> marker =
           MakeUnique<TimestampTimelineMarker>(docShell, TRACING_TIMESTAMP, key);
-        docShell->AddProfileTimelineMarker(Move(marker));
+        TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
       }
       // For `console.time(foo)` and `console.timeEnd(foo)`
       else if (isTimelineRecording && aData.Length() == 1) {
         JS::Rooted<JS::Value> value(aCx, aData[0]);
         JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
         if (jsString) {
           nsAutoJSString key;
           if (key.init(aCx, jsString)) {
             mozilla::UniquePtr<TimelineMarker> marker =
               MakeUnique<ConsoleTimelineMarker>(docShell,
                                                 aMethodName == MethodTime ? TRACING_INTERVAL_START : TRACING_INTERVAL_END,
                                                 key);
-            docShell->AddProfileTimelineMarker(Move(marker));
+            TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
           }
         }
       }
 
     } else {
       WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
       MOZ_ASSERT(workerPrivate);
 
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1133,28 +1133,28 @@ EventListenerManager::HandleEventInterna
               nsDocShell* ds = static_cast<nsDocShell*>(docShell.get());
               nsAutoString typeStr;
               (*aDOMEvent)->GetType(typeStr);
               uint16_t phase;
               (*aDOMEvent)->GetEventPhase(&phase);
               mozilla::UniquePtr<TimelineMarker> marker =
                 MakeUnique<EventTimelineMarker>(ds, TRACING_INTERVAL_START,
                                                 phase, typeStr);
-              ds->AddProfileTimelineMarker(Move(marker));
+              TimelineConsumers::AddMarkerForDocShell(ds, Move(marker));
             }
           }
 
           if (NS_FAILED(HandleEventSubType(listener, *aDOMEvent,
                                            aCurrentTarget))) {
             aEvent->mFlags.mExceptionHasBeenRisen = true;
           }
 
           if (isTimelineRecording) {
             nsDocShell* ds = static_cast<nsDocShell*>(docShell.get());
-            ds->AddProfileTimelineMarker("DOMEvent", TRACING_INTERVAL_END);
+            TimelineConsumers::AddMarkerForDocShell(ds, "DOMEvent", TRACING_INTERVAL_END);
           }
         }
       }
     }
   }
 
   aEvent->currentTarget = nullptr;
 
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -3070,17 +3070,17 @@ void ContainerState::FinishPaintedLayerD
       // can find and recycle it later.
       ParentLayerIntRect emptyRect;
       data->mLayer->SetClipRect(Some(emptyRect));
       data->mLayer->SetVisibleRegion(nsIntRegion());
       data->mLayer->InvalidateRegion(data->mLayer->GetValidRegion().GetBounds());
       data->mLayer->SetEventRegions(EventRegions());
     }
   }
-  
+
   if (!layer) {
     // We couldn't optimize to an image layer or a color layer above.
     layer = data->mLayer;
     layer->SetClipRect(Nothing());
     FLB_LOG_PAINTED_LAYER_DECISION(data, "  Selected painted layer=%p\n", layer.get());
   }
 
   if (mLayerBuilder->IsBuildingRetainedLayers()) {
@@ -5652,17 +5652,17 @@ FrameLayerBuilder::DrawPaintedLayer(Pain
 
   if (presContext && presContext->GetDocShell() && isActiveLayerManager) {
     nsDocShell* docShell = static_cast<nsDocShell*>(presContext->GetDocShell());
     bool isRecording;
     docShell->GetRecordProfileTimelineMarkers(&isRecording);
     if (isRecording) {
       mozilla::UniquePtr<TimelineMarker> marker =
         MakeUnique<LayerTimelineMarker>(docShell, aRegionToDraw);
-      docShell->AddProfileTimelineMarker(Move(marker));
+      TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
     }
   }
 
   if (!aRegionToInvalidate.IsEmpty()) {
     aLayer->AddInvalidRect(aRegionToInvalidate.GetBounds());
   }
 }
 
--- a/layout/base/RestyleTracker.cpp
+++ b/layout/base/RestyleTracker.cpp
@@ -353,34 +353,34 @@ RestyleTracker::DoProcessRestyles()
           continue;
         }
 
         if (isTimelineRecording) {
           mozilla::UniquePtr<TimelineMarker> marker =
             MakeUnique<RestyleTimelineMarker>(docShell,
                                               TRACING_INTERVAL_START,
                                               data->mRestyleHint);
-          docShell->AddProfileTimelineMarker(Move(marker));
+          TimelineConsumers::AddMarkerForDocShell(docShell, 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));
+          TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
         }
       }
 
       if (mHaveLaterSiblingRestyles) {
         // Keep processing restyles for now
         continue;
       }
 
@@ -417,29 +417,29 @@ RestyleTracker::DoProcessRestyles()
             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));
+            TimelineConsumers::AddMarkerForDocShell(docShell, 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));
+            TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
           }
         }
       }
     }
   }
 
   mRestyleManager->EndProcessingRestyles();
 }
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -8918,17 +8918,17 @@ PresShell::DoReflow(nsIFrame* target, bo
   if (uri)
     uri->GetSpec(docURL);
 
   PROFILER_LABEL_PRINTF("PresShell", "DoReflow",
     js::ProfileEntry::Category::GRAPHICS, "(%s)", docURL.get());
 
   nsDocShell* docShell = static_cast<nsDocShell*>(GetPresContext()->GetDocShell());
   if (docShell) {
-    docShell->AddProfileTimelineMarker("Reflow", TRACING_INTERVAL_START);
+    TimelineConsumers::AddMarkerForDocShell(docShell, "Reflow", TRACING_INTERVAL_START);
   }
 
   if (mReflowContinueTimer) {
     mReflowContinueTimer->Cancel();
     mReflowContinueTimer = nullptr;
   }
 
   nsIFrame* rootFrame = mFrameConstructor->GetRootFrame();
@@ -9095,17 +9095,17 @@ PresShell::DoReflow(nsIFrame* target, bo
       TimeDuration reflowTime = TimeStamp::Now() - timeStart;
       LogTextPerfStats(tp, this, tp->current,
                        reflowTime.ToMilliseconds(), eLog_reflow, nullptr);
     }
     tp->Accumulate();
   }
 
   if (docShell) {
-    docShell->AddProfileTimelineMarker("Reflow", TRACING_INTERVAL_END);
+    TimelineConsumers::AddMarkerForDocShell(docShell, "Reflow", TRACING_INTERVAL_END);
   }
   return !interrupted;
 }
 
 #ifdef DEBUG
 void
 PresShell::DoVerifyReflow()
 {
--- a/layout/base/nsRefreshDriver.cpp
+++ b/layout/base/nsRefreshDriver.cpp
@@ -1814,34 +1814,34 @@ nsRefreshDriver::Tick(int64_t aNowEpoch,
   mPresShellsToInvalidateIfHidden.Clear();
 
   if (mViewManagerFlushIsPending) {
     nsTArray<nsDocShell*> profilingDocShells;
     GetProfileTimelineSubDocShells(GetDocShell(mPresContext), profilingDocShells);
     for (nsDocShell* docShell : profilingDocShells) {
       // For the sake of the profile timeline's simplicity, this is flagged as
       // paint even if it includes creating display lists
-      docShell->AddProfileTimelineMarker("Paint", TRACING_INTERVAL_START);
+      TimelineConsumers::AddMarkerForDocShell(docShell, "Paint", TRACING_INTERVAL_START);
     }
 #ifdef MOZ_DUMP_PAINTING
     if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
       printf_stderr("Starting ProcessPendingUpdates\n");
     }
 #endif
 
     mViewManagerFlushIsPending = false;
     nsRefPtr<nsViewManager> vm = mPresContext->GetPresShell()->GetViewManager();
     vm->ProcessPendingUpdates();
 #ifdef MOZ_DUMP_PAINTING
     if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
       printf_stderr("Ending ProcessPendingUpdates\n");
     }
 #endif
     for (nsDocShell* docShell : profilingDocShells) {
-      docShell->AddProfileTimelineMarker("Paint", TRACING_INTERVAL_END);
+      TimelineConsumers::AddMarkerForDocShell(docShell, "Paint", TRACING_INTERVAL_END);
     }
 
     if (nsContentUtils::XPConnect()) {
       nsContentUtils::XPConnect()->NotifyDidPaint();
       nsJSContext::NotifyDidPaint();
     }
   }