Bug 1663554 - Convert AUTO_PROFILER_TEXT_MARKER_... to new AUTO_PROFILER_MARKER_TEXT - r=gregtatum

The name `AUTO_PROFILER_MARKER_TEXT` is more consistent with the equivalent non-`AUTO` macro, and similarly arguments have been re-ordered to be the same, i.e.: Name, category&options, text.

The different macros with different argument sets can now be collapsed into one macro, and the optional arguments (timing, inner window id, backtrace) can easily be added to the `MarkerOptions` where needed.

As a bonus, a specific start time can optionally be provided at construction time.

Differential Revision: https://phabricator.services.mozilla.com/D89588
This commit is contained in:
Gerald Squelart 2020-09-11 00:42:51 +00:00
Родитель b0bf2c2172
Коммит a087b2df35
19 изменённых файлов: 172 добавлений и 205 удалений

Просмотреть файл

@ -52,7 +52,7 @@ void Timeout::SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
mSubmitTime = aBaseTime;
#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
mCause = profiler_get_backtrace();
mCause = profiler_capture_backtrace();
}
#endif

Просмотреть файл

@ -121,7 +121,9 @@ class Timeout final : protected LinkedListElement<RefPtr<Timeout>> {
}
#ifdef MOZ_GECKO_PROFILER
UniqueProfilerBacktrace TakeProfilerBacktrace() { return std::move(mCause); }
UniquePtr<ProfileChunkedBuffer> TakeProfilerBacktrace() {
return std::move(mCause);
}
#endif
private:
@ -159,7 +161,7 @@ class Timeout final : protected LinkedListElement<RefPtr<Timeout>> {
TimeDuration mInterval;
#ifdef MOZ_GECKO_PROFILER
UniqueProfilerBacktrace mCause;
UniquePtr<ProfileChunkedBuffer> mCause;
#endif
// Returned as value of setTimeout()

Просмотреть файл

@ -6067,9 +6067,12 @@ bool nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout,
timeout->mScriptHandler->GetDescription(handlerDescription);
str.Append(handlerDescription);
}
AUTO_PROFILER_TEXT_MARKER_CAUSE("setTimeout callback", str, JS,
Some(mWindowID),
timeout->TakeProfilerBacktrace());
AUTO_PROFILER_MARKER_TEXT(
"setTimeout callback",
JS.WithOptions(
MarkerStack::TakeBacktrace(timeout->TakeProfilerBacktrace()),
MarkerInnerWindowId(mWindowID)),
str);
#endif
bool abortIntervalHandler;

Просмотреть файл

@ -2841,8 +2841,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_TEXT_MARKER_DOCSHELL("ModuleEvaluation",
profilerLabelString, JS, docShell);
AUTO_PROFILER_MARKER_TEXT(
"ModuleEvaluation",
JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)),
profilerLabelString);
// currentScript is set to null for modules.
AutoCurrentScriptUpdater scriptUpdater(this, nullptr);
@ -2915,16 +2917,20 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
} else {
LOG(("ScriptLoadRequest (%p): Decode Bytecode and Execute",
aRequest));
AUTO_PROFILER_TEXT_MARKER_DOCSHELL(
"BytecodeDecodeMainThread", profilerLabelString, JS, docShell);
AUTO_PROFILER_MARKER_TEXT(
"BytecodeDecodeMainThread",
JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)),
profilerLabelString);
rv = exec.Decode(options, aRequest->mScriptBytecode,
aRequest->mBytecodeOffset);
}
if (rv == NS_OK) {
AUTO_PROFILER_TEXT_MARKER_DOCSHELL(
"ScriptExecution", profilerLabelString, JS, docShell);
AUTO_PROFILER_MARKER_TEXT(
"ScriptExecution",
JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)),
profilerLabelString);
rv = ExecuteCompiledScript(cx, aRequest, exec, classicScript);
}
@ -2957,9 +2963,10 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
// Main thread parsing (inline and small scripts)
LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest));
if (aRequest->IsBinASTSource()) {
AUTO_PROFILER_TEXT_MARKER_DOCSHELL("BinASTDecodeMainThread",
profilerLabelString, JS,
docShell);
AUTO_PROFILER_MARKER_TEXT(
"BinASTDecodeMainThread",
JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)),
profilerLabelString);
rv = exec.DecodeBinAST(options,
aRequest->ScriptBinASTData().begin(),
@ -2969,9 +2976,10 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
MaybeSourceText maybeSource;
rv = GetScriptSource(cx, aRequest, &maybeSource);
if (NS_SUCCEEDED(rv)) {
AUTO_PROFILER_TEXT_MARKER_DOCSHELL("ScriptCompileMainThread",
profilerLabelString, JS,
docShell);
AUTO_PROFILER_MARKER_TEXT(
"ScriptCompileMainThread",
JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)),
profilerLabelString);
rv = maybeSource.constructed<SourceText<char16_t>>()
? exec.Compile(
@ -2986,8 +2994,10 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
if (rv == NS_OK) {
script = exec.GetScript();
AUTO_PROFILER_TEXT_MARKER_DOCSHELL(
"ScriptExecution", profilerLabelString, JS, docShell);
AUTO_PROFILER_MARKER_TEXT(
"ScriptExecution",
JS.WithOptions(MarkerInnerWindowIdFromDocShell(docShell)),
profilerLabelString);
rv = ExecuteCompiledScript(cx, aRequest, exec, classicScript);
}
}

Просмотреть файл

@ -361,8 +361,8 @@ void WorkerGlobalScope::ImportScripts(JSContext* aCx,
}
}
}
AUTO_PROFILER_TEXT_MARKER_CAUSE("ImportScripts", urls, JS, Nothing(),
profiler_get_backtrace());
AUTO_PROFILER_MARKER_TEXT("ImportScripts",
JS.WithOptions(MarkerStack::Capture()), urls);
#endif
workerinternals::Load(mWorkerPrivate, std::move(stack), aScriptURLs,
WorkerScript, aRv);

Просмотреть файл

@ -50,8 +50,7 @@ void ImageComposite::UpdateBias(size_t aImageIndex, bool aFrameChanged) {
nsPrintfCString str("current %.2lfms, next %.2lfms",
offsetCurrent.ToMilliseconds(),
offsetNext.ToMilliseconds());
AUTO_PROFILER_TEXT_MARKER_CAUSE("Video frame offsets", str, GRAPHICS,
Nothing(), nullptr);
PROFILER_MARKER_TEXT("Video frame offsets", GRAPHICS, str);
}
#endif
@ -186,8 +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);
AUTO_PROFILER_TEXT_MARKER_CAUSE("ImageComposite::SetImages", str,
GRAPHICS, Nothing(), nullptr);
PROFILER_MARKER_TEXT("ImageComposite::SetImages", GRAPHICS, str);
}
#endif
}
@ -231,8 +229,7 @@ bool ImageComposite::UpdateCompositedFrame(
descr.AppendLiteral(", no change");
}
}
AUTO_PROFILER_TEXT_MARKER_CAUSE("UpdateCompositedFrame", descr, GRAPHICS,
Nothing(), nullptr);
PROFILER_MARKER_TEXT("UpdateCompositedFrame", GRAPHICS, descr);
#endif
if (mLastFrameID == image.mFrameID && mLastProducerID == image.mProducerID) {

Просмотреть файл

@ -381,8 +381,8 @@ const mozilla::Module* mozJSComponentLoader::LoadModule(FileLocation& aFile) {
mInitialized = true;
AUTO_PROFILER_TEXT_MARKER_CAUSE("JS XPCOM", spec, JS, Nothing(),
profiler_get_backtrace());
AUTO_PROFILER_MARKER_TEXT("JS XPCOM", JS.WithOptions(MarkerStack::Capture()),
spec);
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("mozJSComponentLoader::LoadModule",
OTHER, spec);
@ -1198,8 +1198,8 @@ nsresult mozJSComponentLoader::Import(JSContext* aCx,
bool aIgnoreExports) {
mInitialized = true;
AUTO_PROFILER_TEXT_MARKER_CAUSE("ChromeUtils.import", aLocation, JS,
Nothing(), profiler_get_backtrace());
AUTO_PROFILER_MARKER_TEXT("ChromeUtils.import",
JS.WithOptions(MarkerStack::Capture()), aLocation);
ComponentLoaderInfo info(aLocation);

Просмотреть файл

@ -421,8 +421,8 @@ nsresult mozJSSubScriptLoader::DoLoadSubScriptWithOptions(
}
NS_LossyConvertUTF16toASCII asciiUrl(url);
AUTO_PROFILER_TEXT_MARKER_CAUSE("SubScript", asciiUrl, JS, Nothing(),
profiler_get_backtrace());
AUTO_PROFILER_MARKER_TEXT("SubScript", JS.WithOptions(MarkerStack::Capture()),
asciiUrl);
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING_NONSENSITIVE(
"mozJSSubScriptLoader::DoLoadSubScriptWithOptions", OTHER, asciiUrl);

Просмотреть файл

@ -1399,7 +1399,7 @@ void nsRefreshDriver::EnsureTimerStarted(EnsureTimerStartedFlags aFlags) {
#ifdef MOZ_GECKO_PROFILER
if (!mRefreshTimerStartedCause) {
mRefreshTimerStartedCause = profiler_get_backtrace();
mRefreshTimerStartedCause = profiler_capture_backtrace();
}
#endif
@ -1981,9 +1981,12 @@ void nsRefreshDriver::Tick(VsyncId aId, TimeStamp aNowTime) {
AppendTickReasonsToString(tickReasons, profilerStr);
}
#endif
AUTO_PROFILER_TEXT_MARKER_DOCSHELL_CAUSE(
"RefreshDriverTick", profilerStr, GRAPHICS, GetDocShell(mPresContext),
std::move(mRefreshTimerStartedCause));
AUTO_PROFILER_MARKER_TEXT(
"RefreshDriverTick",
GRAPHICS.WithOptions(
MarkerStack::TakeBacktrace(std::move(mRefreshTimerStartedCause)),
MarkerInnerWindowIdFromDocShell(GetDocShell(mPresContext))),
profilerStr);
mResizeSuppressed = false;
@ -2242,9 +2245,10 @@ void nsRefreshDriver::Tick(VsyncId aId, TimeStamp aNowTime) {
transactionId.AppendInt((uint64_t)mNextTransactionId);
}
#endif
AUTO_PROFILER_TEXT_MARKER_CAUSE("ViewManagerFlush", transactionId, GRAPHICS,
Nothing(),
std::move(mViewManagerFlushCause));
AUTO_PROFILER_MARKER_TEXT("ViewManagerFlush",
GRAPHICS.WithOptions(MarkerStack::TakeBacktrace(
std::move(mViewManagerFlushCause))),
transactionId);
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
@ -2583,7 +2587,7 @@ void nsRefreshDriver::ScheduleViewManagerFlush() {
"Should only schedule view manager flush on root prescontexts");
mViewManagerFlushIsPending = true;
if (!mViewManagerFlushCause) {
mViewManagerFlushCause = profiler_get_backtrace();
mViewManagerFlushCause = profiler_capture_backtrace();
}
mHasScheduleFlush = true;
EnsureTimerStarted(eNeverAdjustTimer);

Просмотреть файл

@ -474,7 +474,7 @@ class nsRefreshDriver final : public mozilla::layers::TransactionIdAllocator,
mozilla::RefreshDriverTimer* ChooseTimer();
mozilla::RefreshDriverTimer* mActiveTimer;
RefPtr<mozilla::RefreshDriverTimer> mOwnTimer;
UniqueProfilerBacktrace mRefreshTimerStartedCause;
mozilla::UniquePtr<mozilla::ProfileChunkedBuffer> mRefreshTimerStartedCause;
// nsPresContext passed in constructor and unset in Disconnect.
mozilla::WeakPtr<nsPresContext> mPresContext;
@ -503,7 +503,7 @@ class nsRefreshDriver final : public mozilla::layers::TransactionIdAllocator,
// flush since the last time we did it.
const mozilla::TimeDuration mMinRecomputeVisibilityInterval;
UniqueProfilerBacktrace mViewManagerFlushCause;
mozilla::UniquePtr<mozilla::ProfileChunkedBuffer> mViewManagerFlushCause;
bool mThrottled : 1;
bool mNeedToRecomputeVisibility : 1;

Просмотреть файл

@ -3758,18 +3758,6 @@ void profiler_tracing_marker(const char* aCategoryString,
aInnerWindowID, std::move(aCause)));
}
void profiler_add_text_marker(const char* aMarkerName, const std::string& aText,
ProfilingCategoryPair aCategoryPair,
const TimeStamp& aStartTime,
const TimeStamp& aEndTime,
const Maybe<uint64_t>& aInnerWindowID,
UniqueProfilerBacktrace aCause) {
AUTO_PROFILER_STATS(base_add_marker_with_TextMarkerPayload);
profiler_add_marker(aMarkerName, aCategoryPair,
TextMarkerPayload(aText, aStartTime, aEndTime,
aInnerWindowID, std::move(aCause)));
}
// NOTE: aCollector's methods will be called while the target thread is paused.
// Doing things in those methods like allocating -- which may try to claim
// locks -- is a surefire way to deadlock.

Просмотреть файл

@ -60,8 +60,6 @@
categoryPair, kind)
# define AUTO_BASE_PROFILER_TRACING_MARKER(categoryString, markerName, \
categoryPair)
# define AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE(markerName, text, categoryPair, \
cause)
# define AUTO_PROFILER_STATS(name)
@ -876,54 +874,6 @@ MFBT_API void profiler_tracing_marker(
::mozilla::baseprofiler::ProfilingCategoryPair::categoryPair, \
Nothing())
// Add a text marker. Text markers are similar to tracing markers, with the
// difference that text markers have their "text" separate from the marker name;
// multiple text markers with the same name can have different text, and these
// markers will still be displayed in the same "row" in the UI.
// Another difference is that text markers combine the start and end markers
// into one marker.
MFBT_API void profiler_add_text_marker(
const char* aMarkerName, const std::string& aText,
ProfilingCategoryPair aCategoryPair, const TimeStamp& aStartTime,
const TimeStamp& aEndTime,
const Maybe<uint64_t>& aInnerWindowID = Nothing(),
UniqueProfilerBacktrace aCause = nullptr);
class MOZ_RAII AutoProfilerTextMarker {
public:
AutoProfilerTextMarker(const char* aMarkerName, const std::string& aText,
ProfilingCategoryPair aCategoryPair,
const Maybe<uint64_t>& aInnerWindowID,
UniqueProfilerBacktrace&& aCause = nullptr)
: mMarkerName(aMarkerName),
mText(aText),
mCategoryPair(aCategoryPair),
mStartTime(TimeStamp::NowUnfuzzed()),
mCause(std::move(aCause)),
mInnerWindowID(aInnerWindowID) {}
~AutoProfilerTextMarker() {
profiler_add_text_marker(mMarkerName, mText, mCategoryPair, mStartTime,
TimeStamp::NowUnfuzzed(), mInnerWindowID,
std::move(mCause));
}
protected:
const char* mMarkerName;
std::string mText;
const ProfilingCategoryPair mCategoryPair;
TimeStamp mStartTime;
UniqueProfilerBacktrace mCause;
const Maybe<uint64_t> mInnerWindowID;
};
# define AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE(markerName, text, categoryPair, \
cause) \
::mozilla::baseprofiler::AutoProfilerTextMarker BASE_PROFILER_RAII( \
markerName, text, \
::mozilla::baseprofiler::ProfilingCategoryPair::categoryPair, \
mozilla::Nothing(), cause)
//---------------------------------------------------------------------------
// Output profiles
//---------------------------------------------------------------------------

Просмотреть файл

@ -41,6 +41,7 @@
# 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
@ -123,6 +124,42 @@ struct Text {
markerName, ::mozilla::baseprofiler::category::options, text); \
} while (false)
namespace mozilla::baseprofiler {
// RAII object that adds a BASE_PROFILER_MARKER_TEXT when destroyed; the
// marker's timing will be the interval from construction (unless an instant or
// start time is already specified in the provided options) until destruction.
class MOZ_RAII AutoProfilerTextMarker {
public:
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()) {
mOptions.Set(MarkerTiming::InstantNow());
}
}
~AutoProfilerTextMarker() {
mOptions.Timing().SetIntervalEnd();
BASE_PROFILER_MARKER_TEXT(
ProfilerString8View::WrapNullTerminatedString(mMarkerName),
MarkerOptions(std::move(mOptions)), mText);
}
protected:
const char* mMarkerName;
MarkerOptions mOptions;
std::string mText;
};
} // namespace mozilla::baseprofiler
# 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
#endif // BaseProfilerMarkers_h

Просмотреть файл

@ -338,6 +338,14 @@ class MarkerTiming {
return MarkerTiming{TimeStamp{}, aTime, MarkerTiming::Phase::IntervalEnd};
}
// Set the interval end in this timing.
// If there was already a start time, this makes it a full interval.
void SetIntervalEnd(const TimeStamp& aTime = TimeStamp::NowUnfuzzed()) {
MOZ_ASSERT(!aTime.IsNull(), "Time is null for an interval end marker.");
mEndTime = aTime;
mPhase = mStartTime.IsNull() ? Phase::IntervalEnd : Phase::Interval;
}
[[nodiscard]] const TimeStamp& StartTime() const { return mStartTime; }
[[nodiscard]] const TimeStamp& EndTime() const { return mEndTime; }

Просмотреть файл

@ -3340,10 +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) {
baseprofiler::profiler_add_text_marker(
"fib", std::to_string(DEPTH),
baseprofiler::ProfilingCategoryPair::OTHER, start,
TimeStamp::NowUnfuzzed());
BASE_PROFILER_MARKER_TEXT(
"fib", OTHER.WithOptions(MarkerTiming::IntervalUntilNowFrom(start)),
std::to_string(DEPTH));
}
return f2 + f1;
}
@ -3386,15 +3385,11 @@ void TestProfiler() {
std::thread threadFib([]() {
AUTO_BASE_PROFILER_REGISTER_THREAD("fibonacci");
SleepMilli(5);
auto cause =
# if defined(__linux__) || defined(__ANDROID__)
// Currently disabled on these platforms, so just return a null.
decltype(baseprofiler::profiler_get_backtrace()){};
# else
baseprofiler::profiler_get_backtrace();
# endif
AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE("fibonacci", "First leaf call",
OTHER, std::move(cause));
auto cause = baseprofiler::profiler_capture_backtrace();
AUTO_BASE_PROFILER_MARKER_TEXT(
"fibonacci",
OTHER.WithOptions(MarkerStack::TakeBacktrace(std::move(cause))),
"First leaf call");
static const unsigned long long fibStart = 37;
printf("Fibonacci(%llu)...\n", fibStart);
AUTO_BASE_PROFILER_LABEL("Label around Fibonacci", OTHER);
@ -3406,8 +3401,7 @@ void TestProfiler() {
std::thread threadCancelFib([]() {
AUTO_BASE_PROFILER_REGISTER_THREAD("fibonacci canceller");
SleepMilli(5);
AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE("fibonacci", "Canceller", OTHER,
nullptr);
AUTO_BASE_PROFILER_MARKER_TEXT("fibonacci", OTHER, "Canceller");
static const int waitMaxSeconds = 10;
for (int i = 0; i < waitMaxSeconds; ++i) {
if (sStopFibonacci) {
@ -3424,15 +3418,15 @@ void TestProfiler() {
});
{
AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE(
"main thread", "joining fibonacci thread", OTHER, nullptr);
AUTO_BASE_PROFILER_MARKER_TEXT("main thread", OTHER,
"joining fibonacci thread");
AUTO_BASE_PROFILER_THREAD_SLEEP;
threadFib.join();
}
{
AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE(
"main thread", "joining fibonacci-canceller thread", OTHER, nullptr);
AUTO_BASE_PROFILER_MARKER_TEXT("main thread", OTHER,
"joining fibonacci-canceller thread");
sStopFibonacci = true;
AUTO_BASE_PROFILER_THREAD_SLEEP;
threadCancelFib.join();
@ -3875,10 +3869,10 @@ void TestProfiler() {
AUTO_BASE_PROFILER_INIT;
// This wouldn't build if the macro did output its arguments.
# ifndef AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE
# error AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE not #defined
# endif // AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE
AUTO_BASE_PROFILER_TEXT_MARKER_CAUSE(catch, catch, catch, catch);
# 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);
# ifndef AUTO_BASE_PROFILER_LABEL
# error AUTO_BASE_PROFILER_LABEL not #defined

Просмотреть файл

@ -64,8 +64,6 @@
# define PROFILER_ADD_MARKER_WITH_PAYLOAD(markerName, categoryPair, \
PayloadType, payloadArgs)
# define PROFILER_ADD_TEXT_MARKER(markerName, text, categoryPair, startTime, \
endTime, ...)
# define PROFILER_TRACING_MARKER(categoryString, markerName, categoryPair, \
kind)
@ -74,12 +72,6 @@
# define AUTO_PROFILER_TRACING_MARKER(categoryString, markerName, categoryPair)
# define AUTO_PROFILER_TRACING_MARKER_DOCSHELL(categoryString, markerName, \
categoryPair, docShell)
# define AUTO_PROFILER_TEXT_MARKER_CAUSE(markerName, text, categoryPair, \
innerWindowID, cause)
# define AUTO_PROFILER_TEXT_MARKER_DOCSHELL(markerName, text, categoryPair, \
docShell)
# define AUTO_PROFILER_TEXT_MARKER_DOCSHELL_CAUSE( \
markerName, text, categoryPair, docShell, cause)
// Function stubs for when MOZ_GECKO_PROFILER is not defined.
@ -957,6 +949,16 @@ enum TracingKind {
mozilla::Maybe<uint64_t> profiler_get_inner_window_id_from_docshell(
nsIDocShell* aDocshell);
inline mozilla::MarkerInnerWindowId MarkerInnerWindowIdFromDocShell(
nsIDocShell* aDocshell) {
mozilla::Maybe<uint64_t> id =
profiler_get_inner_window_id_from_docshell(aDocshell);
if (!id) {
return mozilla::MarkerInnerWindowId::NoId();
}
return mozilla::MarkerInnerWindowId(*id);
}
// Adds a tracing marker to the profile. A no-op if the profiler is inactive.
# define PROFILER_TRACING_MARKER(categoryString, markerName, categoryPair, \
@ -991,69 +993,6 @@ void profiler_tracing_marker(
categoryString, markerName, JS::ProfilingCategoryPair::categoryPair, \
profiler_get_inner_window_id_from_docshell(docShell))
// Add a text marker. Text markers are similar to tracing markers, with the
// difference that text markers have their "text" separate from the marker name;
// multiple text markers with the same name can have different text, and these
// markers will still be displayed in the same "row" in the UI.
// Another difference is that text markers combine the start and end markers
// into one marker.
void profiler_add_text_marker(
const char* aMarkerName, const nsACString& aText,
JS::ProfilingCategoryPair aCategoryPair,
const mozilla::TimeStamp& aStartTime, const mozilla::TimeStamp& aEndTime,
const mozilla::Maybe<uint64_t>& aInnerWindowID = mozilla::Nothing(),
UniqueProfilerBacktrace aCause = nullptr);
# define PROFILER_ADD_TEXT_MARKER(markerName, text, categoryPair, startTime, \
endTime, ...) \
profiler_add_text_marker(markerName, text, categoryPair, startTime, \
endTime, ##__VA_ARGS__)
class MOZ_RAII AutoProfilerTextMarker {
public:
AutoProfilerTextMarker(const char* aMarkerName, const nsACString& aText,
JS::ProfilingCategoryPair aCategoryPair,
const mozilla::Maybe<uint64_t>& aInnerWindowID,
UniqueProfilerBacktrace&& aCause = nullptr)
: mMarkerName(aMarkerName),
mText(aText),
mCategoryPair(aCategoryPair),
mStartTime(mozilla::TimeStamp::NowUnfuzzed()),
mCause(std::move(aCause)),
mInnerWindowID(aInnerWindowID) {}
~AutoProfilerTextMarker() {
profiler_add_text_marker(mMarkerName, mText, mCategoryPair, mStartTime,
mozilla::TimeStamp::NowUnfuzzed(), mInnerWindowID,
std::move(mCause));
}
protected:
const char* mMarkerName;
nsCString mText;
const JS::ProfilingCategoryPair mCategoryPair;
mozilla::TimeStamp mStartTime;
UniqueProfilerBacktrace mCause;
const mozilla::Maybe<uint64_t> mInnerWindowID;
};
# define AUTO_PROFILER_TEXT_MARKER_CAUSE(markerName, text, categoryPair, \
innerWindowID, cause) \
AutoProfilerTextMarker PROFILER_RAII( \
markerName, text, JS::ProfilingCategoryPair::categoryPair, \
innerWindowID, cause)
# define AUTO_PROFILER_TEXT_MARKER_DOCSHELL(markerName, text, categoryPair, \
docShell) \
AutoProfilerTextMarker PROFILER_RAII( \
markerName, text, JS::ProfilingCategoryPair::categoryPair, \
profiler_get_inner_window_id_from_docshell(docShell))
# define AUTO_PROFILER_TEXT_MARKER_DOCSHELL_CAUSE( \
markerName, text, categoryPair, docShell, cause) \
AutoProfilerTextMarker PROFILER_RAII( \
markerName, text, JS::ProfilingCategoryPair::categoryPair, \
profiler_get_inner_window_id_from_docshell(docShell), cause)
//---------------------------------------------------------------------------
// Output profiles
//---------------------------------------------------------------------------

Просмотреть файл

@ -43,6 +43,7 @@
# 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
@ -101,6 +102,39 @@ using Text = ::mozilla::baseprofiler::markers::Text;
markerName, ::geckoprofiler::category::options, text); \
} while (false)
// RAII object that adds a PROFILER_MARKER_TEXT when destroyed; the marker's
// timing will be the interval from construction (unless an instant or start
// time is already specified in the provided options) until destruction.
class MOZ_RAII AutoProfilerTextMarker {
public:
AutoProfilerTextMarker(const char* aMarkerName,
mozilla::MarkerOptions&& aOptions,
const nsACString& 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()) {
mOptions.Set(mozilla::MarkerTiming::InstantNow());
}
}
~AutoProfilerTextMarker() {
mOptions.Timing().SetIntervalEnd();
PROFILER_MARKER_TEXT(
mozilla::ProfilerString8View::WrapNullTerminatedString(mMarkerName),
MarkerOptions(std::move(mOptions)), mText);
}
protected:
const char* mMarkerName;
mozilla::MarkerOptions mOptions;
nsCString mText;
};
# define AUTO_PROFILER_MARKER_TEXT(markerName, options, text) \
AutoProfilerTextMarker PROFILER_RAII( \
markerName, ::mozilla::baseprofiler::category::options, text)
#endif // nfed MOZ_GECKO_PROFILER else
#endif // ProfilerMarkers_h

Просмотреть файл

@ -677,9 +677,9 @@ void NS_CreateServicesFromCategory(const char* aCategory, nsISupports* aOrigin,
#ifdef MOZ_GECKO_PROFILER
nsPrintfCString profilerStr("%s (%s)", aObserverTopic,
entryString.get());
AUTO_PROFILER_TEXT_MARKER_CAUSE("Category observer notification",
profilerStr, OTHER, Nothing(),
profiler_get_backtrace());
AUTO_PROFILER_MARKER_TEXT("Category observer notification",
OTHER.WithOptions(MarkerStack::Capture()),
profilerStr);
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING_NONSENSITIVE(
"Category observer notification -", OTHER, profilerStr);
#endif

Просмотреть файл

@ -277,8 +277,9 @@ NS_IMETHODIMP nsObserverService::NotifyObservers(nsISupports* aSubject,
mozilla::TimeStamp start = TimeStamp::Now();
AUTO_PROFILER_TEXT_MARKER_CAUSE("NotifyObservers", nsDependentCString(aTopic),
OTHER, Nothing(), profiler_get_backtrace());
AUTO_PROFILER_MARKER_TEXT("NotifyObservers",
OTHER.WithOptions(MarkerStack::Capture()),
nsDependentCString(aTopic));
AUTO_PROFILER_LABEL_DYNAMIC_CSTR_NONSENSITIVE(
"nsObserverService::NotifyObservers", OTHER, aTopic);