From 3894ab42c2979c250547db52ec333a25f407480d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Wed, 18 Jan 2023 10:56:18 +0000 Subject: [PATCH] Bug 1807011 - Do not call TimeStamp::Now for text markers when profiler is not running r=julienw Differential Revision: https://phabricator.services.mozilla.com/D166804 --- .../baseprofiler/public/BaseProfilerMarkers.h | 13 ++++++++----- tools/profiler/public/ProfilerMarkers.h | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/mozglue/baseprofiler/public/BaseProfilerMarkers.h b/mozglue/baseprofiler/public/BaseProfilerMarkers.h index 5821997e7cbb..580527aae610 100644 --- a/mozglue/baseprofiler/public/BaseProfilerMarkers.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkers.h @@ -203,16 +203,19 @@ class MOZ_RAII AutoProfilerTextMarker { mText(aText) { MOZ_ASSERT(mOptions.Timing().EndTime().IsNull(), "AutoProfilerTextMarker options shouldn't have an end time"); - if (mOptions.Timing().StartTime().IsNull()) { + if (profiler_is_active_and_unpaused() && + mOptions.Timing().StartTime().IsNull()) { mOptions.Set(MarkerTiming::InstantNow()); } } ~AutoProfilerTextMarker() { - mOptions.TimingRef().SetIntervalEnd(); - AUTO_PROFILER_STATS(AUTO_BASE_PROFILER_MARKER_TEXT); - AddMarker(ProfilerString8View::WrapNullTerminatedString(mMarkerName), - mCategory, std::move(mOptions), markers::TextMarker{}, mText); + if (profiler_is_active_and_unpaused()) { + mOptions.TimingRef().SetIntervalEnd(); + AUTO_PROFILER_STATS(AUTO_BASE_PROFILER_MARKER_TEXT); + AddMarker(ProfilerString8View::WrapNullTerminatedString(mMarkerName), + mCategory, std::move(mOptions), markers::TextMarker{}, mText); + } } protected: diff --git a/tools/profiler/public/ProfilerMarkers.h b/tools/profiler/public/ProfilerMarkers.h index 34a335700555..a4a5ad024e03 100644 --- a/tools/profiler/public/ProfilerMarkers.h +++ b/tools/profiler/public/ProfilerMarkers.h @@ -216,19 +216,22 @@ class MOZ_RAII AutoProfilerTextMarker { mText(aText) { MOZ_ASSERT(mOptions.Timing().EndTime().IsNull(), "AutoProfilerTextMarker options shouldn't have an end time"); - if (mOptions.Timing().StartTime().IsNull()) { + if (profiler_is_active_and_unpaused() && + mOptions.Timing().StartTime().IsNull()) { mOptions.Set(mozilla::MarkerTiming::InstantNow()); } } ~AutoProfilerTextMarker() { - AUTO_PROFILER_LABEL("TextMarker", PROFILER); - mOptions.TimingRef().SetIntervalEnd(); - AUTO_PROFILER_STATS(AUTO_PROFILER_MARKER_TEXT); - profiler_add_marker( - mozilla::ProfilerString8View::WrapNullTerminatedString(mMarkerName), - mCategory, std::move(mOptions), geckoprofiler::markers::TextMarker{}, - mText); + if (profiler_is_active_and_unpaused()) { + AUTO_PROFILER_LABEL("TextMarker", PROFILER); + mOptions.TimingRef().SetIntervalEnd(); + AUTO_PROFILER_STATS(AUTO_PROFILER_MARKER_TEXT); + profiler_add_marker( + mozilla::ProfilerString8View::WrapNullTerminatedString(mMarkerName), + mCategory, std::move(mOptions), geckoprofiler::markers::TextMarker{}, + mText); + } } protected: