diff --git a/docshell/base/timeline/AutoGlobalTimelineMarker.cpp b/docshell/base/timeline/AutoGlobalTimelineMarker.cpp new file mode 100644 index 00000000000..4e0721c0d94 --- /dev/null +++ b/docshell/base/timeline/AutoGlobalTimelineMarker.cpp @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/AutoGlobalTimelineMarker.h" + +#include "MainThreadUtils.h" +#include "nsDocShell.h" + +namespace mozilla { + +void +AutoGlobalTimelineMarker::PopulateDocShells() +{ + const LinkedList& docShells = + nsDocShell::GetObservedDocShells(); + MOZ_ASSERT(!docShells.isEmpty()); + + for (const nsDocShell::ObservedDocShell* ds = docShells.getFirst(); + ds; + ds = ds->getNext()) { + mOk = mDocShells.append(**ds); + if (!mOk) { + return; + } + } +} + +AutoGlobalTimelineMarker::AutoGlobalTimelineMarker(const char* aName + MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) + : mOk(true) + , mDocShells() + , mName(aName) +{ + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + MOZ_ASSERT(NS_IsMainThread()); + + if (nsDocShell::gProfileTimelineRecordingsCount == 0) { + return; + } + + PopulateDocShells(); + if (!mOk) { + // If we don't successfully populate our vector with *all* docshells being + // observed, don't add markers to *any* of them. + return; + } + + for (Vector>::Range range = mDocShells.all(); + !range.empty(); + range.popFront()) { + range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_START); + } +} + +AutoGlobalTimelineMarker::~AutoGlobalTimelineMarker() +{ + if (!mOk) { + return; + } + + for (Vector>::Range range = mDocShells.all(); + !range.empty(); + range.popFront()) { + range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_END); + } +} + +} // namespace mozilla diff --git a/docshell/base/timeline/AutoGlobalTimelineMarker.h b/docshell/base/timeline/AutoGlobalTimelineMarker.h new file mode 100644 index 00000000000..464425ff15c --- /dev/null +++ b/docshell/base/timeline/AutoGlobalTimelineMarker.h @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_AutoGlobalTimelineMarker_h_ +#define mozilla_AutoGlobalTimelineMarker_h_ + +#include "mozilla/GuardObjects.h" +#include "mozilla/Vector.h" +#include "nsRefPtr.h" + +class nsDocShell; + +namespace mozilla { + +// # AutoGlobalTimelineMarker +// +// Similar to `AutoTimelineMarker`, but adds its traced marker to all docshells, +// not a single particular one. This is useful for operations that aren't +// associated with any one particular doc shell, or when it isn't clear which +// doc shell triggered the operation. +// +// Example usage: +// +// { +// AutoGlobalTimelineMarker marker("Cycle Collection"); +// nsCycleCollector* cc = GetCycleCollector(); +// cc->Collect(); +// ... +// } +class MOZ_STACK_CLASS AutoGlobalTimelineMarker +{ + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER; + + // True as long as no operation has failed, eg due to OOM. + bool mOk; + + // The set of docshells that are being observed and will get markers. + mozilla::Vector> mDocShells; + + // The name of the marker we are adding. + const char* mName; + + void PopulateDocShells(); + +public: + explicit AutoGlobalTimelineMarker(const char* aName + MOZ_GUARD_OBJECT_NOTIFIER_PARAM); + + ~AutoGlobalTimelineMarker(); + + AutoGlobalTimelineMarker(const AutoGlobalTimelineMarker& aOther) = delete; + void operator=(const AutoGlobalTimelineMarker& aOther) = delete; +}; + +} // namespace mozilla + +#endif /* mozilla_AutoGlobalTimelineMarker_h_ */ diff --git a/docshell/base/timeline/AutoTimelineMarker.cpp b/docshell/base/timeline/AutoTimelineMarker.cpp index 5a2027d9741..82fcd1de8b0 100644 --- a/docshell/base/timeline/AutoTimelineMarker.cpp +++ b/docshell/base/timeline/AutoTimelineMarker.cpp @@ -8,7 +8,6 @@ #include "MainThreadUtils.h" #include "nsDocShell.h" -#include "mozilla/Move.h" namespace mozilla { @@ -44,62 +43,4 @@ AutoTimelineMarker::~AutoTimelineMarker() } } -void -AutoGlobalTimelineMarker::PopulateDocShells() -{ - const LinkedList& docShells = - nsDocShell::GetObservedDocShells(); - MOZ_ASSERT(!docShells.isEmpty()); - - for (const nsDocShell::ObservedDocShell* ds = docShells.getFirst(); - ds; - ds = ds->getNext()) { - mOk = mDocShells.append(**ds); - if (!mOk) { - return; - } - } -} - -AutoGlobalTimelineMarker::AutoGlobalTimelineMarker(const char* aName - MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) - : mOk(true) - , mDocShells() - , mName(aName) -{ - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - MOZ_ASSERT(NS_IsMainThread()); - - if (nsDocShell::gProfileTimelineRecordingsCount == 0) { - return; - } - - PopulateDocShells(); - if (!mOk) { - // If we don't successfully populate our vector with *all* docshells being - // observed, don't add markers to *any* of them. - return; - } - - for (Vector>::Range range = mDocShells.all(); - !range.empty(); - range.popFront()) { - range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_START); - } -} - -AutoGlobalTimelineMarker::~AutoGlobalTimelineMarker() -{ - if (!mOk) { - return; - } - - for (Vector>::Range range = mDocShells.all(); - !range.empty(); - range.popFront()) { - range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_END); - } -} - - } // namespace mozilla diff --git a/docshell/base/timeline/AutoTimelineMarker.h b/docshell/base/timeline/AutoTimelineMarker.h index 2f9db74158a..918cce19603 100644 --- a/docshell/base/timeline/AutoTimelineMarker.h +++ b/docshell/base/timeline/AutoTimelineMarker.h @@ -4,12 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef AutoTimelineMarker_h__ -#define AutoTimelineMarker_h__ +#ifndef mozilla_AutoTimelineMarker_h_ +#define mozilla_AutoTimelineMarker_h_ #include "mozilla/GuardObjects.h" -#include "mozilla/Vector.h" - #include "nsRefPtr.h" class nsIDocShell; @@ -48,46 +46,6 @@ public: void operator=(const AutoTimelineMarker& aOther) = delete; }; -// # AutoGlobalTimelineMarker -// -// Similar to `AutoTimelineMarker`, but adds its traced marker to all docshells, -// not a single particular one. This is useful for operations that aren't -// associated with any one particular doc shell, or when it isn't clear which -// doc shell triggered the operation. -// -// Example usage: -// -// { -// AutoGlobalTimelineMarker marker("Cycle Collection"); -// nsCycleCollector* cc = GetCycleCollector(); -// cc->Collect(); -// ... -// } -class MOZ_STACK_CLASS AutoGlobalTimelineMarker -{ - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER; - - // True as long as no operation has failed, eg due to OOM. - bool mOk; - - // The set of docshells that are being observed and will get markers. - mozilla::Vector> mDocShells; - - // The name of the marker we are adding. - const char* mName; - - void PopulateDocShells(); - -public: - explicit AutoGlobalTimelineMarker(const char* aName - MOZ_GUARD_OBJECT_NOTIFIER_PARAM); - - ~AutoGlobalTimelineMarker(); - - AutoGlobalTimelineMarker(const AutoGlobalTimelineMarker& aOther) = delete; - void operator=(const AutoGlobalTimelineMarker& aOther) = delete; -}; - } // namespace mozilla -#endif /* AutoTimelineMarker_h__ */ +#endif /* mozilla_AutoTimelineMarker_h_ */ diff --git a/docshell/base/timeline/TimelineMarker.h b/docshell/base/timeline/TimelineMarker.h index a13baef3974..25e6e2e8e53 100644 --- a/docshell/base/timeline/TimelineMarker.h +++ b/docshell/base/timeline/TimelineMarker.h @@ -4,8 +4,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef TimelineMarker_h__ -#define TimelineMarker_h__ +#ifndef TimelineMarker_h_ +#define TimelineMarker_h_ #include "nsString.h" #include "GeckoProfiler.h" @@ -96,4 +96,4 @@ private: JS::PersistentRooted mStackTrace; }; -#endif /* TimelineMarker_h__ */ +#endif /* TimelineMarker_h_ */ diff --git a/docshell/base/timeline/moz.build b/docshell/base/timeline/moz.build index 3be0552103f..7c06af16309 100644 --- a/docshell/base/timeline/moz.build +++ b/docshell/base/timeline/moz.build @@ -5,10 +5,12 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXPORTS.mozilla += [ + 'AutoGlobalTimelineMarker.h', 'AutoTimelineMarker.h', ] UNIFIED_SOURCES += [ + 'AutoGlobalTimelineMarker.cpp', 'AutoTimelineMarker.cpp', 'TimelineMarker.cpp', ] diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 1919f0aaf76..1fdb2b99abe 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -182,7 +182,7 @@ #include #include -#include "mozilla/AutoTimelineMarker.h" +#include "mozilla/AutoGlobalTimelineMarker.h" #include "mozilla/Likely.h" #include "mozilla/PoisonIOInterposer.h" #include "mozilla/Telemetry.h"