From 8432e48060cb3b1aea5bd1136b0b4c574920e4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Fri, 2 Nov 2018 16:17:54 +0000 Subject: [PATCH] Bug 1417976 - Part 2: Include DocShell IDs to marker payloads r=mstange MozReview-Commit-ID: AML1ESUnFlu Depends on D4914 Differential Revision: https://phabricator.services.mozilla.com/D4915 --HG-- extra : moz-landing-system : lando --- docshell/base/nsDocShell.cpp | 11 +++ docshell/base/nsIDocShell.idl | 2 + dom/base/nsDOMNavigationTiming.cpp | 18 ++-- dom/events/EventDispatcher.cpp | 12 ++- dom/performance/Performance.cpp | 24 ++++- layout/base/AutoProfilerStyleMarker.h | 19 +++- layout/base/PresShell.cpp | 21 ++++- layout/base/nsRefreshDriver.cpp | 3 +- layout/generic/nsGfxScrollFrame.cpp | 10 +- layout/painting/nsDisplayList.cpp | 5 +- tools/profiler/core/platform.cpp | 22 +++-- tools/profiler/public/GeckoProfiler.h | 92 +++++++++++++++--- tools/profiler/public/ProfilerMarkerPayload.h | 93 +++++++++++++++---- tools/profiler/tests/gtest/GeckoProfiler.cpp | 5 +- 14 files changed, 269 insertions(+), 68 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 78b4dae05c41..e19f85c58771 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -13740,6 +13740,17 @@ nsDocShell::SetOriginAttributes(JS::Handle aOriginAttributes, return SetOriginAttributes(attrs); } +NS_IMETHODIMP +nsDocShell::GetOSHEId(uint32_t* aSHEntryId) +{ + if (mOSHE) { + mOSHE->GetID(aSHEntryId); + return NS_OK; + } else { + return NS_ERROR_FAILURE; + } +} + NS_IMETHODIMP nsDocShell::GetAsyncPanZoomEnabled(bool* aOut) { diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 1c3306e0a60d..07010272a96a 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -1091,6 +1091,8 @@ interface nsIDocShell : nsIDocShellTreeItem in string asyncCause); [noscript,notxpcom,nostdcall] void notifyJSRunToCompletionStop(); + [noscript] void GetOSHEId(out uint32_t aSHEntryId); + /** * This attribute determines whether a document which is not about:blank has * already be loaded by this docShell. diff --git a/dom/base/nsDOMNavigationTiming.cpp b/dom/base/nsDOMNavigationTiming.cpp index 837a3722fe3c..46afdafa5fa7 100644 --- a/dom/base/nsDOMNavigationTiming.cpp +++ b/dom/base/nsDOMNavigationTiming.cpp @@ -102,14 +102,16 @@ void nsDOMNavigationTiming::NotifyUnloadEventStart() { mUnloadStart = TimeStamp::Now(); - PROFILER_TRACING("Navigation", "Unload", TRACING_INTERVAL_START); + PROFILER_TRACING_DOCSHELL( + "Navigation", "Unload", TRACING_INTERVAL_START, mDocShell); } void nsDOMNavigationTiming::NotifyUnloadEventEnd() { mUnloadEnd = TimeStamp::Now(); - PROFILER_TRACING("Navigation", "Unload", TRACING_INTERVAL_END); + PROFILER_TRACING_DOCSHELL( + "Navigation", "Unload", TRACING_INTERVAL_END, mDocShell); } void @@ -120,7 +122,8 @@ nsDOMNavigationTiming::NotifyLoadEventStart() } mLoadEventStart = TimeStamp::Now(); - PROFILER_TRACING("Navigation", "Load", TRACING_INTERVAL_START); + PROFILER_TRACING_DOCSHELL( + "Navigation", "Load", TRACING_INTERVAL_START, mDocShell); if (IsTopLevelContentDocumentInContentProcess()) { TimeStamp now = TimeStamp::Now(); @@ -151,7 +154,8 @@ nsDOMNavigationTiming::NotifyLoadEventEnd() } mLoadEventEnd = TimeStamp::Now(); - PROFILER_TRACING("Navigation", "Load", TRACING_INTERVAL_END); + PROFILER_TRACING_DOCSHELL( + "Navigation", "Load", TRACING_INTERVAL_END, mDocShell); if (IsTopLevelContentDocumentInContentProcess()) { Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_LOAD_EVENT_END_MS, @@ -215,7 +219,8 @@ nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI) mLoadedURI = aURI; mDOMContentLoadedEventStart = TimeStamp::Now(); - PROFILER_TRACING("Navigation", "DOMContentLoaded", TRACING_INTERVAL_START); + PROFILER_TRACING_DOCSHELL( + "Navigation", "DOMContentLoaded", TRACING_INTERVAL_START, mDocShell); if (IsTopLevelContentDocumentInContentProcess()) { TimeStamp now = TimeStamp::Now(); @@ -248,7 +253,8 @@ nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI) mLoadedURI = aURI; mDOMContentLoadedEventEnd = TimeStamp::Now(); - PROFILER_TRACING("Navigation", "DOMContentLoaded", TRACING_INTERVAL_END); + PROFILER_TRACING_DOCSHELL( + "Navigation", "DOMContentLoaded", TRACING_INTERVAL_END, mDocShell); if (IsTopLevelContentDocumentInContentProcess()) { Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_CONTENT_LOADED_END_MS, diff --git a/dom/events/EventDispatcher.cpp b/dom/events/EventDispatcher.cpp index be73e6913824..13ae9318ee74 100644 --- a/dom/events/EventDispatcher.cpp +++ b/dom/events/EventDispatcher.cpp @@ -6,6 +6,7 @@ #include "nsPresContext.h" #include "nsContentUtils.h" +#include "nsDocShell.h" #include "nsError.h" #include #include "nsIContent.h" @@ -1134,12 +1135,17 @@ EventDispatcher::Dispatch(nsISupports* aTarget, AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING( "EventDispatcher::Dispatch", OTHER, typeStr); + nsCOMPtr docShell; + docShell = nsContentUtils::GetDocShellForEventTarget(aEvent->mTarget); + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); profiler_add_marker( "DOMEvent", MakeUnique(typeStr, aEvent->mTimeStamp, "DOMEvent", - TRACING_INTERVAL_START)); + TRACING_INTERVAL_START, + docShellId, + docShellHistoryId)); EventTargetChainItem::HandleEventTargetChain(chain, postVisitor, aCallback, cd); @@ -1149,7 +1155,9 @@ EventDispatcher::Dispatch(nsISupports* aTarget, MakeUnique(typeStr, aEvent->mTimeStamp, "DOMEvent", - TRACING_INTERVAL_END)); + TRACING_INTERVAL_END, + docShellId, + docShellHistoryId)); } else #endif { diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index fe10101c17da..c5737e763ae2 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -7,6 +7,7 @@ #include "Performance.h" #include "GeckoProfiler.h" +#include "nsIDocShell.h" #include "nsRFPService.h" #include "PerformanceEntry.h" #include "PerformanceMainThread.h" @@ -249,9 +250,14 @@ Performance::Mark(const nsAString& aName, ErrorResult& aRv) #ifdef MOZ_GECKO_PROFILER if (profiler_is_active()) { + nsCOMPtr et = do_QueryInterface(GetOwner()); + nsCOMPtr docShell = + nsContentUtils::GetDocShellForEventTarget(et); + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); profiler_add_marker( "UserTiming", - MakeUnique(aName, TimeStamp::Now())); + MakeUnique( + aName, TimeStamp::Now(), docShellId, docShellHistoryId)); } #endif } @@ -347,10 +353,18 @@ Performance::Measure(const nsAString& aName, endMark.emplace(aEndMark.Value()); } - profiler_add_marker( - "UserTiming", - MakeUnique(aName, startMark, endMark, - startTimeStamp, endTimeStamp)); + nsCOMPtr et = do_QueryInterface(GetOwner()); + nsCOMPtr docShell = + nsContentUtils::GetDocShellForEventTarget(et); + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); + profiler_add_marker("UserTiming", + MakeUnique(aName, + startMark, + endMark, + startTimeStamp, + endTimeStamp, + docShellId, + docShellHistoryId)); } #endif } diff --git a/layout/base/AutoProfilerStyleMarker.h b/layout/base/AutoProfilerStyleMarker.h index ec1ec8cd95d7..079c1f2e5dfa 100644 --- a/layout/base/AutoProfilerStyleMarker.h +++ b/layout/base/AutoProfilerStyleMarker.h @@ -18,10 +18,14 @@ namespace mozilla { class MOZ_RAII AutoProfilerStyleMarker { public: - explicit AutoProfilerStyleMarker(UniqueProfilerBacktrace aCause) + explicit AutoProfilerStyleMarker(UniqueProfilerBacktrace aCause, + const Maybe& aDocShellId, + const Maybe& aDocShellHistoryId) : mActive(profiler_is_active()) , mStartTime(TimeStamp::Now()) , mCause(std::move(aCause)) + , mDocShellId(aDocShellId) + , mDocShellHistoryId(aDocShellHistoryId) { if (!mActive) { return; @@ -38,15 +42,22 @@ public: return; } ServoTraversalStatistics::sActive = false; - profiler_add_marker("Styles", MakeUnique( - mStartTime, TimeStamp::Now(), std::move(mCause), - ServoTraversalStatistics::sSingleton)); + profiler_add_marker( + "Styles", + MakeUnique(mStartTime, + TimeStamp::Now(), + std::move(mCause), + ServoTraversalStatistics::sSingleton, + mDocShellId, + mDocShellHistoryId)); } private: bool mActive; TimeStamp mStartTime; UniqueProfilerBacktrace mCause; + Maybe mDocShellId; + Maybe mDocShellHistoryId; }; } // namespace mozilla diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 42f68e9bd5d5..f79cf9bee289 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -3850,7 +3850,8 @@ PresShell::ScheduleViewManagerFlush(PaintType aType) void nsIPresShell::DispatchSynthMouseMove(WidgetGUIEvent* aEvent) { - AUTO_PROFILER_TRACING("Paint", "DispatchSynthMouseMove"); + AUTO_PROFILER_TRACING_DOCSHELL( + "Paint", "DispatchSynthMouseMove", mPresContext->GetDocShell()); nsEventStatus status = nsEventStatus_eIgnore; nsView* targetView = nsView::GetViewFor(aEvent->mWidget); if (!targetView) @@ -4320,7 +4321,10 @@ PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush aFlush) if (MOZ_LIKELY(!mIsDestroying)) { nsAutoScriptBlocker scriptBlocker; #ifdef MOZ_GECKO_PROFILER - AutoProfilerStyleMarker tracingStyleFlush(std::move(mStyleCause)); + nsCOMPtr docShell = mPresContext->GetDocShell(); + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); + AutoProfilerStyleMarker tracingStyleFlush( + std::move(mStyleCause), docShellId, docShellHistoryId); #endif mPresContext->RestyleManager()->ProcessPendingRestyles(); @@ -4343,7 +4347,10 @@ PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush aFlush) if (MOZ_LIKELY(!mIsDestroying)) { nsAutoScriptBlocker scriptBlocker; #ifdef MOZ_GECKO_PROFILER - AutoProfilerStyleMarker tracingStyleFlush(std::move(mStyleCause)); + nsCOMPtr docShell = mPresContext->GetDocShell(); + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); + AutoProfilerStyleMarker tracingStyleFlush( + std::move(mStyleCause), docShellId, docShellHistoryId); #endif mPresContext->RestyleManager()->ProcessPendingRestyles(); @@ -8952,8 +8959,12 @@ PresShell::DoReflow(nsIFrame* target, bool aInterruptible) } #ifdef MOZ_GECKO_PROFILER - AutoProfilerTracing tracingLayoutFlush("Paint", "Reflow", - std::move(mReflowCause)); + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); + AutoProfilerTracing tracingLayoutFlush("Paint", + "Reflow", + std::move(mReflowCause), + docShellId, + docShellHistoryId); mReflowCause = nullptr; #endif diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index c5efa40ff84a..532eedd3243f 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -1701,7 +1701,8 @@ nsRefreshDriver::RunFrameRequestCallbacks(TimeStamp aNowTime) mFrameRequestCallbackDocs.Clear(); if (!frameRequestCallbacks.IsEmpty()) { - AUTO_PROFILER_TRACING("Paint", "Scripts"); + AUTO_PROFILER_TRACING_DOCSHELL( + "Paint", "Scripts", GetDocShell(mPresContext)); for (const DocumentFrameCallbacks& docCallbacks : frameRequestCallbacks) { // XXXbz Bug 863140: GetInnerWindow can return the outer // window in some cases. diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 518cb7e6de97..c8a1fb6fe72b 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -5139,7 +5139,13 @@ ScrollFrameHelper::ScrollEndEvent::Run() void ScrollFrameHelper::FireScrollEvent() { - AUTO_PROFILER_TRACING("Paint", "FireScrollEvent"); + nsIContent* content = mOuter->GetContent(); + nsPresContext* prescontext = mOuter->PresContext(); +#ifdef MOZ_GECKO_PROFILER + nsCOMPtr docShell = prescontext->GetDocShell(); + AUTO_PROFILER_TRACING_DOCSHELL("Paint", "FireScrollEvent", docShell); +#endif + MOZ_ASSERT(mScrollEvent); mScrollEvent->Revoke(); mScrollEvent = nullptr; @@ -5147,8 +5153,6 @@ ScrollFrameHelper::FireScrollEvent() ActiveLayerTracker::SetCurrentScrollHandlerFrame(mOuter); WidgetGUIEvent event(true, eScroll, nullptr); nsEventStatus status = nsEventStatus_eIgnore; - nsIContent* content = mOuter->GetContent(); - nsPresContext* prescontext = mOuter->PresContext(); // Fire viewport scroll events at the document (where they // will bubble to the window) mozilla::layers::ScrollLinkedEffectDetector detector(content->GetComposedDoc()); diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 4b9f3a588d22..754c8d60d3fa 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -2560,7 +2560,10 @@ nsDisplayList::BuildLayers(nsDisplayListBuilder* aBuilder, RefPtr root; { - AUTO_PROFILER_TRACING("Paint", "LayerBuilding"); +#ifdef MOZ_GECKO_PROFILER + nsCOMPtr docShell = presContext->GetDocShell(); + AUTO_PROFILER_TRACING_DOCSHELL("Paint", "LayerBuilding", docShell); +#endif if (XRE_IsContentProcess() && gfxPrefs::AlwaysPaint()) { FrameLayerBuilder::InvalidateAllLayers(aLayerManager); diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index f800a2f4ad14..5f45ccfe9829 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -3825,8 +3825,11 @@ profiler_add_marker_for_thread(int aThreadId, } void -profiler_tracing(const char* aCategory, const char* aMarkerName, - TracingKind aKind) +profiler_tracing(const char* aCategory, + const char* aMarkerName, + TracingKind aKind, + const Maybe& aDocShellId, + const Maybe& aDocShellHistoryId) { MOZ_RELEASE_ASSERT(CorePS::Exists()); @@ -3837,13 +3840,18 @@ profiler_tracing(const char* aCategory, const char* aMarkerName, return; } - auto payload = MakeUnique(aCategory, aKind); + auto payload = MakeUnique( + aCategory, aKind, aDocShellId, aDocShellHistoryId); racy_profiler_add_marker(aMarkerName, std::move(payload)); } void -profiler_tracing(const char* aCategory, const char* aMarkerName, - TracingKind aKind, UniqueProfilerBacktrace aCause) +profiler_tracing(const char* aCategory, + const char* aMarkerName, + TracingKind aKind, + UniqueProfilerBacktrace aCause, + const Maybe& aDocShellId, + const Maybe& aDocShellHistoryId) { MOZ_RELEASE_ASSERT(CorePS::Exists()); @@ -3854,8 +3862,8 @@ profiler_tracing(const char* aCategory, const char* aMarkerName, return; } - auto payload = - MakeUnique(aCategory, aKind, std::move(aCause)); + auto payload = MakeUnique( + aCategory, aKind, aDocShellId, aDocShellHistoryId, std::move(aCause)); racy_profiler_add_marker(aMarkerName, std::move(payload)); } diff --git a/tools/profiler/public/GeckoProfiler.h b/tools/profiler/public/GeckoProfiler.h index ce320c9795d5..1db8aa50ef90 100644 --- a/tools/profiler/public/GeckoProfiler.h +++ b/tools/profiler/public/GeckoProfiler.h @@ -50,8 +50,11 @@ #define PROFILER_ADD_MARKER(markerName) #define PROFILER_ADD_NETWORK_MARKER(uri, pri, channel, type, start, end, count, timings, redirect) +#define DECLARE_DOCSHELL_AND_HISTORY_ID(docShell) #define PROFILER_TRACING(category, markerName, kind) +#define PROFILER_TRACING_DOCSHELL(category, markerName, kind, docshell) #define AUTO_PROFILER_TRACING(category, markerName) +#define AUTO_PROFILER_TRACING_DOCSHELL(category, markerName, docShell) #else // !MOZ_GECKO_PROFILER @@ -613,18 +616,55 @@ enum TracingKind { TRACING_INTERVAL_END, }; +// Helper macro to retrieve DocShellId and DocShellHistoryId from docShell +#define DECLARE_DOCSHELL_AND_HISTORY_ID(docShell) \ + mozilla::Maybe docShellId; \ + mozilla::Maybe docShellHistoryId; \ + if (docShell) { \ + docShellId = Some(docShell->HistoryID()); \ + uint32_t id; \ + nsresult rv = docShell->GetOSHEId(&id); \ + if (NS_SUCCEEDED(rv)) { \ + docShellHistoryId = Some(id); \ + } else { \ + docShellHistoryId = Nothing(); \ + } \ + } else { \ + docShellId = Nothing(); \ + docShellHistoryId = Nothing(); \ + } + // Adds a tracing marker to the profile. A no-op if the profiler is inactive or // in privacy mode. -#define PROFILER_TRACING(category, markerName, kind) \ +#define PROFILER_TRACING(category, markerName, kind) \ profiler_tracing(category, markerName, kind) -void profiler_tracing(const char* aCategory, const char* aMarkerName, - TracingKind aKind); -void profiler_tracing(const char* aCategory, const char* aMarkerName, - TracingKind aKind, UniqueProfilerBacktrace aCause); +#define PROFILER_TRACING_DOCSHELL(category, markerName, kind, docShell) \ + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); \ + profiler_tracing(category, markerName, kind, docShellId, docShellHistoryId) +void +profiler_tracing( + const char* aCategory, + const char* aMarkerName, + TracingKind aKind, + const mozilla::Maybe& aDocShellId = mozilla::Nothing(), + const mozilla::Maybe& aDocShellHistoryId = mozilla::Nothing()); +void +profiler_tracing( + const char* aCategory, + const char* aMarkerName, + TracingKind aKind, + UniqueProfilerBacktrace aCause, + const mozilla::Maybe& aDocShellId = mozilla::Nothing(), + const mozilla::Maybe& aDocShellHistoryId = mozilla::Nothing()); // Adds a START/END pair of tracing markers. -#define AUTO_PROFILER_TRACING(category, markerName) \ - mozilla::AutoProfilerTracing PROFILER_RAII(category, markerName) +#define AUTO_PROFILER_TRACING(category, markerName) \ + mozilla::AutoProfilerTracing PROFILER_RAII( \ + category, markerName, mozilla::Nothing(), mozilla::Nothing()) +#define AUTO_PROFILER_TRACING_DOCSHELL(category, markerName, docShell) \ + DECLARE_DOCSHELL_AND_HISTORY_ID(docShell); \ + mozilla::AutoProfilerTracing PROFILER_RAII( \ + category, markerName, docShellId, docShellHistoryId) //--------------------------------------------------------------------------- // Output profiles @@ -808,35 +848,59 @@ public: class MOZ_RAII AutoProfilerTracing { public: - AutoProfilerTracing(const char* aCategory, const char* aMarkerName + AutoProfilerTracing(const char* aCategory, + const char* aMarkerName, + const mozilla::Maybe& aDocShellId, + const mozilla::Maybe& aDocShellHistoryId MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mCategory(aCategory) , mMarkerName(aMarkerName) + , mDocShellId(aDocShellId) + , mDocShellHistoryId(aDocShellHistoryId) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; - profiler_tracing(mCategory, mMarkerName, TRACING_INTERVAL_START); + profiler_tracing(mCategory, + mMarkerName, + TRACING_INTERVAL_START, + mDocShellId, + mDocShellHistoryId); } - AutoProfilerTracing(const char* aCategory, const char* aMarkerName, - UniqueProfilerBacktrace aBacktrace + AutoProfilerTracing(const char* aCategory, + const char* aMarkerName, + UniqueProfilerBacktrace aBacktrace, + const mozilla::Maybe& aDocShellId, + const mozilla::Maybe& aDocShellHistoryId MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : mCategory(aCategory) , mMarkerName(aMarkerName) + , mDocShellId(aDocShellId) + , mDocShellHistoryId(aDocShellHistoryId) { MOZ_GUARD_OBJECT_NOTIFIER_INIT; - profiler_tracing(mCategory, mMarkerName, TRACING_INTERVAL_START, - std::move(aBacktrace)); + profiler_tracing(mCategory, + mMarkerName, + TRACING_INTERVAL_START, + std::move(aBacktrace), + mDocShellId, + mDocShellHistoryId); } ~AutoProfilerTracing() { - profiler_tracing(mCategory, mMarkerName, TRACING_INTERVAL_END); + profiler_tracing(mCategory, + mMarkerName, + TRACING_INTERVAL_END, + mDocShellId, + mDocShellHistoryId); } protected: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER const char* mCategory; const char* mMarkerName; + const mozilla::Maybe mDocShellId; + const mozilla::Maybe mDocShellHistoryId; }; // Set MOZ_PROFILER_STARTUP* environment variables that will be inherited into diff --git a/tools/profiler/public/ProfilerMarkerPayload.h b/tools/profiler/public/ProfilerMarkerPayload.h index 57c32f8d2460..e182f4d4fd14 100644 --- a/tools/profiler/public/ProfilerMarkerPayload.h +++ b/tools/profiler/public/ProfilerMarkerPayload.h @@ -38,16 +38,26 @@ class UniqueStacks; class ProfilerMarkerPayload { public: - explicit ProfilerMarkerPayload(UniqueProfilerBacktrace aStack = nullptr) + explicit ProfilerMarkerPayload( + const mozilla::Maybe& aDocShellId = mozilla::Nothing(), + const mozilla::Maybe& aDocShellHistoryId = mozilla::Nothing(), + UniqueProfilerBacktrace aStack = nullptr) : mStack(std::move(aStack)) + , mDocShellId(aDocShellId) + , mDocShellHistoryId(aDocShellHistoryId) {} - ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime, - const mozilla::TimeStamp& aEndTime, - UniqueProfilerBacktrace aStack = nullptr) + ProfilerMarkerPayload( + const mozilla::TimeStamp& aStartTime, + const mozilla::TimeStamp& aEndTime, + const mozilla::Maybe& aDocShellId = mozilla::Nothing(), + const mozilla::Maybe& aDocShellHistoryId = mozilla::Nothing(), + UniqueProfilerBacktrace aStack = nullptr) : mStartTime(aStartTime) , mEndTime(aEndTime) , mStack(std::move(aStack)) + , mDocShellId(aDocShellId) + , mDocShellHistoryId(aDocShellHistoryId) {} virtual ~ProfilerMarkerPayload() {} @@ -70,10 +80,22 @@ protected: mStack = std::move(aStack); } + void SetDocShellHistoryId(const mozilla::Maybe& aDocShellHistoryId) + { + mDocShellHistoryId = aDocShellHistoryId; + } + + void SetDocShellId(const mozilla::Maybe& aDocShellId) + { + mDocShellId = aDocShellId; + } + private: mozilla::TimeStamp mStartTime; mozilla::TimeStamp mEndTime; UniqueProfilerBacktrace mStack; + mozilla::Maybe mDocShellId; + mozilla::Maybe mDocShellHistoryId; }; #define DECL_STREAM_PAYLOAD \ @@ -81,17 +103,24 @@ private: const mozilla::TimeStamp& aProcessStartTime, \ UniqueStacks& aUniqueStacks) override; +// TODO: Increase the coverage of tracing markers that include DocShell information class TracingMarkerPayload : public ProfilerMarkerPayload { public: - TracingMarkerPayload(const char* aCategory, TracingKind aKind, - UniqueProfilerBacktrace aCause = nullptr) + TracingMarkerPayload( + const char* aCategory, + TracingKind aKind, + const mozilla::Maybe& aDocShellId = mozilla::Nothing(), + const mozilla::Maybe& aDocShellHistoryId = mozilla::Nothing(), + UniqueProfilerBacktrace aCause = nullptr) : mCategory(aCategory) , mKind(aKind) { if (aCause) { SetStack(std::move(aCause)); } + SetDocShellId(aDocShellId); + SetDocShellHistoryId(aDocShellHistoryId); } DECL_STREAM_PAYLOAD @@ -104,11 +133,16 @@ private: class IOMarkerPayload : public ProfilerMarkerPayload { public: - IOMarkerPayload(const char* aSource, const char* aFilename, + IOMarkerPayload(const char* aSource, + const char* aFilename, const mozilla::TimeStamp& aStartTime, const mozilla::TimeStamp& aEndTime, UniqueProfilerBacktrace aStack) - : ProfilerMarkerPayload(aStartTime, aEndTime, std::move(aStack)) + : ProfilerMarkerPayload(aStartTime, + aEndTime, + mozilla::Nothing(), + mozilla::Nothing(), + std::move(aStack)) , mSource(aSource) , mFilename(aFilename ? strdup(aFilename) : nullptr) { @@ -127,8 +161,11 @@ class DOMEventMarkerPayload : public TracingMarkerPayload public: DOMEventMarkerPayload(const nsAString& aEventType, const mozilla::TimeStamp& aTimeStamp, - const char* aCategory, TracingKind aKind) - : TracingMarkerPayload(aCategory, aKind) + const char* aCategory, + TracingKind aKind, + const mozilla::Maybe& aDocShellId, + const mozilla::Maybe& aDocShellHistoryId) + : TracingMarkerPayload(aCategory, aKind, aDocShellId, aDocShellHistoryId) , mTimeStamp(aTimeStamp) , mEventType(aEventType) {} @@ -144,8 +181,13 @@ class UserTimingMarkerPayload : public ProfilerMarkerPayload { public: UserTimingMarkerPayload(const nsAString& aName, - const mozilla::TimeStamp& aStartTime) - : ProfilerMarkerPayload(aStartTime, aStartTime) + const mozilla::TimeStamp& aStartTime, + const mozilla::Maybe& aDocShellId, + const mozilla::Maybe& aDocShellHistoryId) + : ProfilerMarkerPayload(aStartTime, + aStartTime, + aDocShellId, + aDocShellHistoryId) , mEntryType("mark") , mName(aName) {} @@ -154,8 +196,13 @@ public: const mozilla::Maybe& aStartMark, const mozilla::Maybe& aEndMark, const mozilla::TimeStamp& aStartTime, - const mozilla::TimeStamp& aEndTime) - : ProfilerMarkerPayload(aStartTime, aEndTime) + const mozilla::TimeStamp& aEndTime, + const mozilla::Maybe& aDocShellId, + const mozilla::Maybe& aDocShellHistoryId) + : ProfilerMarkerPayload(aStartTime, + aEndTime, + aDocShellId, + aDocShellHistoryId) , mEntryType("measure") , mName(aName) , mStartMark(aStartMark) @@ -208,7 +255,8 @@ public: class NetworkMarkerPayload : public ProfilerMarkerPayload { public: - NetworkMarkerPayload(int64_t aID, const char* aURI, + NetworkMarkerPayload(int64_t aID, + const char* aURI, NetworkLoadType aType, const mozilla::TimeStamp& aStartTime, const mozilla::TimeStamp& aEndTime, @@ -216,10 +264,12 @@ public: int64_t aCount, const mozilla::net::TimingStruct* aTimings = nullptr, const char* aRedirectURI = nullptr) - : ProfilerMarkerPayload(aStartTime, aEndTime) + : ProfilerMarkerPayload(aStartTime, aEndTime, mozilla::Nothing()) , mID(aID) , mURI(aURI ? strdup(aURI) : nullptr) - , mRedirectURI(aRedirectURI && (strlen(aRedirectURI) > 0) ? strdup(aRedirectURI) : nullptr) + , mRedirectURI(aRedirectURI && (strlen(aRedirectURI) > 0) + ? strdup(aRedirectURI) + : nullptr) , mType(aType) , mPri(aPri) , mCount(aCount) @@ -328,8 +378,13 @@ public: StyleMarkerPayload(const mozilla::TimeStamp& aStartTime, const mozilla::TimeStamp& aEndTime, UniqueProfilerBacktrace aCause, - const mozilla::ServoTraversalStatistics& aStats) - : ProfilerMarkerPayload(aStartTime, aEndTime) + const mozilla::ServoTraversalStatistics& aStats, + const mozilla::Maybe& aDocShellId, + const mozilla::Maybe& aDocShellHistoryId) + : ProfilerMarkerPayload(aStartTime, + aEndTime, + aDocShellId, + aDocShellHistoryId) , mStats(aStats) { if (aCause) { diff --git a/tools/profiler/tests/gtest/GeckoProfiler.cpp b/tools/profiler/tests/gtest/GeckoProfiler.cpp index 5a18adedf4a2..4e6150576530 100644 --- a/tools/profiler/tests/gtest/GeckoProfiler.cpp +++ b/tools/profiler/tests/gtest/GeckoProfiler.cpp @@ -458,7 +458,10 @@ TEST(GeckoProfiler, Markers) PROFILER_ADD_MARKER("M3"); profiler_add_marker( "M4", - MakeUnique("C", TRACING_EVENT, + MakeUnique("C", + TRACING_EVENT, + mozilla::Nothing(), + mozilla::Nothing(), profiler_get_backtrace())); for (int i = 0; i < 10; i++) {