diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index f0ceec181f91..3c1d7ddf8e97 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -7950,7 +7950,7 @@ nsresult nsDocShell::CreateContentViewer(const nsACString& aContentType, BasePrincipal::Cast(thisPrincipal)->GetURI(getter_AddRefs(prinURI)); nsPrintfCString marker("Iframe loaded in background: %s", prinURI->GetSpecOrDefault().get()); - PROFILER_MARKER_TEXT("Background Iframe", DOM, {}, marker); + PROFILER_MARKER_TEXT("Background Iframe", DOM, marker); #endif SetBackgroundLoadIframe(); } diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index 9e95ab0e0be8..416b356ed571 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -200,7 +200,7 @@ void ChromeUtils::AddProfilerMarker( const Optional& aStartTime, const Optional& aText) { #ifdef MOZ_GECKO_PROFILER - MarkerOptions options; + MarkerOptions options{::geckoprofiler::category::JS}; if (aStartTime.WasPassed()) { RefPtr performance; @@ -231,9 +231,10 @@ void ChromeUtils::AddProfilerMarker( } if (aText.WasPassed()) { - PROFILER_MARKER_TEXT(aName, JS, std::move(options), aText.Value()); + PROFILER_MARKER_TEXT(aName, MarkerOptions(std::move(options)), + aText.Value()); } else { - PROFILER_MARKER_UNTYPED(aName, JS, std::move(options)); + PROFILER_MARKER_UNTYPED(aName, MarkerOptions(std::move(options))); } #endif // MOZ_GECKO_PROFILER } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 507d7896f5ec..b8b1775366fd 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -6072,11 +6072,12 @@ bool nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout, timeout->mScriptHandler->GetDescription(handlerDescription); str.Append(handlerDescription); } - AUTO_PROFILER_MARKER_TEXT("setTimeout callback", JS, - MarkerOptions(MarkerStack::TakeBacktrace( - timeout->TakeProfilerBacktrace()), - MarkerInnerWindowId(mWindowID)), - str); + AUTO_PROFILER_MARKER_TEXT( + "setTimeout callback", + JS.WithOptions( + MarkerStack::TakeBacktrace(timeout->TakeProfilerBacktrace()), + MarkerInnerWindowId(mWindowID)), + str); #endif bool abortIntervalHandler; diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp index f7a6c2ddb0eb..97b98a9a1fbb 100644 --- a/dom/events/EventDispatcher.cpp +++ b/dom/events/EventDispatcher.cpp @@ -1063,18 +1063,21 @@ nsresult EventDispatcher::Dispatch(nsISupports* aTarget, } }; - profiler_add_marker("DOMEvent", geckoprofiler::category::DOM, - {MarkerTiming::IntervalStart(), - MarkerInnerWindowId(innerWindowId)}, - DOMEventMarker{}, typeStr, aEvent->mTimeStamp); + profiler_add_marker( + "DOMEvent", + geckoprofiler::category::DOM.WithOptions( + MarkerTiming::IntervalStart(), + MarkerInnerWindowId(innerWindowId)), + typeStr, aEvent->mTimeStamp); EventTargetChainItem::HandleEventTargetChain(chain, postVisitor, aCallback, cd); - profiler_add_marker( - "DOMEvent", geckoprofiler::category::DOM, - {MarkerTiming::IntervalEnd(), std::move(innerWindowId)}, - DOMEventMarker{}, typeStr, aEvent->mTimeStamp); + profiler_add_marker( + "DOMEvent", + geckoprofiler::category::DOM.WithOptions( + MarkerTiming::IntervalEnd(), std::move(innerWindowId)), + typeStr, aEvent->mTimeStamp); } else #endif { diff --git a/dom/ipc/PreallocatedProcessManager.cpp b/dom/ipc/PreallocatedProcessManager.cpp index b76ca5154bb8..bf1a7b85e220 100644 --- a/dom/ipc/PreallocatedProcessManager.cpp +++ b/dom/ipc/PreallocatedProcessManager.cpp @@ -286,9 +286,10 @@ void PreallocatedProcessManagerImpl::RemoveBlocker(ContentParent* aParent) { MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug, ("Blocked preallocation for %fms", (TimeStamp::Now() - mBlockingStartTime).ToMilliseconds())); - PROFILER_MARKER_TEXT("Process", DOM, - MarkerTiming::IntervalUntilNowFrom(mBlockingStartTime), - "Blocked preallocation"); + PROFILER_MARKER_TEXT( + "Process", + DOM.WithOptions(MarkerTiming::IntervalUntilNowFrom(mBlockingStartTime)), + "Blocked preallocation"); if (IsEmpty()) { AllocateAfterDelay(); } diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 87f4e70b22de..72fe4a18be65 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -2863,9 +2863,10 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) { // mDataType of the request might remain set to DataType::Unknown. MOZ_ASSERT(aRequest->IsTextSource() || aRequest->IsUnknownDataType()); LOG(("ScriptLoadRequest (%p): Evaluate Module", aRequest)); - AUTO_PROFILER_MARKER_TEXT("ModuleEvaluation", JS, - MarkerInnerWindowIdFromDocShell(docShell), - profilerLabelString); + AUTO_PROFILER_MARKER_TEXT( + "ModuleEvaluation", + JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)), + profilerLabelString); // currentScript is set to null for modules. AutoCurrentScriptUpdater scriptUpdater(this, nullptr); @@ -2938,18 +2939,20 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) { } else { LOG(("ScriptLoadRequest (%p): Decode Bytecode and Execute", aRequest)); - AUTO_PROFILER_MARKER_TEXT("BytecodeDecodeMainThread", JS, - MarkerInnerWindowIdFromDocShell(docShell), - profilerLabelString); + AUTO_PROFILER_MARKER_TEXT( + "BytecodeDecodeMainThread", + JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)), + profilerLabelString); rv = exec.Decode(options, aRequest->mScriptBytecode, aRequest->mBytecodeOffset); } if (rv == NS_OK) { - AUTO_PROFILER_MARKER_TEXT("ScriptExecution", JS, - MarkerInnerWindowIdFromDocShell(docShell), - profilerLabelString); + AUTO_PROFILER_MARKER_TEXT( + "ScriptExecution", + JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)), + profilerLabelString); rv = ExecuteCompiledScript(cx, aRequest, exec, classicScript); } @@ -2983,8 +2986,8 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) { LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest)); if (aRequest->IsBinASTSource()) { AUTO_PROFILER_MARKER_TEXT( - "BinASTDecodeMainThread", JS, - MarkerInnerWindowIdFromDocShell(docShell), + "BinASTDecodeMainThread", + JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)), profilerLabelString); rv = exec.DecodeBinAST(options, @@ -2996,8 +2999,8 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) { rv = GetScriptSource(cx, aRequest, &maybeSource); if (NS_SUCCEEDED(rv)) { AUTO_PROFILER_MARKER_TEXT( - "ScriptCompileMainThread", JS, - MarkerInnerWindowIdFromDocShell(docShell), + "ScriptCompileMainThread", + JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)), profilerLabelString); rv = maybeSource.constructed>() @@ -3014,8 +3017,8 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) { if (rv == NS_OK) { script = exec.GetScript(); AUTO_PROFILER_MARKER_TEXT( - "ScriptExecution", JS, - MarkerInnerWindowIdFromDocShell(docShell), + "ScriptExecution", + JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)), profilerLabelString); rv = ExecuteCompiledScript(cx, aRequest, exec, classicScript); } diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index b9b15ea97c27..89a289a47c55 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -361,8 +361,8 @@ void WorkerGlobalScope::ImportScripts(JSContext* aCx, } } } - AUTO_PROFILER_MARKER_TEXT("ImportScripts", JS, MarkerStack::Capture(), - urls); + AUTO_PROFILER_MARKER_TEXT("ImportScripts", + JS.WithOptions(MarkerStack::Capture()), urls); #endif workerinternals::Load(mWorkerPrivate, std::move(stack), aScriptURLs, WorkerScript, aRv); diff --git a/gfx/layers/Layers.cpp b/gfx/layers/Layers.cpp index 5689bf6f3f16..daad15c434ce 100644 --- a/gfx/layers/Layers.cpp +++ b/gfx/layers/Layers.cpp @@ -2365,9 +2365,10 @@ void RecordCompositionPayloadsPresented( nsPrintfCString text( "Latency: %dms", int32_t((presented - payload.mTimeStamp).ToMilliseconds())); - PROFILER_MARKER_TEXT( - name, GRAPHICS, - MarkerTiming::Interval(payload.mTimeStamp, presented), text); + PROFILER_MARKER_TEXT(name, + GRAPHICS.WithOptions(MarkerTiming::Interval( + payload.mTimeStamp, presented)), + text); } #endif diff --git a/gfx/layers/SurfacePoolCA.mm b/gfx/layers/SurfacePoolCA.mm index 1bbe95909565..e424d73023ac 100644 --- a/gfx/layers/SurfacePoolCA.mm +++ b/gfx/layers/SurfacePoolCA.mm @@ -81,7 +81,7 @@ void SurfacePoolCA::LockedPool::MutateEntryStorage(const char* aMutationType, #ifdef MOZ_GECKO_PROFILER if (profiler_thread_is_being_profiled()) { PROFILER_MARKER_TEXT( - "SurfacePool", GRAPHICS, MarkerTiming::IntervalUntilNowFrom(before), + "SurfacePool", GRAPHICS.WithOptions(MarkerTiming::IntervalUntilNowFrom(before)), nsPrintfCString("%d -> %d in use | %d -> %d waiting for | %d -> %d " "available | %s %dx%d | %dMB total memory", int(inUseCountBefore), int(mInUseEntries.size()), int(pendingCountBefore), diff --git a/gfx/layers/composite/ImageComposite.cpp b/gfx/layers/composite/ImageComposite.cpp index d9eea066001b..27b39a8077cf 100644 --- a/gfx/layers/composite/ImageComposite.cpp +++ b/gfx/layers/composite/ImageComposite.cpp @@ -50,7 +50,7 @@ void ImageComposite::UpdateBias(size_t aImageIndex, bool aFrameChanged) { nsPrintfCString str("current %.2lfms, next %.2lfms", offsetCurrent.ToMilliseconds(), offsetNext.ToMilliseconds()); - PROFILER_MARKER_TEXT("Video frame offsets", GRAPHICS, {}, str); + PROFILER_MARKER_TEXT("Video frame offsets", GRAPHICS, str); } #endif @@ -185,7 +185,7 @@ void ImageComposite::SetImages(nsTArray&& aNewImages) { ") to frameID %" PRId32 " (prod %" PRId32 ")", len, len == 1 ? "image" : "images", first.mFrameID, first.mProducerID, last.mFrameID, last.mProducerID); - PROFILER_MARKER_TEXT("ImageComposite::SetImages", GRAPHICS, {}, str); + PROFILER_MARKER_TEXT("ImageComposite::SetImages", GRAPHICS, str); } #endif } @@ -229,7 +229,7 @@ bool ImageComposite::UpdateCompositedFrame( descr.AppendLiteral(", no change"); } } - PROFILER_MARKER_TEXT("UpdateCompositedFrame", GRAPHICS, {}, descr); + PROFILER_MARKER_TEXT("UpdateCompositedFrame", GRAPHICS, descr); #endif if (mLastFrameID == image.mFrameID && mLastProducerID == image.mProducerID) { @@ -259,7 +259,7 @@ bool ImageComposite::UpdateCompositedFrame( " (producer %" PRId32 ")", dropped, frameOrFrames, mLastFrameID, image.mFrameID, mLastProducerID); - PROFILER_MARKER_TEXT("Video frames dropped", GRAPHICS, {}, text); + PROFILER_MARKER_TEXT("Video frames dropped", GRAPHICS, text); } #endif } @@ -370,7 +370,7 @@ void ImageComposite::DetectTimeStampJitter(const TimedImage* aNewImage) { } if (jitter) { nsPrintfCString text("%.2lfms", jitter->ToMilliseconds()); - PROFILER_MARKER_TEXT("VideoFrameTimeStampJitter", GRAPHICS, {}, text); + PROFILER_MARKER_TEXT("VideoFrameTimeStampJitter", GRAPHICS, text); } #endif } diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index 83173bff5ae3..94bc2f232209 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -88,8 +88,8 @@ void gecko_profiler_add_text_marker(const char* name, const char* text_bytes, auto now = mozilla::TimeStamp::NowUnfuzzed(); auto start = now - mozilla::TimeDuration::FromMicroseconds(microseconds); PROFILER_MARKER_TEXT( - mozilla::ProfilerString8View::WrapNullTerminatedString(name), GRAPHICS, - mozilla::MarkerTiming::Interval(start, now), + mozilla::ProfilerString8View::WrapNullTerminatedString(name), + GRAPHICS.WithOptions(mozilla::MarkerTiming::Interval(start, now)), mozilla::ProfilerString8View(text_bytes, text_len)); } #endif @@ -1990,7 +1990,7 @@ void WebRenderBridgeParent::CompositeToTarget(VsyncId aId, if (mPaused || !mReceivedDisplayList) { ResetPreviousSampleTime(); mCompositionOpportunityId = mCompositionOpportunityId.Next(); - PROFILER_MARKER_TEXT("SkippedComposite", GRAPHICS, {}, + PROFILER_MARKER_TEXT("SkippedComposite", GRAPHICS, mPaused ? "Paused"_ns : "No display list"_ns); return; } @@ -2010,7 +2010,7 @@ void WebRenderBridgeParent::CompositeToTarget(VsyncId aId, } } - PROFILER_MARKER_TEXT("SkippedComposite", GRAPHICS, {}, + PROFILER_MARKER_TEXT("SkippedComposite", GRAPHICS, "Too many pending frames"); return; } @@ -2037,8 +2037,8 @@ void WebRenderBridgeParent::MaybeGenerateFrame(VsyncId aId, // Skip WR render during paused state. if (cbp->IsPaused()) { TimeStamp now = TimeStamp::NowUnfuzzed(); - PROFILER_MARKER_TEXT("SkippedComposite", GRAPHICS, - MarkerTiming::InstantAt(now), + PROFILER_MARKER_TEXT("SkippedComposite", + GRAPHICS.WithOptions(MarkerTiming::InstantAt(now)), "CompositorBridgeParent is paused"); cbp->NotifyPipelineRendered(mPipelineId, mWrEpoch, VsyncId(), now, now, now); @@ -2073,8 +2073,8 @@ void WebRenderBridgeParent::MaybeGenerateFrame(VsyncId aId, if (!generateFrame) { // Could skip generating frame now. - PROFILER_MARKER_TEXT("SkippedComposite", GRAPHICS, - MarkerTiming::InstantAt(start), + PROFILER_MARKER_TEXT("SkippedComposite", + GRAPHICS.WithOptions(MarkerTiming::InstantAt(start)), "No reason to generate frame"); ResetPreviousSampleTime(); return; diff --git a/gfx/webrender_bindings/RenderCompositorNative.cpp b/gfx/webrender_bindings/RenderCompositorNative.cpp index 60d121382c23..3bf11fe6698e 100644 --- a/gfx/webrender_bindings/RenderCompositorNative.cpp +++ b/gfx/webrender_bindings/RenderCompositorNative.cpp @@ -254,8 +254,9 @@ void RenderCompositorNative::CompositorEndFrame() { nativeLayerCount += int(it.second.mNativeLayers.size()); } PROFILER_MARKER_TEXT( - "WR OS Compositor frame", GRAPHICS, - MarkerTiming::IntervalUntilNowFrom(mBeginFrameTimeStamp), + "WR OS Compositor frame", + GRAPHICS.WithOptions( + MarkerTiming::IntervalUntilNowFrom(mBeginFrameTimeStamp)), nsPrintfCString("%d%% painting, %d%% overdraw, %d used " "layers (%d%% memory) + %d unused layers (%d%% memory)", int(mDrawnPixelCount * 100 / windowPixelCount), diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 9f0c82d411cd..b1773263440d 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -377,7 +377,8 @@ const mozilla::Module* mozJSComponentLoader::LoadModule(FileLocation& aFile) { mInitialized = true; - AUTO_PROFILER_MARKER_TEXT("JS XPCOM", JS, MarkerStack::Capture(), spec); + AUTO_PROFILER_MARKER_TEXT("JS XPCOM", JS.WithOptions(MarkerStack::Capture()), + spec); AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("mozJSComponentLoader::LoadModule", OTHER, spec); @@ -1180,8 +1181,8 @@ nsresult mozJSComponentLoader::Import(JSContext* aCx, bool aIgnoreExports) { mInitialized = true; - AUTO_PROFILER_MARKER_TEXT("ChromeUtils.import", JS, MarkerStack::Capture(), - aLocation); + AUTO_PROFILER_MARKER_TEXT("ChromeUtils.import", + JS.WithOptions(MarkerStack::Capture()), aLocation); ComponentLoaderInfo info(aLocation); diff --git a/js/xpconnect/loader/mozJSSubScriptLoader.cpp b/js/xpconnect/loader/mozJSSubScriptLoader.cpp index 9fe7b753ef26..078e56986f94 100644 --- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp +++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp @@ -416,7 +416,8 @@ nsresult mozJSSubScriptLoader::DoLoadSubScriptWithOptions( } NS_LossyConvertUTF16toASCII asciiUrl(url); - AUTO_PROFILER_MARKER_TEXT("SubScript", JS, MarkerStack::Capture(), asciiUrl); + AUTO_PROFILER_MARKER_TEXT("SubScript", JS.WithOptions(MarkerStack::Capture()), + asciiUrl); AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING_NONSENSITIVE( "mozJSSubScriptLoader::DoLoadSubScriptWithOptions", OTHER, asciiUrl); diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 54b3e163b6be..05e2300a3818 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -1283,10 +1283,11 @@ bool nsRefreshDriver::RemoveRefreshObserver(nsARefreshObserver* aObserver, nsPrintfCString str("%s [%s]", data.mDescription, kFlushTypeNames[aFlushType]); PROFILER_MARKER_TEXT( - "RefreshObserver", GRAPHICS, - MarkerOptions(MarkerStack::TakeBacktrace(std::move(data.mCause)), - MarkerTiming::IntervalUntilNowFrom(data.mRegisterTime), - MarkerInnerWindowId(data.mInnerWindowId)), + "RefreshObserver", + GRAPHICS.WithOptions( + MarkerStack::TakeBacktrace(std::move(data.mCause)), + MarkerTiming::IntervalUntilNowFrom(data.mRegisterTime), + MarkerInnerWindowId(data.mInnerWindowId)), str); } #endif @@ -2069,8 +2070,8 @@ void nsRefreshDriver::Tick(VsyncId aId, TimeStamp aNowTime) { } #endif AUTO_PROFILER_MARKER_TEXT( - "RefreshDriverTick", GRAPHICS, - MarkerOptions( + "RefreshDriverTick", + GRAPHICS.WithOptions( MarkerStack::TakeBacktrace(std::move(mRefreshTimerStartedCause)), MarkerInnerWindowIdFromDocShell(GetDocShell(mPresContext))), profilerStr); @@ -2332,10 +2333,10 @@ void nsRefreshDriver::Tick(VsyncId aId, TimeStamp aNowTime) { transactionId.AppendInt((uint64_t)mNextTransactionId); } #endif - AUTO_PROFILER_MARKER_TEXT( - "ViewManagerFlush", GRAPHICS, - MarkerStack::TakeBacktrace(std::move(mViewManagerFlushCause)), - transactionId); + AUTO_PROFILER_MARKER_TEXT("ViewManagerFlush", + GRAPHICS.WithOptions(MarkerStack::TakeBacktrace( + std::move(mViewManagerFlushCause))), + transactionId); RefPtr timelines = TimelineConsumers::Get(); diff --git a/mozglue/baseprofiler/public/BaseProfilerMarkers.h b/mozglue/baseprofiler/public/BaseProfilerMarkers.h index 46e201b9e20a..c49cab94107d 100644 --- a/mozglue/baseprofiler/public/BaseProfilerMarkers.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkers.h @@ -21,11 +21,11 @@ // supporting types. // // To then record markers: -// - Use `baseprofiler::AddMarker(...)` from mozglue or other libraries that -// are outside of xul, especially if they may happen outside of xpcom's -// lifetime (typically startup, shutdown, or tests). +// - Use `baseprofiler::AddMarker(...)` from +// mozglue or other libraries that are outside of xul, especially if they may +// happen outside of xpcom's lifetime (typically startup, shutdown, or tests). // - Otherwise #include "ProfilerMarkers.h" instead, and use -// `profiler_add_marker(...)`. +// `profiler_add_marker(...)`. // See these functions for more details. #ifndef BaseProfilerMarkers_h @@ -38,18 +38,15 @@ #ifndef MOZ_GECKO_PROFILER -# define BASE_PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) -# define BASE_PROFILER_MARKER(markerName, categoryName, options, MarkerType, \ - ...) -# define BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) -# define AUTO_BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, \ - text) +# define BASE_PROFILER_MARKER_UNTYPED(markerName, options) +# define BASE_PROFILER_MARKER(markerName, options, MarkerType, ...) +# define BASE_PROFILER_MARKER_TEXT(markerName, options, text) +# define AUTO_BASE_PROFILER_MARKER_TEXT(markerName, options, text) #else // ndef MOZ_GECKO_PROFILER # include "mozilla/ProfileChunkedBuffer.h" # include "mozilla/TimeStamp.h" -# include "mozilla/Unused.h" # include # include @@ -57,56 +54,27 @@ namespace mozilla::baseprofiler { -// Add a marker to a given buffer. `AddMarker()` and related macros should be -// used in most cases, see below for more information about them and the -// parameters; This function may be useful when markers need to be recorded in a -// local buffer outside of the main profiler buffer. -template -ProfileBufferBlockIndex AddMarkerToBuffer( - ProfileChunkedBuffer& aBuffer, const ProfilerString8View& aName, - const MarkerCategory& aCategory, MarkerOptions&& aOptions, - MarkerType aMarkerType, const PayloadArguments&... aPayloadArguments) { - Unused << aMarkerType; // Only the empty object type is useful. +template +ProfileBufferBlockIndex AddMarkerToBuffer(ProfileChunkedBuffer& aBuffer, + const ProfilerString8View& aName, + MarkerOptions&& aOptions, + const Ts&... aTs) { return base_profiler_markers_detail::AddMarkerToBuffer( - aBuffer, aName, aCategory, std::move(aOptions), - ::mozilla::baseprofiler::profiler_capture_backtrace_into, - aPayloadArguments...); + aBuffer, aName, std::move(aOptions), + ::mozilla::baseprofiler::profiler_capture_backtrace_into, aTs...); } -// Add a marker (without payload) to a given buffer. -inline ProfileBufferBlockIndex AddMarkerToBuffer( - ProfileChunkedBuffer& aBuffer, const ProfilerString8View& aName, - const MarkerCategory& aCategory, MarkerOptions&& aOptions = {}) { - return AddMarkerToBuffer(aBuffer, aName, aCategory, std::move(aOptions), - markers::NoPayload{}); -} - -// Add a marker to the Base Profiler buffer. -// - aName: Main name of this marker. -// - aCategory: Category for this marker. -// - aOptions: Optional settings (such as timing, inner window id, -// backtrace...), see `MarkerOptions` for details. -// - aMarkerType: Empty object that specifies the type of marker. -// - aPayloadArguments: Arguments expected by this marker type's -// ` StreamJSONMarkerData` function. -template -ProfileBufferBlockIndex AddMarker( - const ProfilerString8View& aName, const MarkerCategory& aCategory, - MarkerOptions&& aOptions, MarkerType aMarkerType, - const PayloadArguments&... aPayloadArguments) { +template +ProfileBufferBlockIndex AddMarker(const ProfilerString8View& aName, + MarkerOptions&& aOptions, const Ts&... aTs) { if (!baseprofiler::profiler_can_accept_markers()) { return {}; } - return ::mozilla::baseprofiler::AddMarkerToBuffer( - base_profiler_markers_detail::CachedBaseCoreBuffer(), aName, aCategory, - std::move(aOptions), aMarkerType, aPayloadArguments...); -} - -// Add a marker (without payload) to the Base Profiler buffer. -inline ProfileBufferBlockIndex AddMarker(const ProfilerString8View& aName, - const MarkerCategory& aCategory, - MarkerOptions&& aOptions = {}) { - return AddMarker(aName, aCategory, std::move(aOptions), markers::NoPayload{}); + return ::mozilla::baseprofiler::AddMarkerToBuffer( + base_profiler_markers_detail::CachedBaseCoreBuffer(), aName, + std::move(aOptions), aTs...); } // Marker types' StreamJSONMarkerData functions should use this to correctly @@ -122,26 +90,20 @@ inline void WritePropertyTime(JSONWriter& aWriter, } // namespace mozilla::baseprofiler -// Same as `AddMarker()` (without payload). This macro is safe to use even if -// MOZ_GECKO_PROFILER is not #defined. -# define BASE_PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) \ - do { \ - AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_UNTYPED); \ - ::mozilla::baseprofiler::AddMarker( \ - markerName, ::mozilla::baseprofiler::category::categoryName, \ - ##__VA_ARGS__); \ +# define BASE_PROFILER_MARKER_UNTYPED(markerName, options) \ + do { \ + AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_UNTYPED); \ + ::mozilla::baseprofiler::AddMarker<>( \ + markerName, ::mozilla::baseprofiler::category::options); \ } while (false) -// Same as `AddMarker()` (with payload). This macro is safe to use even if -// MOZ_GECKO_PROFILER is not #defined. -# define BASE_PROFILER_MARKER(markerName, categoryName, options, MarkerType, \ - ...) \ - do { \ - AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_with_##MarkerType); \ - ::mozilla::baseprofiler::AddMarker( \ - markerName, ::mozilla::baseprofiler::category::categoryName, \ - options, ::mozilla::baseprofiler::markers::MarkerType{}, \ - ##__VA_ARGS__); \ +# define BASE_PROFILER_MARKER(markerName, options, MarkerType, ...) \ + do { \ + AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_with_##MarkerType); \ + ::mozilla::baseprofiler::AddMarker< \ + ::mozilla::baseprofiler::markers::MarkerType>( \ + markerName, ::mozilla::baseprofiler::category::options, \ + ##__VA_ARGS__); \ } while (false) namespace mozilla::baseprofiler::markers { @@ -157,14 +119,12 @@ struct Text { }; } // namespace mozilla::baseprofiler::markers -// Add a text marker. This macro is safe to use even if MOZ_GECKO_PROFILER is -// not #defined. -# define BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ - do { \ - AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_TEXT); \ - ::mozilla::baseprofiler::AddMarker( \ - markerName, ::mozilla::baseprofiler::category::categoryName, \ - options, ::mozilla::baseprofiler::markers::Text{}, text); \ +# define BASE_PROFILER_MARKER_TEXT(markerName, options, text) \ + do { \ + AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_TEXT); \ + ::mozilla::baseprofiler::AddMarker< \ + ::mozilla::baseprofiler::markers::Text>( \ + markerName, ::mozilla::baseprofiler::category::options, text); \ } while (false) namespace mozilla::baseprofiler { @@ -174,13 +134,9 @@ namespace mozilla::baseprofiler { // start time is already specified in the provided options) until destruction. class MOZ_RAII AutoProfilerTextMarker { public: - AutoProfilerTextMarker(const char* aMarkerName, - const MarkerCategory& aCategory, - MarkerOptions&& aOptions, const std::string& aText) - : mMarkerName(aMarkerName), - mCategory(aCategory), - mOptions(std::move(aOptions)), - mText(aText) { + AutoProfilerTextMarker(const char* aMarkerName, MarkerOptions&& aOptions, + const std::string& aText) + : mMarkerName(aMarkerName), mOptions(std::move(aOptions)), mText(aText) { MOZ_ASSERT(mOptions.Timing().EndTime().IsNull(), "AutoProfilerTextMarker options shouldn't have an end time"); if (mOptions.Timing().StartTime().IsNull()) { @@ -190,27 +146,22 @@ class MOZ_RAII AutoProfilerTextMarker { ~AutoProfilerTextMarker() { mOptions.TimingRef().SetIntervalEnd(); - AUTO_PROFILER_STATS(AUTO_BASE_PROFILER_MARKER_TEXT); - AddMarker(ProfilerString8View::WrapNullTerminatedString(mMarkerName), - mCategory, std::move(mOptions), markers::Text{}, mText); + BASE_PROFILER_MARKER_TEXT( + ProfilerString8View::WrapNullTerminatedString(mMarkerName), + MarkerOptions(std::move(mOptions)), mText); } protected: const char* mMarkerName; - MarkerCategory mCategory; MarkerOptions mOptions; std::string mText; }; } // namespace mozilla::baseprofiler -// Creates an AutoProfilerTextMarker RAII object. This macro is safe to use -// even if MOZ_GECKO_PROFILER is not #defined. -# define AUTO_BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, \ - text) \ - ::mozilla::baseprofiler::AutoProfilerTextMarker BASE_PROFILER_RAII( \ - markerName, ::mozilla::baseprofiler::category::categoryName, options, \ - text) +# define AUTO_BASE_PROFILER_MARKER_TEXT(markerName, options, text) \ + ::mozilla::baseprofiler::AutoProfilerTextMarker BASE_PROFILER_RAII( \ + markerName, ::mozilla::baseprofiler::category::options, text) #endif // nfed MOZ_GECKO_PROFILER else diff --git a/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h b/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h index 48cef15df111..f30b4e696a80 100644 --- a/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h @@ -82,12 +82,12 @@ struct StreamFunctionTypeHelper { // references-to-const, permitted implicit conversions can happen. static ProfileBufferBlockIndex Serialize( ProfileChunkedBuffer& aBuffer, const ProfilerString8View& aName, - const MarkerCategory& aCategory, MarkerOptions&& aOptions, - Streaming::DeserializerTag aDeserializerTag, const As&... aAs) { + MarkerOptions&& aOptions, Streaming::DeserializerTag aDeserializerTag, + const As&... aAs) { // Note that options are first after the entry kind, because they contain // the thread id, which is handled first to filter markers by threads. return aBuffer.PutObjects(ProfileBufferEntryKind::Marker, aOptions, aName, - aCategory, aDeserializerTag, aAs...); + aDeserializerTag, aAs...); } }; @@ -111,7 +111,6 @@ struct MarkerTypeSerialization { template static ProfileBufferBlockIndex Serialize(ProfileChunkedBuffer& aBuffer, const ProfilerString8View& aName, - const MarkerCategory& aCategory, MarkerOptions&& aOptions, const Ts&... aTs) { static_assert(!std::is_same_v { template static ProfileBufferBlockIndex AddMarkerWithOptionalStackToBuffer( ProfileChunkedBuffer& aBuffer, const ProfilerString8View& aName, - const MarkerCategory& aCategory, MarkerOptions&& aOptions, - const Ts&... aTs) { + MarkerOptions&& aOptions, const Ts&... aTs) { if constexpr (std::is_same_v) { static_assert(sizeof...(Ts) == 0, @@ -185,11 +183,11 @@ static ProfileBufferBlockIndex AddMarkerWithOptionalStackToBuffer( // Note that options are first after the entry kind, because they contain // the thread id, which is handled first to filter markers by threads. return aBuffer.PutObjects( - ProfileBufferEntryKind::Marker, std::move(aOptions), aName, aCategory, + ProfileBufferEntryKind::Marker, std::move(aOptions), aName, base_profiler_markers_detail::Streaming::DeserializerTag(0)); } else { return MarkerTypeSerialization::Serialize( - aBuffer, aName, aCategory, std::move(aOptions), aTs...); + aBuffer, aName, std::move(aOptions), aTs...); } } @@ -203,7 +201,7 @@ using BacktraceCaptureFunction = bool (*)(ProfileChunkedBuffer&); template ProfileBufferBlockIndex AddMarkerToBuffer( ProfileChunkedBuffer& aBuffer, const ProfilerString8View& aName, - const MarkerCategory& aCategory, MarkerOptions&& aOptions, + MarkerOptions&& aOptions, BacktraceCaptureFunction aBacktraceCaptureFunction, const Ts&... aTs) { if (aOptions.ThreadId().IsUnspecified()) { // If yet unspecified, set thread to this thread where the marker is added. @@ -228,11 +226,11 @@ ProfileBufferBlockIndex AddMarkerToBuffer( aBacktraceCaptureFunction(chunkedBuffer) ? &chunkedBuffer : nullptr); // This call must be made from here, while chunkedBuffer is in scope. return AddMarkerWithOptionalStackToBuffer( - aBuffer, aName, aCategory, std::move(aOptions), aTs...); + aBuffer, aName, std::move(aOptions), aTs...); } return AddMarkerWithOptionalStackToBuffer( - aBuffer, aName, aCategory, std::move(aOptions), aTs...); + aBuffer, aName, std::move(aOptions), aTs...); } template @@ -256,7 +254,7 @@ template aWriter.StartArrayElement(); { std::forward(aNameCallback)( - aEntryReader.ReadObject()); + aEntryReader.ReadObject()); const double startTime = options.Timing().GetStartTime(); aWriter.DoubleElement(startTime); @@ -266,8 +264,7 @@ template aWriter.IntElement(static_cast(options.Timing().MarkerPhase())); - MarkerCategory category = aEntryReader.ReadObject(); - aWriter.IntElement(static_cast(category.GetCategory())); + aWriter.IntElement(static_cast(options.Category().GetCategory())); if (const auto tag = aEntryReader.ReadObject struct ProfileBufferEntryReader::Deserializer { static void ReadInto(ProfileBufferEntryReader& aER, MarkerCategory& aCategory) { - aCategory = Read(aER); + aCategory.mCategoryPair = static_cast( + aER.ReadULEB128()); } static MarkerCategory Read(ProfileBufferEntryReader& aER) { @@ -586,13 +584,14 @@ struct ProfileBufferEntryReader::Deserializer { template <> struct ProfileBufferEntryWriter::Serializer { static Length Bytes(const MarkerOptions& aOptions) { - return SumBytes(aOptions.ThreadId(), aOptions.Timing(), aOptions.Stack(), - aOptions.InnerWindowId()); + return SumBytes(aOptions.Category(), aOptions.ThreadId(), aOptions.Timing(), + aOptions.Stack(), aOptions.InnerWindowId()); } static void Write(ProfileBufferEntryWriter& aEW, const MarkerOptions& aOptions) { - aEW.WriteObjects(aOptions.ThreadId(), aOptions.Timing(), aOptions.Stack(), + aEW.WriteObjects(aOptions.Category(), aOptions.ThreadId(), + aOptions.Timing(), aOptions.Stack(), aOptions.InnerWindowId()); } }; @@ -600,7 +599,8 @@ struct ProfileBufferEntryWriter::Serializer { template <> struct ProfileBufferEntryReader::Deserializer { static void ReadInto(ProfileBufferEntryReader& aER, MarkerOptions& aOptions) { - aER.ReadIntoObjects(aOptions.mThreadId, aOptions.mTiming, aOptions.mStack, + aER.ReadIntoObjects(aOptions.mCategory, aOptions.mThreadId, + aOptions.mTiming, aOptions.mStack, aOptions.mInnerWindowId); } diff --git a/mozglue/baseprofiler/public/BaseProfilerMarkersPrerequisites.h b/mozglue/baseprofiler/public/BaseProfilerMarkersPrerequisites.h index 7b5252973514..b6329f386ede 100644 --- a/mozglue/baseprofiler/public/BaseProfilerMarkersPrerequisites.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkersPrerequisites.h @@ -212,34 +212,47 @@ class MOZ_STACK_CLASS ProfilerStringView { using ProfilerString8View = ProfilerStringView; using ProfilerString16View = ProfilerStringView; -// This compulsory marker parameter contains the required category information. +// The classes below are all embedded in a `MarkerOptions` object. +class MarkerOptions; + +// This compulsory marker option contains the required category information. class MarkerCategory { public: - // Constructor from category pair (includes both super- and sub-categories). + // Constructor from category pair (aka sub-category) and category. constexpr explicit MarkerCategory( baseprofiler::ProfilingCategoryPair aCategoryPair) : mCategoryPair(aCategoryPair) {} - // Returns the stored category pair. constexpr baseprofiler::ProfilingCategoryPair CategoryPair() const { return mCategoryPair; } - // Returns the super-category from the stored category pair. baseprofiler::ProfilingCategory GetCategory() const { return GetProfilingCategoryPairInfo(mCategoryPair).mCategory; } + // Create a MarkerOptions object from this category and options. + // Definition under MarkerOptions below. + template + MarkerOptions WithOptions(Options&&... aOptions) const; + private: + // The default constructor is only used during deserialization of + // MarkerOptions. + friend MarkerOptions; + constexpr MarkerCategory() = default; + + friend ProfileBufferEntryReader::Deserializer; + baseprofiler::ProfilingCategoryPair mCategoryPair = baseprofiler::ProfilingCategoryPair::OTHER; }; namespace baseprofiler::category { -// Each category pair name constructs a MarkerCategory. +// Each category-pair (aka subcategory) name constructs a MarkerCategory. // E.g.: mozilla::baseprofiler::category::OTHER_Profiling -// Profiler macros will take the category name alone without namespace. +// Profiler macros will take the category name alone. // E.g.: `PROFILER_MARKER_UNTYPED("name", OTHER_Profiling)` # define CATEGORY_ENUM_BEGIN_CATEGORY(name, labelAsString, color) # define CATEGORY_ENUM_SUBCATEGORY(supercategory, name, labelAsString) \ @@ -254,15 +267,12 @@ MOZ_PROFILING_CATEGORY_LIST(CATEGORY_ENUM_BEGIN_CATEGORY, // Import `MarkerCategory` into this namespace. This will allow using this type // dynamically in macros that prepend `::mozilla::baseprofiler::category::` to -// the given category, e.g.: +// the given category, e.g.: E.g.: // `PROFILER_MARKER_UNTYPED("name", MarkerCategory(...))` using MarkerCategory = ::mozilla::MarkerCategory; } // namespace baseprofiler::category -// The classes below are all embedded in a `MarkerOptions` object. -class MarkerOptions; - // This marker option captures a given thread id. // If left unspecified (by default construction) during the add-marker call, the // current thread id will be used then. @@ -575,15 +585,22 @@ class MarkerInnerWindowId { uint64_t mInnerWindowId = scNoId; }; -// This class combines each of the possible marker options above. +// This class combines a compulsory category with the above marker options. +// To provide options to add-marker functions, first pick a MarkerCategory +// object, then options may be added with WithOptions(), e.g.: +// `mozilla::baseprofiler::category::OTHER_profiling` +// `mozilla::baseprofiler::category::DOM.WithOptions( +// MarkerThreadId(1), MarkerTiming::IntervalStart())` class MarkerOptions { public: - // Constructor from individual options (including none). - // Implicit to allow `{}` and one option type as-is. - // Options that are not provided here are defaulted. In particular, timing - // defaults to `MarkerTiming::InstantNow()` when the marker is recorded. + // Implicit constructor from category. + constexpr MOZ_IMPLICIT MarkerOptions(const MarkerCategory& aCategory) + : mCategory(aCategory) {} + + // Constructor from category and other options. template - MOZ_IMPLICIT MarkerOptions(Options&&... aOptions) { + explicit MarkerOptions(const MarkerCategory& aCategory, Options&&... aOptions) + : mCategory(aCategory) { (Set(std::forward(aOptions)), ...); } @@ -604,6 +621,7 @@ class MarkerOptions { // `options.Set(MarkerThreadId(123)).Set(MarkerTiming::IntervalEnd())`. // When passed to an add-marker function, it must be an rvalue, either created // on the spot, or `std::move`d from storage, e.g.: + // `PROFILER_MARKER_UNTYPED("...", OTHER.Set(...))`; // `PROFILER_MARKER_UNTYPED("...", std::move(options).Set(...))`; // // Options can be read by their name (without "Marker"), e.g.: `o.ThreadId()`. @@ -623,6 +641,7 @@ class MarkerOptions { \ Marker##NAME& NAME##Ref() { return m##NAME; } + FUNCTIONS_ON_MEMBER(Category); FUNCTIONS_ON_MEMBER(ThreadId); FUNCTIONS_ON_MEMBER(Timing); FUNCTIONS_ON_MEMBER(Stack); @@ -632,12 +651,31 @@ class MarkerOptions { private: friend ProfileBufferEntryReader::Deserializer; + // The default constructor is only used during deserialization. + constexpr MarkerOptions() = default; + + MarkerCategory mCategory; MarkerThreadId mThreadId; MarkerTiming mTiming; MarkerStack mStack; MarkerInnerWindowId mInnerWindowId; }; +template +MarkerOptions MarkerCategory::WithOptions(Options&&... aOptions) const { + return MarkerOptions(*this, std::forward(aOptions)...); +} + +namespace baseprofiler::category { + +// Import `MarkerOptions` into this namespace. This will allow using this type +// dynamically in macros that prepend `::mozilla::baseprofiler::category::` to +// the given category, e.g.: E.g.: +// `PROFILER_MARKER_UNTYPED("name", MarkerOptions(...))` +using MarkerOptions = ::mozilla::MarkerOptions; + +} // namespace baseprofiler::category + } // namespace mozilla namespace mozilla::baseprofiler::markers { diff --git a/mozglue/tests/TestBaseProfiler.cpp b/mozglue/tests/TestBaseProfiler.cpp index 6c8999f03f98..7b90e0db3740 100644 --- a/mozglue/tests/TestBaseProfiler.cpp +++ b/mozglue/tests/TestBaseProfiler.cpp @@ -3340,9 +3340,9 @@ MOZ_NEVER_INLINE unsigned long long Fibonacci(unsigned long long n) { } unsigned long long f1 = Fibonacci(n - 1); if (DEPTH < MAX_MARKER_DEPTH) { - BASE_PROFILER_MARKER_TEXT("fib", OTHER, - MarkerTiming::IntervalUntilNowFrom(start), - std::to_string(DEPTH)); + BASE_PROFILER_MARKER_TEXT( + "fib", OTHER.WithOptions(MarkerTiming::IntervalUntilNowFrom(start)), + std::to_string(DEPTH)); } return f2 + f1; } @@ -3387,7 +3387,8 @@ void TestProfiler() { SleepMilli(5); auto cause = baseprofiler::profiler_capture_backtrace(); AUTO_BASE_PROFILER_MARKER_TEXT( - "fibonacci", OTHER, MarkerStack::TakeBacktrace(std::move(cause)), + "fibonacci", + OTHER.WithOptions(MarkerStack::TakeBacktrace(std::move(cause))), "First leaf call"); static const unsigned long long fibStart = 37; printf("Fibonacci(%llu)...\n", fibStart); @@ -3400,7 +3401,7 @@ void TestProfiler() { std::thread threadCancelFib([]() { AUTO_BASE_PROFILER_REGISTER_THREAD("fibonacci canceller"); SleepMilli(5); - AUTO_BASE_PROFILER_MARKER_TEXT("fibonacci", OTHER, {}, "Canceller"); + AUTO_BASE_PROFILER_MARKER_TEXT("fibonacci", OTHER, "Canceller"); static const int waitMaxSeconds = 10; for (int i = 0; i < waitMaxSeconds; ++i) { if (sStopFibonacci) { @@ -3417,14 +3418,14 @@ void TestProfiler() { }); { - AUTO_BASE_PROFILER_MARKER_TEXT("main thread", OTHER, {}, + AUTO_BASE_PROFILER_MARKER_TEXT("main thread", OTHER, "joining fibonacci thread"); AUTO_BASE_PROFILER_THREAD_SLEEP; threadFib.join(); } { - AUTO_BASE_PROFILER_MARKER_TEXT("main thread", OTHER, {}, + AUTO_BASE_PROFILER_MARKER_TEXT("main thread", OTHER, "joining fibonacci-canceller thread"); sStopFibonacci = true; AUTO_BASE_PROFILER_THREAD_SLEEP; @@ -3449,18 +3450,20 @@ void TestProfiler() { baseprofiler::FileIOMarkerPayload( "operation", "source", "filename", TimeStamp::NowUnfuzzed(), TimeStamp::NowUnfuzzed(), std::move(cause))); - baseprofiler::AddMarker("m2fileio", mozilla::baseprofiler::category::OTHER, - {}, mozilla::baseprofiler::markers::FileIO{}, "op2", - "src2", "f2", MarkerThreadId{}); - baseprofiler::AddMarker( - "m2fileio-capture", mozilla::baseprofiler::category::OTHER, - MarkerStack::Capture(), mozilla::baseprofiler::markers::FileIO{}, "op2", - "src2", "f2", MarkerThreadId{}); - baseprofiler::AddMarker( - "m2fileio-take-backtrace", mozilla::baseprofiler::category::OTHER, - MarkerStack::TakeBacktrace(baseprofiler::profiler_capture_backtrace()), - mozilla::baseprofiler::markers::FileIO{}, "op2", "src2", "f2", + baseprofiler::AddMarker( + "m2fileio", mozilla::baseprofiler::category::OTHER, "op2", "src2", "f2", MarkerThreadId{}); + baseprofiler::AddMarker( + "m2fileio-capture", + mozilla::baseprofiler::category::OTHER.WithOptions( + MarkerStack::Capture()), + "op2", "src2", "f2", MarkerThreadId{}); + baseprofiler::AddMarker( + "m2fileio-take-backtrace", + mozilla::baseprofiler::category::OTHER.WithOptions( + MarkerStack::TakeBacktrace( + baseprofiler::profiler_capture_backtrace())), + "op2", "src2", "f2", MarkerThreadId{}); baseprofiler::profiler_add_marker( "UserTimingMarkerPayload", baseprofiler::ProfilingCategoryPair::OTHER, @@ -3490,105 +3493,66 @@ void TestProfiler() { baseprofiler::LogMarkerPayload("module", "text", TimeStamp::NowUnfuzzed())); - MOZ_RELEASE_ASSERT( - baseprofiler::AddMarker("markers 2.0 without options (omitted)", - mozilla::baseprofiler::category::OTHER)); + MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( + "markers 2.0 without options", mozilla::baseprofiler::category::OTHER)); MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 without options (implicit brace-init)", - mozilla::baseprofiler::category::OTHER, {})); + "markers 2.0 with option", + mozilla::baseprofiler::category::OTHER.WithOptions( + MarkerInnerWindowId(123)))); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 without options (explicit init)", - mozilla::baseprofiler::category::OTHER, MarkerOptions())); + MOZ_RELEASE_ASSERT(baseprofiler::AddMarker<>( + "default-templated markers 2.0 without options", + mozilla::baseprofiler::category::OTHER)); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 without options (explicit brace-init)", - mozilla::baseprofiler::category::OTHER, MarkerOptions{})); - - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 with one option (implicit)", - mozilla::baseprofiler::category::OTHER, MarkerInnerWindowId(123))); - - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 with one option (implicit brace-init)", - mozilla::baseprofiler::category::OTHER, {MarkerInnerWindowId(123)})); - - MOZ_RELEASE_ASSERT( - baseprofiler::AddMarker("markers 2.0 with one option (explicit init)", - mozilla::baseprofiler::category::OTHER, - MarkerOptions(MarkerInnerWindowId(123)))); - - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 with one option (explicit brace-init)", - mozilla::baseprofiler::category::OTHER, - MarkerOptions{MarkerInnerWindowId(123)})); - - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 with two options (implicit brace-init)", - mozilla::baseprofiler::category::OTHER, - {MarkerInnerWindowId(123), MarkerStack::Capture()})); - - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 with two options (explicit init)", - mozilla::baseprofiler::category::OTHER, - MarkerOptions(MarkerInnerWindowId(123), MarkerStack::Capture()))); - - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "markers 2.0 with two options (explicit brace-init)", - mozilla::baseprofiler::category::OTHER, - MarkerOptions{MarkerInnerWindowId(123), MarkerStack::Capture()})); - - MOZ_RELEASE_ASSERT( - baseprofiler::AddMarker("default-templated markers 2.0 without options", - mozilla::baseprofiler::category::OTHER)); - - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( + MOZ_RELEASE_ASSERT(baseprofiler::AddMarker<>( "default-templated markers 2.0 with option", - mozilla::baseprofiler::category::OTHER, MarkerInnerWindowId(123))); + mozilla::baseprofiler::category::OTHER.WithOptions( + MarkerInnerWindowId(123)))); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "explicitly-default-templated markers 2.0 without options", - mozilla::baseprofiler::category::OTHER, {}, - ::mozilla::baseprofiler::markers::NoPayload{})); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker<::mozilla::baseprofiler::markers::NoPayload>( + "explicitly-default-templated markers 2.0 without options", + mozilla::baseprofiler::category::OTHER)); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "explicitly-default-templated markers 2.0 with option", - mozilla::baseprofiler::category::OTHER, MarkerInnerWindowId(123), - ::mozilla::baseprofiler::markers::NoPayload{})); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker<::mozilla::baseprofiler::markers::NoPayload>( + "explicitly-default-templated markers 2.0 with option", + mozilla::baseprofiler::category::OTHER.WithOptions( + MarkerInnerWindowId(123)))); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "tracing", mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::Tracing{}, "category")); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker( + "tracing", mozilla::baseprofiler::category::OTHER, "category")); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "mark", mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::UserTimingMark{}, "mark name")); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker( + "mark", mozilla::baseprofiler::category::OTHER, "mark name")); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "measure", mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::UserTimingMeasure{}, "measure name", + MOZ_RELEASE_ASSERT(baseprofiler::AddMarker< + mozilla::baseprofiler::markers::UserTimingMeasure>( + "measure", mozilla::baseprofiler::category::OTHER, "measure name", Some(ProfilerString8View("start")), Some(ProfilerString8View("end")))); MOZ_RELEASE_ASSERT( - baseprofiler::AddMarker("hang", mozilla::baseprofiler::category::OTHER, - {}, mozilla::baseprofiler::markers::Hang{})); + baseprofiler::AddMarker( + "hang", mozilla::baseprofiler::category::OTHER)); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "longtask", mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::LongTask{})); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker( + "longtask", mozilla::baseprofiler::category::OTHER)); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "text", mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::Text{}, "text text")); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker( + "text", mozilla::baseprofiler::category::OTHER, "text text")); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "log", mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::Log{}, "module", "text")); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker( + "log", mozilla::baseprofiler::category::OTHER, "module", "text")); - MOZ_RELEASE_ASSERT(baseprofiler::AddMarker( - "media sample", mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::MediaSample{}, 123, 456)); + MOZ_RELEASE_ASSERT( + baseprofiler::AddMarker( + "media sample", mozilla::baseprofiler::category::OTHER, 123, 456)); printf("Sleep 1s...\n"); { @@ -3739,6 +3703,12 @@ void TestMarkerCategory() { # undef CATEGORY_ENUM_SUBCATEGORY # undef CATEGORY_ENUM_END_CATEGORY + static_assert( + std::is_same_v().WithOptions()), + mozilla::MarkerOptions>, + "MarkerCategory::WithOptions() should return a MarkerOptions"); + printf("TestMarkerCategory done\n"); } @@ -3750,22 +3720,22 @@ void TestMarkerNoPayload() { mozilla::ProfileChunkedBuffer::ThreadSafety::WithoutMutex, chunkManager); mozilla::ProfileBufferBlockIndex i0 = - mozilla::baseprofiler::AddMarkerToBuffer( + mozilla::baseprofiler::AddMarkerToBuffer<>( buffer, "literal", mozilla::baseprofiler::category::OTHER_Profiling); MOZ_RELEASE_ASSERT(i0); const std::string dynamic = "dynamic"; mozilla::ProfileBufferBlockIndex i1 = - mozilla::baseprofiler::AddMarkerToBuffer( + mozilla::baseprofiler::AddMarkerToBuffer<>( buffer, dynamic, - mozilla::baseprofiler::category::GRAPHICS_FlushingAsyncPaints, {}); + mozilla::baseprofiler::category::GRAPHICS_FlushingAsyncPaints); MOZ_RELEASE_ASSERT(i1); MOZ_RELEASE_ASSERT(i1 > i0); mozilla::ProfileBufferBlockIndex i2 = - mozilla::baseprofiler::AddMarkerToBuffer( + mozilla::baseprofiler::AddMarkerToBuffer<>( buffer, std::string_view("string_view"), - mozilla::baseprofiler::category::GRAPHICS_FlushingAsyncPaints, {}); + mozilla::baseprofiler::category::GRAPHICS_FlushingAsyncPaints); MOZ_RELEASE_ASSERT(i2); MOZ_RELEASE_ASSERT(i2 > i1); @@ -3797,55 +3767,72 @@ void TestUserMarker() { mozilla::ProfileChunkedBuffer buffer( mozilla::ProfileChunkedBuffer::ThreadSafety::WithoutMutex, chunkManager); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, {}, - MarkerTypeTestMinimal{}, std::string("payload text"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, + std::string("payload text"))); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerThreadId(123), MarkerTypeTestMinimal{}, - std::string("ThreadId(123)"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerThreadId(123)), + std::string("ThreadId(123)"))); auto start = mozilla::TimeStamp::NowUnfuzzed(); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerTiming::InstantAt(start), MarkerTypeTestMinimal{}, - std::string("InstantAt(start)"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerTiming::InstantAt(start)), + std::string("InstantAt(start)"))); auto then = mozilla::TimeStamp::NowUnfuzzed(); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerTiming::IntervalStart(start), MarkerTypeTestMinimal{}, - std::string("IntervalStart(start)"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerTiming::IntervalStart(start)), + std::string("IntervalStart(start)"))); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerTiming::IntervalEnd(then), MarkerTypeTestMinimal{}, - std::string("IntervalEnd(then)"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerTiming::IntervalEnd(then)), + std::string("IntervalEnd(then)"))); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerTiming::Interval(start, then), MarkerTypeTestMinimal{}, - std::string("Interval(start, then)"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerTiming::Interval(start, then)), + std::string("Interval(start, then)"))); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerTiming::IntervalUntilNowFrom(start), - MarkerTypeTestMinimal{}, std::string("IntervalUntilNowFrom(start)"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerTiming::IntervalUntilNowFrom(start)), + std::string("IntervalUntilNowFrom(start)"))); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerStack::NoStack(), MarkerTypeTestMinimal{}, - std::string("NoStack"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerStack::NoStack()), + std::string("NoStack"))); // Note: We cannot test stack-capture here, because the profiler is not // initialized. - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, "test2", mozilla::baseprofiler::category::OTHER_Profiling, - mozilla::MarkerInnerWindowId(123), MarkerTypeTestMinimal{}, - std::string("InnerWindowId(123)"))); + MOZ_RELEASE_ASSERT( + mozilla::baseprofiler::AddMarkerToBuffer( + buffer, "test2", + mozilla::baseprofiler::category::OTHER_Profiling.WithOptions( + mozilla::MarkerInnerWindowId(123)), + std::string("InnerWindowId(123)"))); # ifdef DEBUG buffer.Dump(); @@ -3875,42 +3862,47 @@ void TestPredefinedMarkers() { mozilla::ProfileChunkedBuffer buffer( mozilla::ProfileChunkedBuffer::ThreadSafety::WithoutMutex, chunkManager); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::Tracing>( buffer, std::string_view("tracing"), - mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::Tracing{}, "category")); + mozilla::baseprofiler::category::OTHER, "category")); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::UserTimingMark>( buffer, std::string_view("mark"), mozilla::baseprofiler::category::OTHER, - {}, mozilla::baseprofiler::markers::UserTimingMark{}, "mark name")); + "mark name")); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::UserTimingMeasure>( buffer, std::string_view("measure"), - mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::UserTimingMeasure{}, "measure name ", + mozilla::baseprofiler::category::OTHER, "measure name ", mozilla::Some(mozilla::ProfilerString8View(" start ")), mozilla::Some(mozilla::ProfilerString8View("end")))); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( - buffer, std::string_view("hang"), mozilla::baseprofiler::category::OTHER, - {}, mozilla::baseprofiler::markers::Hang{})); + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::Hang>( + buffer, std::string_view("hang"), + mozilla::baseprofiler::category::OTHER)); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::LongTask>( buffer, std::string_view("long task"), - mozilla::baseprofiler::category::OTHER, {}, - mozilla::baseprofiler::markers::LongTask{})); + mozilla::baseprofiler::category::OTHER)); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::Text>( buffer, std::string_view("text"), mozilla::baseprofiler::category::OTHER, - {}, mozilla::baseprofiler::markers::Text{}, "text text")); + "text text")); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::Log>( buffer, std::string_view("log"), mozilla::baseprofiler::category::OTHER, - {}, mozilla::baseprofiler::markers::Log{}, "module", "text")); + "module", "text")); - MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer( + MOZ_RELEASE_ASSERT(mozilla::baseprofiler::AddMarkerToBuffer< + mozilla::baseprofiler::markers::MediaSample>( buffer, std::string_view("media"), mozilla::baseprofiler::category::OTHER, - {}, mozilla::baseprofiler::markers::MediaSample{}, 123, 456)); + 123, 456)); # ifdef DEBUG buffer.Dump(); @@ -3952,7 +3944,7 @@ void TestProfiler() { # ifndef AUTO_BASE_PROFILER_MARKER_TEXT # error AUTO_BASE_PROFILER_MARKER_TEXT not #defined # endif // AUTO_BASE_PROFILER_MARKER_TEXT - AUTO_BASE_PROFILER_MARKER_TEXT(catch, catch, catch, catch); + AUTO_BASE_PROFILER_MARKER_TEXT(catch, catch, catch); # ifndef AUTO_BASE_PROFILER_LABEL # error AUTO_BASE_PROFILER_LABEL not #defined @@ -3968,18 +3960,17 @@ void TestProfiler() { # error BASE_PROFILER_MARKER_UNTYPED not #defined # endif // BASE_PROFILER_MARKER_UNTYPED BASE_PROFILER_MARKER_UNTYPED(catch, catch); - BASE_PROFILER_MARKER_UNTYPED(catch, catch, catch); # ifndef BASE_PROFILER_MARKER # error BASE_PROFILER_MARKER not #defined # endif // BASE_PROFILER_MARKER + BASE_PROFILER_MARKER(catch, catch, catch); BASE_PROFILER_MARKER(catch, catch, catch, catch); - BASE_PROFILER_MARKER(catch, catch, catch, catch, catch); # ifndef BASE_PROFILER_MARKER_TEXT # error BASE_PROFILER_MARKER_TEXT not #defined # endif // BASE_PROFILER_MARKER_TEXT - BASE_PROFILER_MARKER_TEXT(catch, catch, catch, catch); + BASE_PROFILER_MARKER_TEXT(catch, catch, catch); MOZ_RELEASE_ASSERT(!mozilla::baseprofiler::profiler_get_backtrace(), "profiler_get_backtrace should return nullptr"); diff --git a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp index 7175e3d6f465..726ba3a4ae31 100644 --- a/toolkit/components/extensions/webrequest/ChannelWrapper.cpp +++ b/toolkit/components/extensions/webrequest/ChannelWrapper.cpp @@ -265,9 +265,10 @@ void ChannelWrapper::Resume(const nsCString& aText, ErrorResult& aRv) { if (nsCOMPtr chan = MaybeChannel()) { rv = chan->Resume(); - PROFILER_MARKER_TEXT("Extension Suspend", NETWORK, - MarkerTiming::IntervalUntilNowFrom(mSuspendTime), - aText); + PROFILER_MARKER_TEXT( + "Extension Suspend", + NETWORK.WithOptions(MarkerTiming::IntervalUntilNowFrom(mSuspendTime)), + aText); } if (NS_FAILED(rv)) { aRv.Throw(rv); diff --git a/toolkit/components/telemetry/core/Stopwatch.cpp b/toolkit/components/telemetry/core/Stopwatch.cpp index fe34d40ccf06..871b2de8538e 100644 --- a/toolkit/components/telemetry/core/Stopwatch.cpp +++ b/toolkit/components/telemetry/core/Stopwatch.cpp @@ -341,9 +341,10 @@ int32_t Timers::Finish(JSContext* aCx, const nsAString& aHistogram, markerText.AppendLiteral(":"); markerText.Append(NS_ConvertUTF16toUTF8(aKey)); } - PROFILER_MARKER_TEXT("TelemetryStopwatch", OTHER, - MarkerTiming::IntervalUntilNowFrom(timer->StartTime()), - markerText); + PROFILER_MARKER_TEXT( + "TelemetryStopwatch", + OTHER.WithOptions(MarkerTiming::IntervalUntilNowFrom(timer->StartTime())), + markerText); #endif if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE && !mSuppressErrors) { LogError(aCx, nsPrintfCString( diff --git a/tools/profiler/public/ProfilerMarkers.h b/tools/profiler/public/ProfilerMarkers.h index 353ed8f20f41..ed472c6ab44c 100644 --- a/tools/profiler/public/ProfilerMarkers.h +++ b/tools/profiler/public/ProfilerMarkers.h @@ -22,11 +22,11 @@ // types. // // To then record markers: -// - Use `baseprofiler::AddMarker(...)` from mozglue or other libraries that are -// outside of xul, especially if they may happen outside of xpcom's lifetime -// (typically startup, shutdown, or tests). +// - Use `baseprofiler::AddMarker(...)` from +// mozglue or other libraries that are outside of xul, especially if they may +// happen outside of xpcom's lifetime (typically startup, shutdown, or tests). // - Otherwise #include "ProfilerMarkers.h" instead, and use -// `profiler_add_marker(...)`. +// `profiler_add_marker(...)`. // See these functions for more details. #ifndef ProfilerMarkers_h @@ -40,10 +40,10 @@ #ifndef MOZ_GECKO_PROFILER -# define PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) -# define PROFILER_MARKER(markerName, categoryName, options, MarkerType, ...) -# define PROFILER_MARKER_TEXT(markerName, categoryName, options, text) -# define AUTO_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) +# define PROFILER_MARKER_UNTYPED(markerName, options) +# define PROFILER_MARKER(markerName, options, MarkerType, ...) +# define PROFILER_MARKER_TEXT(markerName, options, text) +# define AUTO_PROFILER_MARKER_TEXT(markerName, options, text) #else // ndef MOZ_GECKO_PROFILER @@ -53,79 +53,41 @@ namespace geckoprofiler::category { using namespace ::mozilla::baseprofiler::category; } -// Add a marker to a given buffer. `AddMarker()` and related macros should be -// used in most cases, see below for more information about them and the -// paramters; This function may be useful when markers need to be recorded in a -// local buffer outside of the main profiler buffer. -template +template mozilla::ProfileBufferBlockIndex AddMarkerToBuffer( mozilla::ProfileChunkedBuffer& aBuffer, const mozilla::ProfilerString8View& aName, - const mozilla::MarkerCategory& aCategory, mozilla::MarkerOptions&& aOptions, - MarkerType aMarkerType, const PayloadArguments&... aPayloadArguments) { - mozilla::Unused << aMarkerType; // Only the empty object type is useful. + mozilla::MarkerOptions&& aOptions, const Ts&... aTs) { return mozilla::base_profiler_markers_detail::AddMarkerToBuffer( - aBuffer, aName, aCategory, std::move(aOptions), - ::profiler_capture_backtrace_into, aPayloadArguments...); + aBuffer, aName, std::move(aOptions), ::profiler_capture_backtrace_into, + aTs...); } -// Add a marker (without payload) to a given buffer. -inline mozilla::ProfileBufferBlockIndex AddMarkerToBuffer( - mozilla::ProfileChunkedBuffer& aBuffer, - const mozilla::ProfilerString8View& aName, - const mozilla::MarkerCategory& aCategory, - mozilla::MarkerOptions&& aOptions = {}) { - return AddMarkerToBuffer(aBuffer, aName, aCategory, std::move(aOptions), - mozilla::baseprofiler::markers::NoPayload{}); -} - -// Add a marker to the Gecko Profiler buffer. -// - aName: Main name of this marker. -// - aCategory: Category for this marker. -// - aOptions: Optional settings (such as timing, inner window id, -// backtrace...), see `MarkerOptions` for details. -// - aMarkerType: Empty object that specifies the type of marker. -// - aPayloadArguments: Arguments expected by this marker type's -// ` StreamJSONMarkerData` function. -template +template mozilla::ProfileBufferBlockIndex profiler_add_marker( const mozilla::ProfilerString8View& aName, - const mozilla::MarkerCategory& aCategory, mozilla::MarkerOptions&& aOptions, - MarkerType aMarkerType, const PayloadArguments&... aPayloadArguments) { + mozilla::MarkerOptions&& aOptions, const Ts&... aTs) { if (!profiler_can_accept_markers()) { return {}; } - return ::AddMarkerToBuffer(profiler_markers_detail::CachedCoreBuffer(), aName, - aCategory, std::move(aOptions), aMarkerType, - aPayloadArguments...); + return ::AddMarkerToBuffer( + profiler_markers_detail::CachedCoreBuffer(), aName, std::move(aOptions), + aTs...); } -// Add a marker (without payload) to the Gecko Profiler buffer. -inline mozilla::ProfileBufferBlockIndex profiler_add_marker( - const mozilla::ProfilerString8View& aName, - const mozilla::MarkerCategory& aCategory, - mozilla::MarkerOptions&& aOptions = {}) { - return profiler_add_marker(aName, aCategory, std::move(aOptions), - mozilla::baseprofiler::markers::NoPayload{}); -} - -// Same as `profiler_add_marker()` (without payload). This macro is safe to use -// even if MOZ_GECKO_PROFILER is not #defined. -# define PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) \ +# define PROFILER_MARKER_UNTYPED(markerName, options) \ do { \ AUTO_PROFILER_STATS(PROFILER_MARKER_UNTYPED); \ - ::profiler_add_marker( \ - markerName, ::geckoprofiler::category::categoryName, ##__VA_ARGS__); \ + ::profiler_add_marker<>(markerName, ::geckoprofiler::category::options); \ } while (false) -// Same as `profiler_add_marker()` (with payload). This macro is safe to use -// even if MOZ_GECKO_PROFILER is not #defined. -# define PROFILER_MARKER(markerName, categoryName, options, MarkerType, ...) \ - do { \ - AUTO_PROFILER_STATS(PROFILER_MARKER_with_##MarkerType); \ - ::profiler_add_marker( \ - markerName, ::geckoprofiler::category::categoryName, options, \ - ::geckoprofiler::markers::MarkerType{}, ##__VA_ARGS__); \ +# define PROFILER_MARKER(markerName, options, MarkerType, ...) \ + do { \ + AUTO_PROFILER_STATS(PROFILER_MARKER_with_##MarkerType); \ + ::profiler_add_marker<::geckoprofiler::markers::MarkerType>( \ + markerName, ::geckoprofiler::category::options, ##__VA_ARGS__); \ } while (false) namespace geckoprofiler::markers { @@ -133,14 +95,11 @@ namespace geckoprofiler::markers { using Text = ::mozilla::baseprofiler::markers::Text; } // namespace geckoprofiler::markers -// Add a text marker. This macro is safe to use even if MOZ_GECKO_PROFILER is -// not #defined. -# define PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ - do { \ - AUTO_PROFILER_STATS(PROFILER_MARKER_TEXT); \ - ::profiler_add_marker(markerName, \ - ::geckoprofiler::category::categoryName, options, \ - ::geckoprofiler::markers::Text{}, text); \ +# define PROFILER_MARKER_TEXT(markerName, options, text) \ + do { \ + AUTO_PROFILER_STATS(PROFILER_MARKER_TEXT); \ + ::profiler_add_marker<::geckoprofiler::markers::Text>( \ + markerName, ::geckoprofiler::category::options, text); \ } while (false) // RAII object that adds a PROFILER_MARKER_TEXT when destroyed; the marker's @@ -149,13 +108,9 @@ using Text = ::mozilla::baseprofiler::markers::Text; class MOZ_RAII AutoProfilerTextMarker { public: AutoProfilerTextMarker(const char* aMarkerName, - const mozilla::MarkerCategory& aCategory, mozilla::MarkerOptions&& aOptions, const nsACString& aText) - : mMarkerName(aMarkerName), - mCategory(aCategory), - mOptions(std::move(aOptions)), - mText(aText) { + : mMarkerName(aMarkerName), mOptions(std::move(aOptions)), mText(aText) { MOZ_ASSERT(mOptions.Timing().EndTime().IsNull(), "AutoProfilerTextMarker options shouldn't have an end time"); if (mOptions.Timing().StartTime().IsNull()) { @@ -165,25 +120,20 @@ class MOZ_RAII AutoProfilerTextMarker { ~AutoProfilerTextMarker() { mOptions.TimingRef().SetIntervalEnd(); - AUTO_PROFILER_STATS(AUTO_PROFILER_MARKER_TEXT); - profiler_add_marker( + PROFILER_MARKER_TEXT( mozilla::ProfilerString8View::WrapNullTerminatedString(mMarkerName), - mCategory, std::move(mOptions), geckoprofiler::markers::Text{}, mText); + MarkerOptions(std::move(mOptions)), mText); } protected: const char* mMarkerName; - mozilla::MarkerCategory mCategory; mozilla::MarkerOptions mOptions; nsCString mText; }; -// Creates an AutoProfilerTextMarker RAII object. This macro is safe to use -// even if MOZ_GECKO_PROFILER is not #defined. -# define AUTO_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ - AutoProfilerTextMarker PROFILER_RAII( \ - markerName, ::mozilla::baseprofiler::category::categoryName, options, \ - text) +# define AUTO_PROFILER_MARKER_TEXT(markerName, options, text) \ + AutoProfilerTextMarker PROFILER_RAII( \ + markerName, ::mozilla::baseprofiler::category::options, text) #endif // nfed MOZ_GECKO_PROFILER else diff --git a/tools/profiler/tests/gtest/GeckoProfiler.cpp b/tools/profiler/tests/gtest/GeckoProfiler.cpp index fc3044c66f38..e24da6581f55 100644 --- a/tools/profiler/tests/gtest/GeckoProfiler.cpp +++ b/tools/profiler/tests/gtest/GeckoProfiler.cpp @@ -523,7 +523,7 @@ TEST(GeckoProfiler, Pause) // Check that we are writing markers while not paused. info1 = profiler_get_buffer_info(); - PROFILER_MARKER_UNTYPED("Not paused", OTHER, {}); + PROFILER_MARKER_UNTYPED("Not paused", OTHER); info2 = profiler_get_buffer_info(); ASSERT_TRUE(info1->mRangeEnd != info2->mRangeEnd); @@ -540,10 +540,10 @@ TEST(GeckoProfiler, Pause) // Check that we are now writing markers while paused. info1 = profiler_get_buffer_info(); - PROFILER_MARKER_UNTYPED("Paused", OTHER, {}); + PROFILER_MARKER_UNTYPED("Paused", OTHER); info2 = profiler_get_buffer_info(); ASSERT_TRUE(info1->mRangeEnd == info2->mRangeEnd); - PROFILER_MARKER_UNTYPED("Paused v2", OTHER, {}); + PROFILER_MARKER_UNTYPED("Paused v2", OTHER); Maybe info3 = profiler_get_buffer_info(); ASSERT_TRUE(info2->mRangeEnd == info3->mRangeEnd); @@ -650,10 +650,10 @@ TEST(GeckoProfiler, Markers) { AUTO_PROFILER_TRACING_MARKER("C", "auto tracing", OTHER); } - PROFILER_MARKER_UNTYPED("M1", OTHER, {}); + PROFILER_MARKER_UNTYPED("M1", OTHER); PROFILER_ADD_MARKER_WITH_PAYLOAD("M2", OTHER, TracingMarkerPayload, ("C", TRACING_EVENT, ts0)); - PROFILER_MARKER_UNTYPED("M3", OTHER, {}); + PROFILER_MARKER_UNTYPED("M3", OTHER); PROFILER_ADD_MARKER_WITH_PAYLOAD( "M4", OTHER, TracingMarkerPayload, ("C", TRACING_EVENT, ts0, mozilla::Nothing(), profiler_get_backtrace())); @@ -704,20 +704,19 @@ TEST(GeckoProfiler, Markers) // Test basic markers 2.0. MOZ_RELEASE_ASSERT( - profiler_add_marker("default-templated markers 2.0 with empty options", - geckoprofiler::category::OTHER, {})); + profiler_add_marker<>("default-templated markers 2.0 with empty options", + geckoprofiler::category::OTHER)); - PROFILER_MARKER_UNTYPED( - "default-templated markers 2.0 with option", OTHER, - MarkerStack::TakeBacktrace(profiler_capture_backtrace())); + PROFILER_MARKER_UNTYPED("default-templated markers 2.0 with option", + OTHER.WithOptions(MarkerStack::TakeBacktrace( + profiler_capture_backtrace()))); PROFILER_MARKER("explicitly-default-templated markers 2.0 with empty options", - OTHER, {}, NoPayload); + OTHER, NoPayload); - MOZ_RELEASE_ASSERT(profiler_add_marker( + MOZ_RELEASE_ASSERT(profiler_add_marker<::geckoprofiler::markers::NoPayload>( "explicitly-default-templated markers 2.0 with option", - geckoprofiler::category::OTHER, {}, - ::geckoprofiler::markers::NoPayload{})); + geckoprofiler::category::OTHER)); // Used in markers below. TimeStamp ts1 = TimeStamp::NowUnfuzzed(); @@ -739,18 +738,20 @@ TEST(GeckoProfiler, Markers) "FileIOMarkerPayload marker", OTHER, FileIOMarkerPayload, ("operation", "source", "filename", ts1, ts2, nullptr)); - MOZ_RELEASE_ASSERT(profiler_add_marker( - "FileIOMarkerPayload marker 2.0", geckoprofiler::category::OTHER, - MarkerTiming::Interval(ts1, ts2), geckoprofiler::markers::FileIO{}, + MOZ_RELEASE_ASSERT(profiler_add_marker( + "FileIOMarkerPayload marker 2.0", + geckoprofiler::category::OTHER.WithOptions( + MarkerTiming::Interval(ts1, ts2)), "operation", "source", "filename", MarkerThreadId{})); PROFILER_ADD_MARKER_WITH_PAYLOAD( "FileIOMarkerPayload marker off-MT", OTHER, FileIOMarkerPayload, ("operation2", "source2", "filename2", ts1, ts2, nullptr, Some(123))); - MOZ_RELEASE_ASSERT(profiler_add_marker( - "FileIOMarkerPayload marker 2.0 off-MT", geckoprofiler::category::OTHER, - MarkerTiming::Interval(ts1, ts2), geckoprofiler::markers::FileIO{}, + MOZ_RELEASE_ASSERT(profiler_add_marker( + "FileIOMarkerPayload marker 2.0 off-MT", + geckoprofiler::category::OTHER.WithOptions( + MarkerTiming::Interval(ts1, ts2)), "operation2", "source2", "filename2", MarkerThreadId{123})); // Other markers in alphabetical order of payload class names. @@ -857,42 +858,36 @@ TEST(GeckoProfiler, Markers) mozilla::ipc::MessageDirection::eSending, mozilla::ipc::MessagePhase::Endpoint, false, ts1)); - MOZ_RELEASE_ASSERT( - profiler_add_marker("Tracing", geckoprofiler::category::OTHER, {}, - geckoprofiler::markers::Tracing{}, "category")); - - MOZ_RELEASE_ASSERT(profiler_add_marker( - "UserTimingMark", geckoprofiler::category::OTHER, {}, - geckoprofiler::markers::UserTimingMark{}, "mark name")); - - MOZ_RELEASE_ASSERT(profiler_add_marker( - "UserTimingMeasure", geckoprofiler::category::OTHER, {}, - geckoprofiler::markers::UserTimingMeasure{}, "measure name", - Some(mozilla::ProfilerString8View("start")), - Some(mozilla::ProfilerString8View("end")))); - - MOZ_RELEASE_ASSERT(profiler_add_marker("Hang", geckoprofiler::category::OTHER, - {}, geckoprofiler::markers::Hang{})); - - MOZ_RELEASE_ASSERT(profiler_add_marker("LongTask", - geckoprofiler::category::OTHER, {}, - geckoprofiler::markers::LongTask{})); - - MOZ_RELEASE_ASSERT(profiler_add_marker("Text", geckoprofiler::category::OTHER, - {}, geckoprofiler::markers::Text{}, - "Text text")); - - MOZ_RELEASE_ASSERT(profiler_add_marker("Log", geckoprofiler::category::OTHER, - {}, geckoprofiler::markers::Log{}, - "module", "log text")); + MOZ_RELEASE_ASSERT(profiler_add_marker( + "Tracing", geckoprofiler::category::OTHER, "category")); MOZ_RELEASE_ASSERT( - profiler_add_marker("MediaSample", geckoprofiler::category::OTHER, {}, - geckoprofiler::markers::MediaSample{}, 123, 456)); + profiler_add_marker( + "UserTimingMark", geckoprofiler::category::OTHER, "mark name")); - MOZ_RELEASE_ASSERT(profiler_add_marker("Budget", - geckoprofiler::category::OTHER, {}, - geckoprofiler::markers::Budget{})); + MOZ_RELEASE_ASSERT( + profiler_add_marker( + "UserTimingMeasure", geckoprofiler::category::OTHER, "measure name", + Some(mozilla::ProfilerString8View("start")), + Some(mozilla::ProfilerString8View("end")))); + + MOZ_RELEASE_ASSERT(profiler_add_marker( + "Hang", geckoprofiler::category::OTHER)); + + MOZ_RELEASE_ASSERT(profiler_add_marker( + "LongTask", geckoprofiler::category::OTHER)); + + MOZ_RELEASE_ASSERT(profiler_add_marker( + "Text", geckoprofiler::category::OTHER, "Text text")); + + MOZ_RELEASE_ASSERT(profiler_add_marker( + "Log", geckoprofiler::category::OTHER, "module", "log text")); + + MOZ_RELEASE_ASSERT(profiler_add_marker( + "MediaSample", geckoprofiler::category::OTHER, 123, 456)); + + MOZ_RELEASE_ASSERT(profiler_add_marker( + "Budget", geckoprofiler::category::OTHER)); SpliceableChunkedJSONWriter w; w.Start(); @@ -2020,7 +2015,7 @@ TEST(GeckoProfiler, BaseProfilerHandOff) // Add at least a marker, which should go straight into the buffer. Maybe info0 = baseprofiler::profiler_get_buffer_info(); - BASE_PROFILER_MARKER_UNTYPED("Marker from base profiler", OTHER, {}); + BASE_PROFILER_MARKER_UNTYPED("Marker from base profiler", OTHER); Maybe info1 = baseprofiler::profiler_get_buffer_info(); ASSERT_GT(info1->mRangeEnd, info0->mRangeEnd); diff --git a/xpcom/components/nsCategoryManager.cpp b/xpcom/components/nsCategoryManager.cpp index e62006721957..ec438b168c1d 100644 --- a/xpcom/components/nsCategoryManager.cpp +++ b/xpcom/components/nsCategoryManager.cpp @@ -677,8 +677,9 @@ void NS_CreateServicesFromCategory(const char* aCategory, nsISupports* aOrigin, #ifdef MOZ_GECKO_PROFILER nsPrintfCString profilerStr("%s (%s)", aObserverTopic, entryString.get()); - AUTO_PROFILER_MARKER_TEXT("Category observer notification", OTHER, - MarkerStack::Capture(), profilerStr); + AUTO_PROFILER_MARKER_TEXT("Category observer notification", + OTHER.WithOptions(MarkerStack::Capture()), + profilerStr); AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING_NONSENSITIVE( "Category observer notification -", OTHER, profilerStr); #endif diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index bd28a3fc93d1..4889799ff537 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -1325,7 +1325,7 @@ nsresult nsComponentManagerImpl::GetServiceLocked(MutexLock& aLock, { SafeMutexAutoUnlock unlock(mLock); AUTO_PROFILER_MARKER_TEXT( - "GetService", OTHER, MarkerStack::Capture(), + "GetService", OTHER.WithOptions(MarkerStack::Capture()), nsDependentCString(nsIDToCString(aEntry.CID()).get())); rv = aEntry.CreateInstance(nullptr, aIID, getter_AddRefs(service)); } diff --git a/xpcom/ds/nsObserverService.cpp b/xpcom/ds/nsObserverService.cpp index 9a9f0b202473..5707947cdc78 100644 --- a/xpcom/ds/nsObserverService.cpp +++ b/xpcom/ds/nsObserverService.cpp @@ -277,7 +277,8 @@ NS_IMETHODIMP nsObserverService::NotifyObservers(nsISupports* aSubject, mozilla::TimeStamp start = TimeStamp::Now(); - AUTO_PROFILER_MARKER_TEXT("NotifyObservers", OTHER, MarkerStack::Capture(), + AUTO_PROFILER_MARKER_TEXT("NotifyObservers", + OTHER.WithOptions(MarkerStack::Capture()), nsDependentCString(aTopic)); AUTO_PROFILER_LABEL_DYNAMIC_CSTR_NONSENSITIVE( "nsObserverService::NotifyObservers", OTHER, aTopic);