Backed out 2 changesets (bug 1667915) for platform related bustage CLOSED TREE

Backed out changeset e7a0788a1741 (bug 1667915)
Backed out changeset d34505b2d81b (bug 1667915)
This commit is contained in:
Bogdan Tara
2020-10-01 12:34:39 +03:00
parent 0bbcb5776e
commit 6fe40f83f1
26 changed files with 464 additions and 521 deletions

View File

@@ -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();
}

View File

@@ -200,7 +200,7 @@ void ChromeUtils::AddProfilerMarker(
const Optional<DOMHighResTimeStamp>& aStartTime,
const Optional<nsACString>& aText) {
#ifdef MOZ_GECKO_PROFILER
MarkerOptions options;
MarkerOptions options{::geckoprofiler::category::JS};
if (aStartTime.WasPassed()) {
RefPtr<Performance> 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
}

View File

@@ -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;

View File

@@ -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<DOMEventMarker>(
"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<DOMEventMarker>(
"DOMEvent",
geckoprofiler::category::DOM.WithOptions(
MarkerTiming::IntervalEnd(), std::move(innerWindowId)),
typeStr, aEvent->mTimeStamp);
} else
#endif
{

View File

@@ -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();
}

View File

@@ -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<SourceText<char16_t>>()
@@ -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);
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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),

View File

@@ -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<TimedImage>&& 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
}

View File

@@ -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;

View File

@@ -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),

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<TimelineConsumers> timelines = TimelineConsumers::Get();

View File

@@ -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<ChosenMarkerType>(...)` 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<ChosenMarkerType>(...)`.
// 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 <functional>
# include <string>
@@ -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 <typename MarkerType, typename... PayloadArguments>
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 <typename MarkerType = ::mozilla::baseprofiler::markers::NoPayload,
typename... Ts>
ProfileBufferBlockIndex AddMarkerToBuffer(ProfileChunkedBuffer& aBuffer,
const ProfilerString8View& aName,
MarkerOptions&& aOptions,
const Ts&... aTs) {
return base_profiler_markers_detail::AddMarkerToBuffer<MarkerType>(
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 <typename MarkerType, typename... PayloadArguments>
ProfileBufferBlockIndex AddMarker(
const ProfilerString8View& aName, const MarkerCategory& aCategory,
MarkerOptions&& aOptions, MarkerType aMarkerType,
const PayloadArguments&... aPayloadArguments) {
template <typename MarkerType = ::mozilla::baseprofiler::markers::NoPayload,
typename... Ts>
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<MarkerType>(
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

View File

@@ -82,12 +82,12 @@ struct StreamFunctionTypeHelper<R(JSONWriter&, As...)> {
// 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 <typename... Ts>
static ProfileBufferBlockIndex Serialize(ProfileChunkedBuffer& aBuffer,
const ProfilerString8View& aName,
const MarkerCategory& aCategory,
MarkerOptions&& aOptions,
const Ts&... aTs) {
static_assert(!std::is_same_v<MarkerType,
@@ -127,8 +126,8 @@ struct MarkerTypeSerialization {
// everybody, even the majority of users not using the profiler.
static const Streaming::DeserializerTag tag =
Streaming::TagForDeserializer(Deserialize);
return StreamFunctionType::Serialize(aBuffer, aName, aCategory,
std::move(aOptions), tag, aTs...);
return StreamFunctionType::Serialize(aBuffer, aName, std::move(aOptions),
tag, aTs...);
}
private:
@@ -176,8 +175,7 @@ struct MarkerTypeSerialization<::mozilla::baseprofiler::markers::NoPayload> {
template <typename MarkerType, typename... Ts>
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<MarkerType,
::mozilla::baseprofiler::markers::NoPayload>) {
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<MarkerType>::Serialize(
aBuffer, aName, aCategory, std::move(aOptions), aTs...);
aBuffer, aName, std::move(aOptions), aTs...);
}
}
@@ -203,7 +201,7 @@ using BacktraceCaptureFunction = bool (*)(ProfileChunkedBuffer&);
template <typename MarkerType, typename... Ts>
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<MarkerType>(
aBuffer, aName, aCategory, std::move(aOptions), aTs...);
aBuffer, aName, std::move(aOptions), aTs...);
}
return AddMarkerWithOptionalStackToBuffer<MarkerType>(
aBuffer, aName, aCategory, std::move(aOptions), aTs...);
aBuffer, aName, std::move(aOptions), aTs...);
}
template <typename NameCallback, typename StackCallback>
@@ -256,7 +254,7 @@ template <typename NameCallback, typename StackCallback>
aWriter.StartArrayElement();
{
std::forward<NameCallback>(aNameCallback)(
aEntryReader.ReadObject<ProfilerString8View>());
aEntryReader.ReadObject<mozilla::ProfilerString8View>());
const double startTime = options.Timing().GetStartTime();
aWriter.DoubleElement(startTime);
@@ -266,8 +264,7 @@ template <typename NameCallback, typename StackCallback>
aWriter.IntElement(static_cast<int64_t>(options.Timing().MarkerPhase()));
MarkerCategory category = aEntryReader.ReadObject<MarkerCategory>();
aWriter.IntElement(static_cast<int64_t>(category.GetCategory()));
aWriter.IntElement(static_cast<int64_t>(options.Category().GetCategory()));
if (const auto tag =
aEntryReader.ReadObject<mozilla::base_profiler_markers_detail::
@@ -425,7 +422,8 @@ template <>
struct ProfileBufferEntryReader::Deserializer<MarkerCategory> {
static void ReadInto(ProfileBufferEntryReader& aER,
MarkerCategory& aCategory) {
aCategory = Read(aER);
aCategory.mCategoryPair = static_cast<baseprofiler::ProfilingCategoryPair>(
aER.ReadULEB128<uint32_t>());
}
static MarkerCategory Read(ProfileBufferEntryReader& aER) {
@@ -586,13 +584,14 @@ struct ProfileBufferEntryReader::Deserializer<MarkerStack> {
template <>
struct ProfileBufferEntryWriter::Serializer<MarkerOptions> {
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<MarkerOptions> {
template <>
struct ProfileBufferEntryReader::Deserializer<MarkerOptions> {
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);
}

View File

@@ -212,34 +212,47 @@ class MOZ_STACK_CLASS ProfilerStringView {
using ProfilerString8View = ProfilerStringView<char>;
using ProfilerString16View = ProfilerStringView<char16_t>;
// 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 <typename... Options>
MarkerOptions WithOptions(Options&&... aOptions) const;
private:
// The default constructor is only used during deserialization of
// MarkerOptions.
friend MarkerOptions;
constexpr MarkerCategory() = default;
friend ProfileBufferEntryReader::Deserializer<MarkerCategory>;
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 <typename... Options>
MOZ_IMPLICIT MarkerOptions(Options&&... aOptions) {
explicit MarkerOptions(const MarkerCategory& aCategory, Options&&... aOptions)
: mCategory(aCategory) {
(Set(std::forward<Options>(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<MarkerOptions>;
// The default constructor is only used during deserialization.
constexpr MarkerOptions() = default;
MarkerCategory mCategory;
MarkerThreadId mThreadId;
MarkerTiming mTiming;
MarkerStack mStack;
MarkerInnerWindowId mInnerWindowId;
};
template <typename... Options>
MarkerOptions MarkerCategory::WithOptions(Options&&... aOptions) const {
return MarkerOptions(*this, std::forward<Options>(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 {

View File

@@ -3340,9 +3340,9 @@ MOZ_NEVER_INLINE unsigned long long Fibonacci(unsigned long long n) {
}
unsigned long long f1 = Fibonacci<NextDepth(DEPTH)>(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<mozilla::baseprofiler::markers::FileIO>(
"m2fileio", mozilla::baseprofiler::category::OTHER, "op2", "src2", "f2",
MarkerThreadId{});
baseprofiler::AddMarker<mozilla::baseprofiler::markers::FileIO>(
"m2fileio-capture",
mozilla::baseprofiler::category::OTHER.WithOptions(
MarkerStack::Capture()),
"op2", "src2", "f2", MarkerThreadId{});
baseprofiler::AddMarker<mozilla::baseprofiler::markers::FileIO>(
"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<mozilla::baseprofiler::markers::Tracing>(
"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<mozilla::baseprofiler::markers::UserTimingMark>(
"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<mozilla::baseprofiler::markers::Hang>(
"hang", mozilla::baseprofiler::category::OTHER));
MOZ_RELEASE_ASSERT(baseprofiler::AddMarker(
"longtask", mozilla::baseprofiler::category::OTHER, {},
mozilla::baseprofiler::markers::LongTask{}));
MOZ_RELEASE_ASSERT(
baseprofiler::AddMarker<mozilla::baseprofiler::markers::LongTask>(
"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<mozilla::baseprofiler::markers::Text>(
"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<mozilla::baseprofiler::markers::Log>(
"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<mozilla::baseprofiler::markers::MediaSample>(
"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<decltype(
std::declval<mozilla::MarkerCategory>().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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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<MarkerTypeTestMinimal>(
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");

View File

@@ -265,9 +265,10 @@ void ChannelWrapper::Resume(const nsCString& aText, ErrorResult& aRv) {
if (nsCOMPtr<nsIChannel> 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);

View File

@@ -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(

View File

@@ -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<ChosenMarkerType>(...)` 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<ChosenMarkerType>(...)`.
// 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 <typename MarkerType, typename... PayloadArguments>
template <typename MarkerType = ::mozilla::baseprofiler::markers::NoPayload,
typename... Ts>
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<MarkerType>(
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 <typename MarkerType, typename... PayloadArguments>
template <typename MarkerType = ::mozilla::baseprofiler::markers::NoPayload,
typename... Ts>
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<MarkerType>(
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

View File

@@ -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<ProfilerBufferInfo> 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<geckoprofiler::markers::FileIO>(
"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<geckoprofiler::markers::FileIO>(
"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<geckoprofiler::markers::Tracing>(
"Tracing", geckoprofiler::category::OTHER, "category"));
MOZ_RELEASE_ASSERT(
profiler_add_marker("MediaSample", geckoprofiler::category::OTHER, {},
geckoprofiler::markers::MediaSample{}, 123, 456));
profiler_add_marker<geckoprofiler::markers::UserTimingMark>(
"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<geckoprofiler::markers::UserTimingMeasure>(
"UserTimingMeasure", geckoprofiler::category::OTHER, "measure name",
Some(mozilla::ProfilerString8View("start")),
Some(mozilla::ProfilerString8View("end"))));
MOZ_RELEASE_ASSERT(profiler_add_marker<geckoprofiler::markers::Hang>(
"Hang", geckoprofiler::category::OTHER));
MOZ_RELEASE_ASSERT(profiler_add_marker<geckoprofiler::markers::LongTask>(
"LongTask", geckoprofiler::category::OTHER));
MOZ_RELEASE_ASSERT(profiler_add_marker<geckoprofiler::markers::Text>(
"Text", geckoprofiler::category::OTHER, "Text text"));
MOZ_RELEASE_ASSERT(profiler_add_marker<geckoprofiler::markers::Log>(
"Log", geckoprofiler::category::OTHER, "module", "log text"));
MOZ_RELEASE_ASSERT(profiler_add_marker<geckoprofiler::markers::MediaSample>(
"MediaSample", geckoprofiler::category::OTHER, 123, 456));
MOZ_RELEASE_ASSERT(profiler_add_marker<geckoprofiler::markers::Budget>(
"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<baseprofiler::ProfilerBufferInfo> 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<baseprofiler::ProfilerBufferInfo> info1 =
baseprofiler::profiler_get_buffer_info();
ASSERT_GT(info1->mRangeEnd, info0->mRangeEnd);

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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);