Bug 1357849 - Instrument performance.measure with markers; r=baku,mstange
authorGreg Tatum <tatum.creative@gmail.com>
Mon, 24 Apr 2017 10:15:11 -0500
changeset 403345 4651fc0179ee72e4cd521bb916b9d89409fcd883
parent 403344 2d6216823293868123441dd1484633f420d8e9f0
child 403346 1be01419533eea31443b17fffb91625ca7623aff
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, mstange
bugs1357849
milestone55.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 1357849 - Instrument performance.measure with markers; r=baku,mstange MozReview-Commit-ID: KQcQgxYyEYi
dom/performance/Performance.cpp
tools/profiler/core/ProfilerMarkers.cpp
tools/profiler/public/ProfilerMarkers.h
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -2,16 +2,19 @@
 /* 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 "Performance.h"
 
 #include "GeckoProfiler.h"
+#ifdef MOZ_GECKO_PROFILER
+#include "ProfilerMarkers.h"
+#endif
 #include "PerformanceEntry.h"
 #include "PerformanceMainThread.h"
 #include "PerformanceMark.h"
 #include "PerformanceMeasure.h"
 #include "PerformanceObserver.h"
 #include "PerformanceResourceTiming.h"
 #include "PerformanceService.h"
 #include "PerformanceWorker.h"
@@ -265,19 +268,23 @@ Performance::Mark(const nsAString& aName
     aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     return;
   }
 
   RefPtr<PerformanceMark> performanceMark =
     new PerformanceMark(GetAsISupports(), aName, Now());
   InsertUserEntry(performanceMark);
 
+#ifdef MOZ_GECKO_PROFILER
   if (profiler_is_active()) {
-    PROFILER_MARKER(NS_ConvertUTF16toUTF8(aName).get());
+    PROFILER_MARKER_PAYLOAD("UserTiming",
+                            new UserTimingMarkerPayload(aName,
+                                                        TimeStamp::Now()));
   }
+#endif
 }
 
 void
 Performance::ClearMarks(const Optional<nsAString>& aName)
 {
   ClearUserEntries(aName, NS_LITERAL_STRING("mark"));
 }
 
@@ -349,16 +356,28 @@ Performance::Measure(const nsAString& aN
     }
   } else {
     endTime = Now();
   }
 
   RefPtr<PerformanceMeasure> performanceMeasure =
     new PerformanceMeasure(GetAsISupports(), aName, startTime, endTime);
   InsertUserEntry(performanceMeasure);
+
+#ifdef MOZ_GECKO_PROFILER
+  if (profiler_is_active()) {
+    TimeStamp startTimeStamp = CreationTimeStamp() +
+                               TimeDuration::FromMilliseconds(startTime);
+    TimeStamp endTimeStamp = CreationTimeStamp() +
+                             TimeDuration::FromMilliseconds(endTime);
+    PROFILER_MARKER_PAYLOAD("UserTiming",
+                            new UserTimingMarkerPayload(aName, startTimeStamp,
+                                                        endTimeStamp));
+  }
+#endif
 }
 
 void
 Performance::ClearMeasures(const Optional<nsAString>& aName)
 {
   ClearUserEntries(aName, NS_LITERAL_STRING("measure"));
 }
 
--- a/tools/profiler/core/ProfilerMarkers.cpp
+++ b/tools/profiler/core/ProfilerMarkers.cpp
@@ -152,16 +152,47 @@ IOMarkerPayload::StreamPayload(Spliceabl
 {
   streamCommonProps("io", aWriter, aStartTime, aUniqueStacks);
   aWriter.StringProperty("source", mSource);
   if (mFilename != nullptr) {
     aWriter.StringProperty("filename", mFilename);
   }
 }
 
+UserTimingMarkerPayload::UserTimingMarkerPayload(const nsAString& aName,
+                                                 const mozilla::TimeStamp& aStartTime)
+  : ProfilerMarkerPayload(aStartTime, aStartTime, nullptr)
+  , mEntryType("mark")
+  , mName(aName)
+{
+}
+
+UserTimingMarkerPayload::UserTimingMarkerPayload(const nsAString& aName,
+                                                 const mozilla::TimeStamp& aStartTime,
+                                                 const mozilla::TimeStamp& aEndTime)
+  : ProfilerMarkerPayload(aStartTime, aEndTime, nullptr)
+  , mEntryType("measure")
+  , mName(aName)
+{
+}
+
+UserTimingMarkerPayload::~UserTimingMarkerPayload()
+{
+}
+
+void
+UserTimingMarkerPayload::StreamPayload(SpliceableJSONWriter& aWriter,
+                                       const TimeStamp& aStartTime,
+                                       UniqueStacks& aUniqueStacks)
+{
+  streamCommonProps("UserTiming", aWriter, aStartTime, aUniqueStacks);
+  aWriter.StringProperty("name", NS_ConvertUTF16toUTF8(mName).get());
+  aWriter.StringProperty("entryType", mEntryType);
+}
+
 DOMEventMarkerPayload::DOMEventMarkerPayload(const nsAString& aType, uint16_t aPhase,
                                              const mozilla::TimeStamp& aStartTime,
                                              const mozilla::TimeStamp& aEndTime)
   : ProfilerMarkerPayload(aStartTime, aEndTime, nullptr)
   , mType(aType)
   , mPhase(aPhase)
 {
 }
--- a/tools/profiler/public/ProfilerMarkers.h
+++ b/tools/profiler/public/ProfilerMarkers.h
@@ -134,16 +134,36 @@ public:
                              const mozilla::TimeStamp& aStartTime,
                              UniqueStacks& aUniqueStacks) override;
 
 private:
   nsString mType;
   uint16_t mPhase;
 };
 
+class UserTimingMarkerPayload : public ProfilerMarkerPayload
+{
+public:
+  UserTimingMarkerPayload(const nsAString& aName,
+                          const mozilla::TimeStamp& aStartTime);
+  UserTimingMarkerPayload(const nsAString& aName,
+                          const mozilla::TimeStamp& aStartTime,
+                          const mozilla::TimeStamp& aEndTime);
+  ~UserTimingMarkerPayload();
+
+  virtual void StreamPayload(SpliceableJSONWriter& aWriter,
+                             const mozilla::TimeStamp& aStartTime,
+                             UniqueStacks& aUniqueStacks) override;
+
+private:
+  // Either "mark" or "measure".
+  const char* mEntryType;
+  nsString mName;
+};
+
 /**
  * Contains the translation applied to a 2d layer so we can
  * track the layer position at each frame.
  */
 class LayerTranslationPayload : public ProfilerMarkerPayload
 {
 public:
   LayerTranslationPayload(mozilla::layers::Layer* aLayer,