From 95f77c2409dd328e42cd9bb1b3e7cb3c3a2dfe2e Mon Sep 17 00:00:00 2001 From: Gerald Squelart Date: Wed, 4 Sep 2019 07:56:51 +0000 Subject: [PATCH] Bug 1576819 - Use PROFILER_ADD_MARKER{,_WITH_PAYLOAD} everywhere - r=gregtatum All calls to `profiler_add_marker()` (outside of the profilers code) are now replaced by either: - `PROFILER_ADD_MARKER(name, categoryPair)` - `PROFILER_ADD_MARKER_WITH_PAYLOAD(name, categoryPair, TypeOfMarkerPayload, (payload, ..., arguments))` This makes all calls consistent, and they won't need to prefix the category pair with `JS::ProfilingCategoryPair::`. Also it will make it easier to add (and later remove) internal-profiling instrumentation (bug 1576550), and to replace heap-allocated payloads with stack-allocated ones (bug 1576555). Differential Revision: https://phabricator.services.mozilla.com/D43588 --HG-- extra : moz-landing-system : lando --- accessible/generic/Accessible.cpp | 2 +- dom/base/TimeoutManager.cpp | 17 ++++------ dom/base/nsDOMNavigationTiming.cpp | 34 +++++++++---------- dom/events/EventDispatcher.cpp | 18 +++++----- dom/media/mediasink/VideoSink.cpp | 14 ++++---- dom/performance/Performance.cpp | 15 ++++---- gfx/layers/Layers.cpp | 2 +- .../composite/CompositorScreenshotGrabber.cpp | 4 +-- .../composite/ContainerLayerComposite.cpp | 6 ++-- gfx/layers/ipc/CompositorBridgeParent.cpp | 4 +-- gfx/layers/mlgpu/MLGPUScreenshotGrabber.cpp | 4 +-- layout/base/AutoProfilerStyleMarker.h | 10 +++--- modules/libpref/Preferences.cpp | 18 +++++----- mozglue/baseprofiler/public/BaseProfiler.h | 14 ++++++++ .../gecko/ProfilerIOInterposeObserver.cpp | 11 +++--- tools/profiler/gecko/nsProfiler.cpp | 2 +- tools/profiler/public/GeckoProfiler.h | 15 +++++++- tools/profiler/tests/gtest/GeckoProfiler.cpp | 26 ++++++-------- xpcom/base/CycleCollectedJSRuntime.cpp | 26 +++++++------- xpcom/base/Logging.cpp | 5 ++- xpcom/threads/nsThread.cpp | 5 ++- 21 files changed, 130 insertions(+), 122 deletions(-) diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index 583600e51234..4eeb391d5217 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -839,7 +839,7 @@ nsresult Accessible::HandleAccEvent(AccEvent* aEvent) { nsAutoCString strMarker; strMarker.AppendLiteral("A11y Event - "); strMarker.Append(strEventType); - profiler_add_marker(strMarker.get(), JS::ProfilingCategoryPair::OTHER); + PROFILER_ADD_MARKER(strMarker.get(), OTHER); } #endif diff --git a/dom/base/TimeoutManager.cpp b/dom/base/TimeoutManager.cpp index e44ddc0c57e1..387d24711e7d 100644 --- a/dom/base/TimeoutManager.cpp +++ b/dom/base/TimeoutManager.cpp @@ -155,11 +155,9 @@ void TimeoutManager::MoveIdleToActive() { int(elapsed.ToMilliseconds()), int(target.ToMilliseconds()), int(delta.ToMilliseconds())); // don't have end before start... - profiler_add_marker( - "setTimeout deferred release", JS::ProfilingCategoryPair::DOM, - MakeUnique( - marker, delta.ToMilliseconds() >= 0 ? timeout->When() : now, - now)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "setTimeout deferred release", DOM, TextMarkerPayload, + (marker, delta.ToMilliseconds() >= 0 ? timeout->When() : now, now)); } #endif num++; @@ -906,11 +904,10 @@ void TimeoutManager::RunTimeout(const TimeStamp& aNow, int(elapsed.ToMilliseconds()), int(target.ToMilliseconds()), int(delta.ToMilliseconds()), int(runtime.ToMilliseconds())); // don't have end before start... - profiler_add_marker( - "setTimeout", JS::ProfilingCategoryPair::DOM, - MakeUnique( - marker, delta.ToMilliseconds() >= 0 ? timeout->When() : now, - now)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "setTimeout", DOM, TextMarkerPayload, + (marker, delta.ToMilliseconds() >= 0 ? timeout->When() : now, + now)); } #endif diff --git a/dom/base/nsDOMNavigationTiming.cpp b/dom/base/nsDOMNavigationTiming.cpp index f0e3b50a39cb..89d0b676bf18 100644 --- a/dom/base/nsDOMNavigationTiming.cpp +++ b/dom/base/nsDOMNavigationTiming.cpp @@ -165,9 +165,8 @@ void nsDOMNavigationTiming::NotifyLoadEventEnd() { int(elapsed.ToMilliseconds()), int(duration.ToMilliseconds())); DECLARE_DOCSHELL_AND_HISTORY_ID(mDocShell); PAGELOAD_LOG(("%s", marker.get())); - profiler_add_marker( - "DocumentLoad", JS::ProfilingCategoryPair::DOM, - MakeUnique(marker, mNavigationStart, mLoadEventEnd, + PROFILER_ADD_MARKER_WITH_PAYLOAD("DocumentLoad", DOM, TextMarkerPayload, + (marker, mNavigationStart, mLoadEventEnd, docShellId, docShellHistoryId)); } #endif @@ -360,10 +359,9 @@ void nsDOMNavigationTiming::TTITimeout(nsITimer* aTimer) { int(elapsedLongTask.ToMilliseconds()), spec.get()); DECLARE_DOCSHELL_AND_HISTORY_ID(mDocShell); - profiler_add_marker( - "TTFI", JS::ProfilingCategoryPair::DOM, - MakeUnique(marker, mNavigationStart, mTTFI, - docShellId, docShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "TTFI", DOM, TextMarkerPayload, + (marker, mNavigationStart, mTTFI, docShellId, docShellHistoryId)); } #endif return; @@ -395,9 +393,9 @@ void nsDOMNavigationTiming::NotifyNonBlankPaintForRootContentDocument() { "and first non-blank paint"); PAGELOAD_LOG(("%s", marker.get())); DECLARE_DOCSHELL_AND_HISTORY_ID(mDocShell); - profiler_add_marker( - "FirstNonBlankPaint", JS::ProfilingCategoryPair::DOM, - MakeUnique(marker, mNavigationStart, mNonBlankPaint, + PROFILER_ADD_MARKER_WITH_PAYLOAD("FirstNonBlankPaint", DOM, + TextMarkerPayload, + (marker, mNavigationStart, mNonBlankPaint, docShellId, docShellHistoryId)); } #endif @@ -445,10 +443,10 @@ void nsDOMNavigationTiming::NotifyContentfulPaintForRootContentDocument( "and first non-blank paint"); DECLARE_DOCSHELL_AND_HISTORY_ID(mDocShell); PAGELOAD_LOG(("%s", marker.get())); - profiler_add_marker("FirstContentfulPaint", JS::ProfilingCategoryPair::DOM, - MakeUnique( - marker, mNavigationStart, mContentfulPaint, - docShellId, docShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "FirstContentfulPaint", DOM, TextMarkerPayload, + (marker, mNavigationStart, mContentfulPaint, docShellId, + docShellHistoryId)); } #endif @@ -495,10 +493,10 @@ void nsDOMNavigationTiming::NotifyDOMContentFlushedForRootContentDocument() { "and DOMContentFlushed"); DECLARE_DOCSHELL_AND_HISTORY_ID(mDocShell); PAGELOAD_LOG(("%s", marker.get())); - profiler_add_marker("DOMContentFlushed", JS::ProfilingCategoryPair::DOM, - MakeUnique( - marker, mNavigationStart, mDOMContentFlushed, - docShellId, docShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "DOMContentFlushed", DOM, TextMarkerPayload, + (marker, mNavigationStart, mDOMContentFlushed, docShellId, + docShellHistoryId)); } #endif } diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp index 6ff64ba483d3..c6aaee2bbd88 100644 --- a/dom/events/EventDispatcher.cpp +++ b/dom/events/EventDispatcher.cpp @@ -1027,20 +1027,18 @@ nsresult EventDispatcher::Dispatch(nsISupports* aTarget, nsCOMPtr docShell; docShell = nsContentUtils::GetDocShellForEventTarget(aEvent->mTarget); DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); - profiler_add_marker( - "DOMEvent", JS::ProfilingCategoryPair::DOM, - MakeUnique( - typeStr, aEvent->mTimeStamp, "DOMEvent", - TRACING_INTERVAL_START, docShellId, docShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "DOMEvent", DOM, DOMEventMarkerPayload, + (typeStr, aEvent->mTimeStamp, "DOMEvent", TRACING_INTERVAL_START, + docShellId, docShellHistoryId)); EventTargetChainItem::HandleEventTargetChain(chain, postVisitor, aCallback, cd); - profiler_add_marker( - "DOMEvent", JS::ProfilingCategoryPair::DOM, - MakeUnique( - typeStr, aEvent->mTimeStamp, "DOMEvent", TRACING_INTERVAL_END, - docShellId, docShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "DOMEvent", DOM, DOMEventMarkerPayload, + (typeStr, aEvent->mTimeStamp, "DOMEvent", TRACING_INTERVAL_END, + docShellId, docShellHistoryId)); } else #endif { diff --git a/dom/media/mediasink/VideoSink.cpp b/dom/media/mediasink/VideoSink.cpp index 947d112bc0ec..6e889797ecc2 100644 --- a/dom/media/mediasink/VideoSink.cpp +++ b/dom/media/mediasink/VideoSink.cpp @@ -36,13 +36,13 @@ extern LazyLogModule gMediaDecoderLog; MOZ_LOG(gMediaDecoderLog, LogLevel::Verbose, (FMT(x, ##__VA_ARGS__))) #ifdef MOZ_GECKO_PROFILER -# define VSINK_ADD_PROFILER_MARKER(tag, markerTime, aTime, vTime) \ - do { \ - if (profiler_thread_is_being_profiled()) { \ - profiler_add_marker( \ - tag, JS::ProfilingCategoryPair::GRAPHICS, \ - MakeUnique(markerTime, aTime, vTime)); \ - } \ +# define VSINK_ADD_PROFILER_MARKER(tag, markerTime, aTime, vTime) \ + do { \ + if (profiler_thread_is_being_profiled()) { \ + PROFILER_ADD_MARKER_WITH_PAYLOAD(tag, GRAPHICS, \ + VideoFrameMarkerPayload, \ + (markerTime, aTime, vTime)); \ + } \ } while (0) class VideoFrameMarkerPayload : public ProfilerMarkerPayload { diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 6e03e42ae9c1..e83d9c7168f8 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -226,10 +226,9 @@ void Performance::Mark(const nsAString& aName, ErrorResult& aRv) { nsCOMPtr docShell = nsContentUtils::GetDocShellForEventTarget(et); DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); - profiler_add_marker( - "UserTiming", JS::ProfilingCategoryPair::DOM, - MakeUnique(aName, TimeStamp::Now(), docShellId, - docShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "UserTiming", DOM, UserTimingMarkerPayload, + (aName, TimeStamp::Now(), docShellId, docShellHistoryId)); } #endif } @@ -327,10 +326,10 @@ void Performance::Measure(const nsAString& aName, nsCOMPtr docShell = nsContentUtils::GetDocShellForEventTarget(et); DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); - profiler_add_marker("UserTiming", JS::ProfilingCategoryPair::DOM, - MakeUnique( - aName, startMark, endMark, startTimeStamp, - endTimeStamp, docShellId, docShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "UserTiming", DOM, UserTimingMarkerPayload, + (aName, startMark, endMark, startTimeStamp, endTimeStamp, docShellId, + docShellHistoryId)); } #endif } diff --git a/gfx/layers/Layers.cpp b/gfx/layers/Layers.cpp index e362b24faaf9..e69975d3a658 100644 --- a/gfx/layers/Layers.cpp +++ b/gfx/layers/Layers.cpp @@ -2324,7 +2324,7 @@ void RecordCompositionPayloadsPresented( "Payload Presented, type: %d latency: %dms\n", int32_t(payload.mType), int32_t((presented - payload.mTimeStamp).ToMilliseconds())); - profiler_add_marker(marker.get(), JS::ProfilingCategoryPair::GRAPHICS); + PROFILER_ADD_MARKER(marker.get(), GRAPHICS); } #endif diff --git a/gfx/layers/composite/CompositorScreenshotGrabber.cpp b/gfx/layers/composite/CompositorScreenshotGrabber.cpp index dc3be46d733d..8b8798d28739 100644 --- a/gfx/layers/composite/CompositorScreenshotGrabber.cpp +++ b/gfx/layers/composite/CompositorScreenshotGrabber.cpp @@ -89,8 +89,8 @@ void CompositorScreenshotGrabber::MaybeProcessQueue() { void CompositorScreenshotGrabber::NotifyEmptyFrame() { #ifdef MOZ_GECKO_PROFILER - profiler_add_marker("NoCompositorScreenshot because nothing changed", - JS::ProfilingCategoryPair::GRAPHICS); + PROFILER_ADD_MARKER("NoCompositorScreenshot because nothing changed", + GRAPHICS); #endif } diff --git a/gfx/layers/composite/ContainerLayerComposite.cpp b/gfx/layers/composite/ContainerLayerComposite.cpp index b5e9eac7a8d8..c5725d9b29aa 100644 --- a/gfx/layers/composite/ContainerLayerComposite.cpp +++ b/gfx/layers/composite/ContainerLayerComposite.cpp @@ -102,9 +102,9 @@ static void PrintUniformityInfo(Layer* aLayer) { } Point translation = transform.As2D().GetTranslation(); - profiler_add_marker("LayerTranslation", JS::ProfilingCategoryPair::GRAPHICS, - MakeUnique( - aLayer, translation, TimeStamp::Now())); + PROFILER_ADD_MARKER_WITH_PAYLOAD("LayerTranslation", GRAPHICS, + LayerTranslationMarkerPayload, + (aLayer, translation, TimeStamp::Now())); #endif } diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index bcd53db5d60c..598d362bf0a6 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -1976,8 +1976,8 @@ already_AddRefed CompositorBridgeParent::GetAPZCTreeManager( static void InsertVsyncProfilerMarker(TimeStamp aVsyncTimestamp) { MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); if (profiler_thread_is_being_profiled()) { - profiler_add_marker("VsyncTimestamp", JS::ProfilingCategoryPair::GRAPHICS, - MakeUnique(aVsyncTimestamp)); + PROFILER_ADD_MARKER_WITH_PAYLOAD("VsyncTimestamp", GRAPHICS, + VsyncMarkerPayload, (aVsyncTimestamp)); } } #endif diff --git a/gfx/layers/mlgpu/MLGPUScreenshotGrabber.cpp b/gfx/layers/mlgpu/MLGPUScreenshotGrabber.cpp index dad635525d18..ab78a0493c8f 100644 --- a/gfx/layers/mlgpu/MLGPUScreenshotGrabber.cpp +++ b/gfx/layers/mlgpu/MLGPUScreenshotGrabber.cpp @@ -101,8 +101,8 @@ void MLGPUScreenshotGrabber::MaybeProcessQueue() { void MLGPUScreenshotGrabber::NotifyEmptyFrame() { #ifdef MOZ_GECKO_PROFILER - profiler_add_marker("NoCompositorScreenshot because nothing changed", - JS::ProfilingCategoryPair::GRAPHICS); + PROFILER_ADD_MARKER("NoCompositorScreenshot because nothing changed", + GRAPHICS); #endif } diff --git a/layout/base/AutoProfilerStyleMarker.h b/layout/base/AutoProfilerStyleMarker.h index 07d3229f10d0..fe18a8ab395f 100644 --- a/layout/base/AutoProfilerStyleMarker.h +++ b/layout/base/AutoProfilerStyleMarker.h @@ -39,11 +39,11 @@ class MOZ_RAII AutoProfilerStyleMarker { return; } ServoTraversalStatistics::sActive = false; - profiler_add_marker("Styles", JS::ProfilingCategoryPair::LAYOUT, - MakeUnique( - mStartTime, TimeStamp::Now(), std::move(mCause), - ServoTraversalStatistics::sSingleton, mDocShellId, - mDocShellHistoryId)); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "Styles", LAYOUT, StyleMarkerPayload, + (mStartTime, TimeStamp::Now(), std::move(mCause), + ServoTraversalStatistics::sSingleton, mDocShellId, + mDocShellHistoryId)); } private: diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index c84b7ede909a..346fccd49f07 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -4360,11 +4360,10 @@ struct Internals { #ifdef MOZ_GECKO_PROFILER if (profiler_feature_active(ProfilerFeature::PreferenceReads)) { - profiler_add_marker("PreferenceRead", - JS::ProfilingCategoryPair::OTHER_PreferenceRead, - MakeUnique( - aPrefName, Some(aKind), Some(pref->Type()), - PrefValueToString(aResult), TimeStamp::Now())); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "PreferenceRead", OTHER_PreferenceRead, PrefMarkerPayload, + (aPrefName, Some(aKind), Some(pref->Type()), + PrefValueToString(aResult), TimeStamp::Now())); } #endif } @@ -4381,11 +4380,10 @@ struct Internals { #ifdef MOZ_GECKO_PROFILER if (profiler_feature_active(ProfilerFeature::PreferenceReads)) { - profiler_add_marker( - "PreferenceRead", JS::ProfilingCategoryPair::OTHER_PreferenceRead, - MakeUnique( - aName, Nothing() /* indicates Shared */, Some(pref->Type()), - PrefValueToString(aResult), TimeStamp::Now())); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "PreferenceRead", OTHER_PreferenceRead, PrefMarkerPayload, + (aName, Nothing() /* indicates Shared */, Some(pref->Type()), + PrefValueToString(aResult), TimeStamp::Now())); } #endif } diff --git a/mozglue/baseprofiler/public/BaseProfiler.h b/mozglue/baseprofiler/public/BaseProfiler.h index 5d5c0def4eb0..9a9b00425d50 100644 --- a/mozglue/baseprofiler/public/BaseProfiler.h +++ b/mozglue/baseprofiler/public/BaseProfiler.h @@ -65,6 +65,8 @@ categoryPair, ctx, flags) # define BASE_PROFILER_ADD_MARKER(markerName, categoryPair) +# define BASE_PROFILER_ADD_MARKER_WITH_PAYLOAD( \ + markerName, categoryPair, PayloadType, parenthesizedPayloadArgs) # define MOZDECLARE_DOCSHELL_AND_HISTORY_ID(docShell) # define BASE_PROFILER_TRACING(categoryString, markerName, categoryPair, kind) @@ -695,6 +697,18 @@ class MOZ_RAII AutoProfilerStats { MFBT_API void profiler_add_marker(const char* aMarkerName, ProfilingCategoryPair aCategoryPair); + +// `PayloadType` is a sub-class of BaseMarkerPayload, `parenthesizedPayloadArgs` +// is the argument list used to construct that `PayloadType`. E.g.: +// `BASE_PROFILER_ADD_MARKER_WITH_PAYLOAD("Load", DOM, TextMarkerPayload, +// ("text", start, end, ds, dsh))` +# define BASE_PROFILER_ADD_MARKER_WITH_PAYLOAD( \ + markerName, categoryPair, PayloadType, parenthesizedPayloadArgs) \ + ::mozilla::baseprofiler::profiler_add_marker( \ + markerName, \ + ::mozilla::baseprofiler::ProfilingCategoryPair::categoryPair, \ + ::mozilla::MakeUnique parenthesizedPayloadArgs) + MFBT_API void profiler_add_marker(const char* aMarkerName, ProfilingCategoryPair aCategoryPair, UniquePtr aPayload); diff --git a/tools/profiler/gecko/ProfilerIOInterposeObserver.cpp b/tools/profiler/gecko/ProfilerIOInterposeObserver.cpp index f338c4d73bfe..5138d343a81e 100644 --- a/tools/profiler/gecko/ProfilerIOInterposeObserver.cpp +++ b/tools/profiler/gecko/ProfilerIOInterposeObserver.cpp @@ -18,10 +18,9 @@ void ProfilerIOInterposeObserver::Observe(Observation& aObservation) { nsString filename; aObservation.Filename(filename); - profiler_add_marker( - "FileIO", JS::ProfilingCategoryPair::OTHER, - MakeUnique( - aObservation.ObservedOperationString(), aObservation.Reference(), - NS_ConvertUTF16toUTF8(filename).get(), aObservation.Start(), - aObservation.End(), std::move(stack))); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "FileIO", OTHER, FileIOMarkerPayload, + (aObservation.ObservedOperationString(), aObservation.Reference(), + NS_ConvertUTF16toUTF8(filename).get(), aObservation.Start(), + aObservation.End(), std::move(stack))); } diff --git a/tools/profiler/gecko/nsProfiler.cpp b/tools/profiler/gecko/nsProfiler.cpp index 6fb583888e4f..4a3a18b26386 100644 --- a/tools/profiler/gecko/nsProfiler.cpp +++ b/tools/profiler/gecko/nsProfiler.cpp @@ -173,7 +173,7 @@ nsProfiler::ResumeSampling() { NS_IMETHODIMP nsProfiler::AddMarker(const char* aMarker) { - profiler_add_marker(aMarker, JS::ProfilingCategoryPair::OTHER); + PROFILER_ADD_MARKER(aMarker, OTHER); return NS_OK; } diff --git a/tools/profiler/public/GeckoProfiler.h b/tools/profiler/public/GeckoProfiler.h index 458612d3deb5..d4eded0fbbc2 100644 --- a/tools/profiler/public/GeckoProfiler.h +++ b/tools/profiler/public/GeckoProfiler.h @@ -51,6 +51,8 @@ ctx, flags) # define PROFILER_ADD_MARKER(markerName, categoryPair) +# define PROFILER_ADD_MARKER_WITH_PAYLOAD(markerName, categoryPair, \ + PayloadType, payloadArgs) # define PROFILER_ADD_NETWORK_MARKER(uri, pri, channel, type, start, end, \ count, cache, timings, redirect) @@ -675,10 +677,21 @@ mozilla::Maybe profiler_get_buffer_info(); // mode. # define PROFILER_ADD_MARKER(markerName, categoryPair) \ - profiler_add_marker(markerName, JS::ProfilingCategoryPair::categoryPair) + ::profiler_add_marker(markerName, ::JS::ProfilingCategoryPair::categoryPair) void profiler_add_marker(const char* aMarkerName, JS::ProfilingCategoryPair aCategoryPair); + +// `PayloadType` is a sub-class of MarkerPayload, `parenthesizedPayloadArgs` is +// the argument list used to construct that `PayloadType`. E.g.: +// `PROFILER_ADD_MARKER_WITH_PAYLOAD("Load", DOM, TextMarkerPayload, +// ("text", start, end, ds, dsh))` +# define PROFILER_ADD_MARKER_WITH_PAYLOAD( \ + markerName, categoryPair, PayloadType, parenthesizedPayloadArgs) \ + ::profiler_add_marker( \ + markerName, ::JS::ProfilingCategoryPair::categoryPair, \ + ::mozilla::MakeUnique parenthesizedPayloadArgs) + void profiler_add_marker(const char* aMarkerName, JS::ProfilingCategoryPair aCategoryPair, mozilla::UniquePtr aPayload); diff --git a/tools/profiler/tests/gtest/GeckoProfiler.cpp b/tools/profiler/tests/gtest/GeckoProfiler.cpp index 31c0bc448dd5..7689a491bc6f 100644 --- a/tools/profiler/tests/gtest/GeckoProfiler.cpp +++ b/tools/profiler/tests/gtest/GeckoProfiler.cpp @@ -530,18 +530,17 @@ TEST(GeckoProfiler, Markers) { AUTO_PROFILER_TRACING("C", "A", OTHER); } - profiler_add_marker("M1", JS::ProfilingCategoryPair::OTHER); - profiler_add_marker("M2", JS::ProfilingCategoryPair::OTHER, - MakeUnique("C", TRACING_EVENT)); + PROFILER_ADD_MARKER("M1", OTHER); + PROFILER_ADD_MARKER_WITH_PAYLOAD("M2", OTHER, TracingMarkerPayload, + ("C", TRACING_EVENT)); PROFILER_ADD_MARKER("M3", OTHER); - profiler_add_marker("M4", JS::ProfilingCategoryPair::OTHER, - MakeUnique( - "C", TRACING_EVENT, mozilla::Nothing(), - mozilla::Nothing(), profiler_get_backtrace())); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "M4", OTHER, TracingMarkerPayload, + ("C", TRACING_EVENT, mozilla::Nothing(), mozilla::Nothing(), + profiler_get_backtrace())); for (int i = 0; i < 10; i++) { - profiler_add_marker("M5", JS::ProfilingCategoryPair::OTHER, - MakeUnique(i)); + PROFILER_ADD_MARKER_WITH_PAYLOAD("M5", OTHER, GTestMarkerPayload, (i)); } // Create two strings: one that is the maximum allowed length, and one that @@ -628,8 +627,7 @@ TEST(GeckoProfiler, Markers) ASSERT_TRUE(GTestMarkerPayload::sNumDestroyed == 10); for (int i = 0; i < 10; i++) { - profiler_add_marker("M5", JS::ProfilingCategoryPair::OTHER, - MakeUnique(i)); + PROFILER_ADD_MARKER_WITH_PAYLOAD("M5", OTHER, GTestMarkerPayload, (i)); } // Warning: this could be racy @@ -659,11 +657,9 @@ TEST(GeckoProfiler, DurationLimit) GTestMarkerPayload::sNumStreamed = 0; GTestMarkerPayload::sNumDestroyed = 0; - profiler_add_marker("M1", JS::ProfilingCategoryPair::OTHER, - MakeUnique(1)); + PROFILER_ADD_MARKER_WITH_PAYLOAD("M1", OTHER, GTestMarkerPayload, (1)); PR_Sleep(PR_MillisecondsToInterval(1100)); - profiler_add_marker("M2", JS::ProfilingCategoryPair::OTHER, - MakeUnique(2)); + PROFILER_ADD_MARKER_WITH_PAYLOAD("M2", OTHER, GTestMarkerPayload, (2)); PR_Sleep(PR_MillisecondsToInterval(500)); SpliceableChunkedJSONWriter w; diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp index d850836d0851..fd0d7749fe4f 100644 --- a/xpcom/base/CycleCollectedJSRuntime.cpp +++ b/xpcom/base/CycleCollectedJSRuntime.cpp @@ -841,17 +841,15 @@ void CycleCollectedJSRuntime::GCSliceCallback(JSContext* aContext, #ifdef MOZ_GECKO_PROFILER if (profiler_thread_is_being_profiled()) { if (aProgress == JS::GC_CYCLE_END) { - profiler_add_marker( - "GCMajor", JS::ProfilingCategoryPair::GCCC, - MakeUnique(aDesc.startTime(aContext), - aDesc.endTime(aContext), - aDesc.formatJSONProfiler(aContext))); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "GCMajor", GCCC, GCMajorMarkerPayload, + (aDesc.startTime(aContext), aDesc.endTime(aContext), + aDesc.formatJSONProfiler(aContext))); } else if (aProgress == JS::GC_SLICE_END) { - profiler_add_marker( - "GCSlice", JS::ProfilingCategoryPair::GCCC, - MakeUnique( - aDesc.lastSliceStart(aContext), aDesc.lastSliceEnd(aContext), - aDesc.sliceToJSONProfiler(aContext))); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "GCSlice", GCCC, GCSliceMarkerPayload, + (aDesc.lastSliceStart(aContext), aDesc.lastSliceEnd(aContext), + aDesc.sliceToJSONProfiler(aContext))); } } #endif @@ -930,10 +928,10 @@ void CycleCollectedJSRuntime::GCNurseryCollectionCallback( #ifdef MOZ_GECKO_PROFILER else if (aProgress == JS::GCNurseryProgress::GC_NURSERY_COLLECTION_END && profiler_thread_is_being_profiled()) { - profiler_add_marker("GCMinor", JS::ProfilingCategoryPair::GCCC, - MakeUnique( - self->mLatestNurseryCollectionStart, - TimeStamp::Now(), JS::MinorGcToJSON(aContext))); + PROFILER_ADD_MARKER_WITH_PAYLOAD( + "GCMinor", GCCC, GCMinorMarkerPayload, + (self->mLatestNurseryCollectionStart, TimeStamp::Now(), + JS::MinorGcToJSON(aContext))); } #endif diff --git a/xpcom/base/Logging.cpp b/xpcom/base/Logging.cpp index aa6ce93168c0..ab6ff1c86b61 100644 --- a/xpcom/base/Logging.cpp +++ b/xpcom/base/Logging.cpp @@ -407,9 +407,8 @@ class LogModuleManager { #ifdef MOZ_GECKO_PROFILER if (mAddProfilerMarker && profiler_is_active()) { - profiler_add_marker( - "LogMessages", JS::ProfilingCategoryPair::OTHER, - MakeUnique(aName, buffToWrite, TimeStamp::Now())); + PROFILER_ADD_MARKER_WITH_PAYLOAD("LogMessages", OTHER, LogMarkerPayload, + (aName, buffToWrite, TimeStamp::Now())); } #endif diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index 23fdd2bbb474..b8678bae0dfd 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -1237,11 +1237,10 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult) { mLastLongTaskEnd = now; #ifdef MOZ_GECKO_PROFILER if (profiler_thread_is_being_profiled()) { - profiler_add_marker( + PROFILER_ADD_MARKER_WITH_PAYLOAD( (priority != EventQueuePriority::Idle) ? "LongTask" : "LongIdleTask", - JS::ProfilingCategoryPair::OTHER, - MakeUnique(mCurrentEventStart, now)); + OTHER, LongTaskMarkerPayload, (mCurrentEventStart, now)); } #endif }