summaryrefslogtreecommitdiffstats
path: root/dom/performance/Performance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/performance/Performance.cpp')
-rw-r--r--dom/performance/Performance.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp
index ce2557100d..070bca9ec4 100644
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -33,6 +33,7 @@
#include "mozilla/dom/PerformanceObserverBinding.h"
#include "mozilla/dom/PerformanceNavigationTiming.h"
#include "mozilla/IntegerPrintfMacros.h"
+#include "mozilla/Perfetto.h"
#include "mozilla/Preferences.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/WorkerPrivate.h"
@@ -764,6 +765,25 @@ already_AddRefed<PerformanceMeasure> Performance::Measure(
detail.setNull();
}
+#ifdef MOZ_PERFETTO
+ // Perfetto requires that events are properly nested within each category.
+ // Since this is not a guarantee here, we need to define a dynamic category
+ // for each measurement so it's not prematurely ended by another measurement
+ // that overlaps. We also use the usertiming category to guard these markers
+ // so it's easy to toggle.
+ if (TRACE_EVENT_CATEGORY_ENABLED("usertiming")) {
+ NS_ConvertUTF16toUTF8 str(aName);
+ perfetto::DynamicCategory category{str.get()};
+ TimeStamp startTimeStamp =
+ CreationTimeStamp() + TimeDuration::FromMilliseconds(startTime);
+ TimeStamp endTimeStamp =
+ CreationTimeStamp() + TimeDuration::FromMilliseconds(endTime);
+ PERFETTO_TRACE_EVENT_BEGIN(category, perfetto::DynamicString{str.get()},
+ startTimeStamp);
+ PERFETTO_TRACE_EVENT_END(category, endTimeStamp);
+ }
+#endif
+
RefPtr<PerformanceMeasure> performanceMeasure = new PerformanceMeasure(
GetParentObject(), aName, startTime, endTime, detail);
InsertUserEntry(performanceMeasure);