From 59203c63bb777a3bacec32fb8830fba33540e809 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:29 +0200 Subject: Adding upstream version 127.0. Signed-off-by: Daniel Baumann --- dom/performance/Performance.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'dom/performance/Performance.cpp') 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 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 = new PerformanceMeasure( GetParentObject(), aName, startTime, endTime, detail); InsertUserEntry(performanceMeasure); -- cgit v1.2.3