Bug 1113706 - move TimelineMarker to a new header; r=smaug
authorTom Tromey <tromey@mozilla.com>
Mon, 05 Jan 2015 09:39:16 -0800
changeset 247912 4793ea3d1a21e3f5ab363c99591b689a30abdf60
parent 247911 010c93a343d2f1ad0b18ce0906e867c867b0275b
child 247913 9e27809d4438e7741d628ad38b385ef19126cd73
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1113706
milestone37.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 1113706 - move TimelineMarker to a new header; r=smaug
docshell/base/TimelineMarker.cpp
docshell/base/TimelineMarker.h
docshell/base/moz.build
docshell/base/nsDocShell.h
dom/base/Console.cpp
dom/events/EventListenerManager.cpp
layout/base/FrameLayerBuilder.cpp
new file mode 100644
--- /dev/null
+++ b/docshell/base/TimelineMarker.cpp
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=2 sw=2 tw=80 et:
+ *
+ * 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 "nsDocShell.h"
+#include "TimelineMarker.h"
+
+TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
+                               TracingMetadata aMetaData)
+  : mName(aName)
+  , mMetaData(aMetaData)
+{
+  MOZ_COUNT_CTOR(TimelineMarker);
+  MOZ_ASSERT(aName);
+  aDocShell->Now(&mTime);
+  if (aMetaData == TRACING_INTERVAL_START) {
+    CaptureStack();
+  }
+}
+
+TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
+                               TracingMetadata aMetaData,
+                               const nsAString& aCause)
+  : mName(aName)
+  , mMetaData(aMetaData)
+  , mCause(aCause)
+{
+  MOZ_COUNT_CTOR(TimelineMarker);
+  MOZ_ASSERT(aName);
+  aDocShell->Now(&mTime);
+  if (aMetaData == TRACING_INTERVAL_START) {
+    CaptureStack();
+  }
+}
+
+TimelineMarker::~TimelineMarker()
+{
+  MOZ_COUNT_DTOR(TimelineMarker);
+}
new file mode 100644
--- /dev/null
+++ b/docshell/base/TimelineMarker.h
@@ -0,0 +1,114 @@
+/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=2 sw=2 tw=80 et:
+ *
+ * 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 TimelineMarker_h__
+#define TimelineMarker_h__
+
+#include "nsString.h"
+#include "GeckoProfiler.h"
+#include "mozilla/dom/ProfileTimelineMarkerBinding.h"
+#include "nsContentUtils.h"
+#include "jsapi.h"
+
+class nsDocShell;
+
+// Objects of this type can be added to the timeline.  The class can
+// also be subclassed to let a given marker creator provide custom
+// details.
+class TimelineMarker
+{
+public:
+  TimelineMarker(nsDocShell* aDocShell, const char* aName,
+                 TracingMetadata aMetaData);
+
+  TimelineMarker(nsDocShell* aDocShell, const char* aName,
+                 TracingMetadata aMetaData,
+                 const nsAString& aCause);
+
+  virtual ~TimelineMarker();
+
+  // Check whether two markers should be considered the same,
+  // for the purpose of pairing start and end markers.  Normally
+  // this definition suffices.
+  virtual bool Equals(const TimelineMarker* other)
+  {
+    return strcmp(mName, other->mName) == 0;
+  }
+
+  // Add details specific to this marker type to aMarker.  The
+  // standard elements have already been set.  This method is
+  // called on both the starting and ending markers of a pair.
+  // Ordinarily the ending marker doesn't need to do anything
+  // here.
+  virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker)
+  {
+  }
+
+  virtual void AddLayerRectangles(mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
+  {
+    MOZ_ASSERT_UNREACHABLE("can only be called on layer markers");
+  }
+
+  const char* GetName() const
+  {
+    return mName;
+  }
+
+  TracingMetadata GetMetaData() const
+  {
+    return mMetaData;
+  }
+
+  DOMHighResTimeStamp GetTime() const
+  {
+    return mTime;
+  }
+
+  const nsString& GetCause() const
+  {
+    return mCause;
+  }
+
+  JSObject* GetStack()
+  {
+    if (mStackTrace) {
+      return mStackTrace->get();
+    }
+    return nullptr;
+  }
+
+protected:
+
+  void CaptureStack()
+  {
+    JSContext* ctx = nsContentUtils::GetCurrentJSContext();
+    if (ctx) {
+      JS::RootedObject stack(ctx);
+      if (JS::CaptureCurrentStack(ctx, &stack)) {
+        mStackTrace.emplace(ctx, stack.get());
+      } else {
+        JS_ClearPendingException(ctx);
+      }
+    }
+  }
+
+private:
+
+  const char* mName;
+  TracingMetadata mMetaData;
+  DOMHighResTimeStamp mTime;
+  nsString mCause;
+
+  // While normally it is not a good idea to make a persistent
+  // root, in this case changing nsDocShell to participate in
+  // cycle collection was deemed too invasive, the stack trace
+  // can't actually cause a cycle, and the markers are only held
+  // here temporarily to boot.
+  mozilla::Maybe<JS::PersistentRooted<JSObject*>> mStackTrace;
+};
+
+#endif /* TimelineMarker_h__ */
--- a/docshell/base/moz.build
+++ b/docshell/base/moz.build
@@ -57,16 +57,17 @@ UNIFIED_SOURCES += [
     'nsDocShellEditorData.cpp',
     'nsDocShellEnumerator.cpp',
     'nsDocShellLoadInfo.cpp',
     'nsDocShellTransferableHooks.cpp',
     'nsDownloadHistory.cpp',
     'nsDSURIContentListener.cpp',
     'nsWebNavigationInfo.cpp',
     'SerializedLoadContext.cpp',
+    'TimelineMarker.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -27,16 +27,17 @@
 
 // Helper Classes
 #include "nsCOMPtr.h"
 #include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences
 #include "nsString.h"
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "nsContentUtils.h"
+#include "TimelineMarker.h"
 
 // Threshold value in ms for META refresh based redirects
 #define REFRESH_REDIRECT_TIMER 15000
 
 // Interfaces Needed
 #include "nsIDocCharset.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIRefreshURI.h"
@@ -255,135 +256,16 @@ public:
 
     // Notify Scroll observers when an async panning/zooming transform
     // has started being applied
     void NotifyAsyncPanZoomStarted(const mozilla::CSSIntPoint aScrollPos);
     // Notify Scroll observers when an async panning/zooming transform
     // is no longer applied
     void NotifyAsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos);
 
-    // Objects of this type can be added to the timeline.  The class
-    // can also be subclassed to let a given marker creator provide
-    // custom details.
-    class TimelineMarker
-    {
-    public:
-        TimelineMarker(nsDocShell* aDocShell, const char* aName,
-                       TracingMetadata aMetaData)
-            : mName(aName)
-            , mMetaData(aMetaData)
-        {
-            MOZ_COUNT_CTOR(TimelineMarker);
-            MOZ_ASSERT(aName);
-            aDocShell->Now(&mTime);
-            if (aMetaData == TRACING_INTERVAL_START) {
-                CaptureStack();
-            }
-        }
-
-        TimelineMarker(nsDocShell* aDocShell, const char* aName,
-                       TracingMetadata aMetaData,
-                       const nsAString& aCause)
-            : mName(aName)
-            , mMetaData(aMetaData)
-            , mCause(aCause)
-        {
-            MOZ_COUNT_CTOR(TimelineMarker);
-            MOZ_ASSERT(aName);
-            aDocShell->Now(&mTime);
-            if (aMetaData == TRACING_INTERVAL_START) {
-                CaptureStack();
-            }
-        }
-
-        virtual ~TimelineMarker()
-        {
-            MOZ_COUNT_DTOR(TimelineMarker);
-        }
-
-        // Check whether two markers should be considered the same,
-        // for the purpose of pairing start and end markers.  Normally
-        // this definition suffices.
-        virtual bool Equals(const TimelineMarker* other)
-        {
-            return strcmp(mName, other->mName) == 0;
-        }
-
-        // Add details specific to this marker type to aMarker.  The
-        // standard elements have already been set.  This method is
-        // called on both the starting and ending markers of a pair.
-        // Ordinarily the ending marker doesn't need to do anything
-        // here.
-        virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker)
-        {
-        }
-
-        virtual void AddLayerRectangles(mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
-        {
-            MOZ_ASSERT_UNREACHABLE("can only be called on layer markers");
-        }
-
-        const char* GetName() const
-        {
-            return mName;
-        }
-
-        TracingMetadata GetMetaData() const
-        {
-            return mMetaData;
-        }
-
-        DOMHighResTimeStamp GetTime() const
-        {
-            return mTime;
-        }
-
-        const nsString& GetCause() const
-        {
-            return mCause;
-        }
-
-        JSObject* GetStack()
-        {
-            if (mStackTrace) {
-                return mStackTrace->get();
-            }
-            return nullptr;
-        }
-
-    protected:
-
-        void CaptureStack()
-        {
-            JSContext* ctx = nsContentUtils::GetCurrentJSContext();
-            if (ctx) {
-                JS::RootedObject stack(ctx);
-                if (JS::CaptureCurrentStack(ctx, &stack)) {
-                    mStackTrace.emplace(ctx, stack.get());
-                } else {
-                    JS_ClearPendingException(ctx);
-                }
-            }
-        }
-
-    private:
-
-        const char* mName;
-        TracingMetadata mMetaData;
-        DOMHighResTimeStamp mTime;
-        nsString mCause;
-
-        // While normally it is not a good idea to make a persistent
-        // root, in this case changing nsDocShell to participate in
-        // cycle collection was deemed too invasive, the stack trace
-        // can't actually cause a cycle, and the markers are only held
-        // here temporarily to boot.
-        mozilla::Maybe<JS::PersistentRooted<JSObject*>> mStackTrace;
-    };
-
     // 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);
 
     // Global counter for how many docShells are currently recording profile
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -800,32 +800,32 @@ ReifyStack(nsIStackFrame* aStack, nsTArr
     NS_ENSURE_SUCCESS(rv, rv);
 
     stack.swap(caller);
   }
 
   return NS_OK;
 }
 
-class ConsoleTimelineMarker : public nsDocShell::TimelineMarker
+class ConsoleTimelineMarker : public TimelineMarker
 {
 public:
   ConsoleTimelineMarker(nsDocShell* aDocShell,
                         TracingMetadata aMetaData,
                         const nsAString& aCause)
-    : nsDocShell::TimelineMarker(aDocShell, "ConsoleTime", aMetaData, aCause)
+    : TimelineMarker(aDocShell, "ConsoleTime", aMetaData, aCause)
   {
     if (aMetaData == TRACING_INTERVAL_END) {
       CaptureStack();
     }
   }
 
-  virtual bool Equals(const nsDocShell::TimelineMarker* aOther)
+  virtual bool Equals(const TimelineMarker* aOther)
   {
-    if (!nsDocShell::TimelineMarker::Equals(aOther)) {
+    if (!TimelineMarker::Equals(aOther)) {
       return false;
     }
     // Console markers must have matching causes as well.
     return GetCause() == aOther->GetCause();
   }
 
   virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker)
   {
@@ -964,17 +964,17 @@ Console::Method(JSContext* aCx, MethodNa
       }
 
       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<nsDocShell::TimelineMarker> marker =
+            mozilla::UniquePtr<TimelineMarker> marker =
               MakeUnique<ConsoleTimelineMarker>(docShell,
                                                 aMethodName == MethodTime ? TRACING_INTERVAL_START : TRACING_INTERVAL_END,
                                                 key);
             docShell->AddProfileTimelineMarker(marker);
           }
         }
       }
 
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1019,22 +1019,22 @@ EventListenerManager::GetDocShellForTarg
 
   if (doc) {
     docShell = doc->GetDocShell();
   }
 
   return docShell;
 }
 
-class EventTimelineMarker : public nsDocShell::TimelineMarker
+class EventTimelineMarker : public TimelineMarker
 {
 public:
   EventTimelineMarker(nsDocShell* aDocShell, TracingMetadata aMetaData,
                       uint16_t aPhase, const nsAString& aCause)
-    : nsDocShell::TimelineMarker(aDocShell, "DOMEvent", aMetaData, aCause)
+    : TimelineMarker(aDocShell, "DOMEvent", aMetaData, aCause)
     , mPhase(aPhase)
   {
   }
 
   virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker)
   {
     if (GetMetaData() == TRACING_INTERVAL_START) {
       aMarker.mType.Construct(GetCause());
@@ -1109,17 +1109,17 @@ EventListenerManager::HandleEventInterna
               docShell->GetRecordProfileTimelineMarkers(&isTimelineRecording);
             }
             if (isTimelineRecording) {
               nsDocShell* ds = static_cast<nsDocShell*>(docShell.get());
               nsAutoString typeStr;
               (*aDOMEvent)->GetType(typeStr);
               uint16_t phase;
               (*aDOMEvent)->GetEventPhase(&phase);
-              mozilla::UniquePtr<nsDocShell::TimelineMarker> marker =
+              mozilla::UniquePtr<TimelineMarker> marker =
                 MakeUnique<EventTimelineMarker>(ds, TRACING_INTERVAL_START,
                                                 phase, typeStr);
               ds->AddProfileTimelineMarker(marker);
             }
           }
 
           if (NS_FAILED(HandleEventSubType(listener, *aDOMEvent,
                                            aCurrentTarget))) {
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -4466,21 +4466,21 @@ static void DrawForcedBackgroundColor(Dr
 {
   if (NS_GET_A(aBackgroundColor) > 0) {
     nsIntRect r = aLayer->GetVisibleRegion().GetBounds();
     ColorPattern color(ToDeviceColor(aBackgroundColor));
     aDrawTarget.FillRect(Rect(r.x, r.y, r.width, r.height), color);
   }
 }
 
-class LayerTimelineMarker : public nsDocShell::TimelineMarker
+class LayerTimelineMarker : public TimelineMarker
 {
 public:
   LayerTimelineMarker(nsDocShell* aDocShell, const nsIntRegion& aRegion)
-    : nsDocShell::TimelineMarker(aDocShell, "Layer", TRACING_EVENT)
+    : TimelineMarker(aDocShell, "Layer", TRACING_EVENT)
     , mRegion(aRegion)
   {
   }
 
   ~LayerTimelineMarker()
   {
   }
 
@@ -4648,17 +4648,17 @@ FrameLayerBuilder::DrawPaintedLayer(Pain
     FlashPaint(aContext);
   }
 
   if (presContext && presContext->GetDocShell() && isActiveLayerManager) {
     nsDocShell* docShell = static_cast<nsDocShell*>(presContext->GetDocShell());
     bool isRecording;
     docShell->GetRecordProfileTimelineMarkers(&isRecording);
     if (isRecording) {
-      mozilla::UniquePtr<nsDocShell::TimelineMarker> marker =
+      mozilla::UniquePtr<TimelineMarker> marker =
         MakeUnique<LayerTimelineMarker>(docShell, aRegionToDraw);
       docShell->AddProfileTimelineMarker(marker);
     }
   }
 
   if (!aRegionToInvalidate.IsEmpty()) {
     aLayer->AddInvalidRect(aRegionToInvalidate.GetBounds());
   }