зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1141614 - Part 2: Add mozilla::AutoGlobalTimelineMarker; r=smaug
This commit is contained in:
Родитель
ac6fdc2468
Коммит
e3176f3516
|
@ -0,0 +1,105 @@
|
||||||
|
/* -*- 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/AutoTimelineMarker.h"
|
||||||
|
|
||||||
|
#include "MainThreadUtils.h"
|
||||||
|
#include "nsDocShell.h"
|
||||||
|
#include "mozilla/Move.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
bool
|
||||||
|
AutoTimelineMarker::DocShellIsRecording(nsDocShell& aDocShell)
|
||||||
|
{
|
||||||
|
bool isRecording = false;
|
||||||
|
if (nsDocShell::gProfileTimelineRecordingsCount > 0) {
|
||||||
|
aDocShell.GetRecordProfileTimelineMarkers(&isRecording);
|
||||||
|
}
|
||||||
|
return isRecording;
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoTimelineMarker::AutoTimelineMarker(nsIDocShell* aDocShell, const char* aName
|
||||||
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
|
||||||
|
: mDocShell(nullptr)
|
||||||
|
, mName(aName)
|
||||||
|
{
|
||||||
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
nsDocShell* docShell = static_cast<nsDocShell*>(aDocShell);
|
||||||
|
if (docShell && DocShellIsRecording(*docShell)) {
|
||||||
|
mDocShell = docShell;
|
||||||
|
mDocShell->AddProfileTimelineMarker(mName, TRACING_INTERVAL_START);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoTimelineMarker::~AutoTimelineMarker()
|
||||||
|
{
|
||||||
|
if (mDocShell) {
|
||||||
|
mDocShell->AddProfileTimelineMarker(mName, TRACING_INTERVAL_END);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AutoGlobalTimelineMarker::PopulateDocShells()
|
||||||
|
{
|
||||||
|
const LinkedList<nsDocShell::ObservedDocShell>& 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<nsRefPtr<nsDocShell>>::Range range = mDocShells.all();
|
||||||
|
!range.empty();
|
||||||
|
range.popFront()) {
|
||||||
|
range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_START);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoGlobalTimelineMarker::~AutoGlobalTimelineMarker()
|
||||||
|
{
|
||||||
|
if (!mOk) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Vector<nsRefPtr<nsDocShell>>::Range range = mDocShells.all();
|
||||||
|
!range.empty();
|
||||||
|
range.popFront()) {
|
||||||
|
range.front()->AddProfileTimelineMarker(mName, TRACING_INTERVAL_END);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace mozilla
|
|
@ -8,10 +8,13 @@
|
||||||
#define AutoTimelineMarker_h__
|
#define AutoTimelineMarker_h__
|
||||||
|
|
||||||
#include "mozilla/GuardObjects.h"
|
#include "mozilla/GuardObjects.h"
|
||||||
#include "mozilla/Move.h"
|
#include "mozilla/Vector.h"
|
||||||
#include "nsDocShell.h"
|
|
||||||
#include "nsRefPtr.h"
|
#include "nsRefPtr.h"
|
||||||
|
|
||||||
|
class nsIDocShell;
|
||||||
|
class nsDocShell;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
// # AutoTimelineMarker
|
// # AutoTimelineMarker
|
||||||
|
@ -27,7 +30,6 @@ namespace mozilla {
|
||||||
// nsresult rv = ParseTheCSSFile(mFile);
|
// nsresult rv = ParseTheCSSFile(mFile);
|
||||||
// ...
|
// ...
|
||||||
// }
|
// }
|
||||||
|
|
||||||
class MOZ_STACK_CLASS AutoTimelineMarker
|
class MOZ_STACK_CLASS AutoTimelineMarker
|
||||||
{
|
{
|
||||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
|
||||||
|
@ -35,42 +37,57 @@ class MOZ_STACK_CLASS AutoTimelineMarker
|
||||||
nsRefPtr<nsDocShell> mDocShell;
|
nsRefPtr<nsDocShell> mDocShell;
|
||||||
const char* mName;
|
const char* mName;
|
||||||
|
|
||||||
bool
|
bool DocShellIsRecording(nsDocShell& aDocShell);
|
||||||
DocShellIsRecording(nsDocShell& aDocShell)
|
|
||||||
{
|
|
||||||
bool isRecording = false;
|
|
||||||
if (nsDocShell::gProfileTimelineRecordingsCount > 0) {
|
|
||||||
aDocShell.GetRecordProfileTimelineMarkers(&isRecording);
|
|
||||||
}
|
|
||||||
return isRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AutoTimelineMarker(nsIDocShell* aDocShell, const char* aName
|
explicit AutoTimelineMarker(nsIDocShell* aDocShell, const char* aName
|
||||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
|
||||||
: mDocShell(nullptr)
|
~AutoTimelineMarker();
|
||||||
, mName(aName)
|
|
||||||
{
|
|
||||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
||||||
|
|
||||||
nsDocShell* docShell = static_cast<nsDocShell*>(aDocShell);
|
|
||||||
if (docShell && DocShellIsRecording(*docShell)) {
|
|
||||||
mDocShell = docShell;
|
|
||||||
mDocShell->AddProfileTimelineMarker(mName, TRACING_INTERVAL_START);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~AutoTimelineMarker()
|
|
||||||
{
|
|
||||||
if (mDocShell) {
|
|
||||||
mDocShell->AddProfileTimelineMarker(mName, TRACING_INTERVAL_END);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoTimelineMarker(const AutoTimelineMarker& aOther) = delete;
|
AutoTimelineMarker(const AutoTimelineMarker& aOther) = delete;
|
||||||
void operator=(const AutoTimelineMarker& aOther) = delete;
|
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<nsRefPtr<nsDocShell>> 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
|
} // namespace mozilla
|
||||||
|
|
||||||
#endif /* AutoTimelineMarker_h__ */
|
#endif /* AutoTimelineMarker_h__ */
|
||||||
|
|
|
@ -48,6 +48,7 @@ EXPORTS.mozilla += [
|
||||||
]
|
]
|
||||||
|
|
||||||
UNIFIED_SOURCES += [
|
UNIFIED_SOURCES += [
|
||||||
|
'AutoTimelineMarker.cpp',
|
||||||
'LoadContext.cpp',
|
'LoadContext.cpp',
|
||||||
'nsAboutRedirector.cpp',
|
'nsAboutRedirector.cpp',
|
||||||
'nsDefaultURIFixup.cpp',
|
'nsDefaultURIFixup.cpp',
|
||||||
|
|
Загрузка…
Ссылка в новой задаче