From 778111225d2782f355da1505a7d505cb7420da85 Mon Sep 17 00:00:00 2001 From: Greg Tatum Date: Mon, 24 Apr 2017 10:15:11 -0500 Subject: [PATCH] Bug 1357849 - Instrument performance.measure with markers; r=baku,mstange MozReview-Commit-ID: KQcQgxYyEYi --HG-- extra : rebase_source : bc26048ca4317d11ab22a5a54064fa2c031a9fdc --- dom/performance/Performance.cpp | 21 ++++++++++++++++- tools/profiler/core/ProfilerMarkers.cpp | 31 +++++++++++++++++++++++++ tools/profiler/public/ProfilerMarkers.h | 20 ++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 078bd0124a71..f1d55b3fb72d 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -7,6 +7,9 @@ #include "Performance.h" #include "GeckoProfiler.h" +#ifdef MOZ_GECKO_PROFILER +#include "ProfilerMarkers.h" +#endif #include "PerformanceEntry.h" #include "PerformanceMainThread.h" #include "PerformanceMark.h" @@ -270,9 +273,13 @@ Performance::Mark(const nsAString& aName, ErrorResult& aRv) 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 @@ -354,6 +361,18 @@ Performance::Measure(const nsAString& aName, RefPtr 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 diff --git a/tools/profiler/core/ProfilerMarkers.cpp b/tools/profiler/core/ProfilerMarkers.cpp index 0d1b3942750d..6cf8e6ce69eb 100644 --- a/tools/profiler/core/ProfilerMarkers.cpp +++ b/tools/profiler/core/ProfilerMarkers.cpp @@ -157,6 +157,37 @@ IOMarkerPayload::StreamPayload(SpliceableJSONWriter& aWriter, } } +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) diff --git a/tools/profiler/public/ProfilerMarkers.h b/tools/profiler/public/ProfilerMarkers.h index d787211e4944..0cd1c8ad27c5 100644 --- a/tools/profiler/public/ProfilerMarkers.h +++ b/tools/profiler/public/ProfilerMarkers.h @@ -139,6 +139,26 @@ private: 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.