mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1141614 - Part 2: Add mozilla::AutoGlobalTimelineMarker; r=smaug
This commit is contained in:
parent
f3ec8dcf22
commit
4028b6226f
105
docshell/base/AutoTimelineMarker.cpp
Normal file
105
docshell/base/AutoTimelineMarker.cpp
Normal file
@ -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__
|
||||
|
||||
#include "mozilla/GuardObjects.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "nsDocShell.h"
|
||||
#include "mozilla/Vector.h"
|
||||
|
||||
#include "nsRefPtr.h"
|
||||
|
||||
class nsIDocShell;
|
||||
class nsDocShell;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// # AutoTimelineMarker
|
||||
@ -27,7 +30,6 @@ namespace mozilla {
|
||||
// nsresult rv = ParseTheCSSFile(mFile);
|
||||
// ...
|
||||
// }
|
||||
|
||||
class MOZ_STACK_CLASS AutoTimelineMarker
|
||||
{
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
|
||||
@ -35,42 +37,57 @@ class MOZ_STACK_CLASS AutoTimelineMarker
|
||||
nsRefPtr<nsDocShell> mDocShell;
|
||||
const char* mName;
|
||||
|
||||
bool
|
||||
DocShellIsRecording(nsDocShell& aDocShell)
|
||||
{
|
||||
bool isRecording = false;
|
||||
if (nsDocShell::gProfileTimelineRecordingsCount > 0) {
|
||||
aDocShell.GetRecordProfileTimelineMarkers(&isRecording);
|
||||
}
|
||||
return isRecording;
|
||||
}
|
||||
bool DocShellIsRecording(nsDocShell& aDocShell);
|
||||
|
||||
public:
|
||||
explicit AutoTimelineMarker(nsIDocShell* aDocShell, const char* aName
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: mDocShell(nullptr)
|
||||
, 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);
|
||||
}
|
||||
}
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
|
||||
~AutoTimelineMarker();
|
||||
|
||||
AutoTimelineMarker(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
|
||||
|
||||
#endif /* AutoTimelineMarker_h__ */
|
||||
|
@ -48,6 +48,7 @@ EXPORTS.mozilla += [
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'AutoTimelineMarker.cpp',
|
||||
'LoadContext.cpp',
|
||||
'nsAboutRedirector.cpp',
|
||||
'nsDefaultURIFixup.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user