Bug 1357849 - Instrument performance.measure with markers; r?mstange
MozReview-Commit-ID: KQcQgxYyEYi
--- 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,