Files
palemoon27/docshell/base/AutoTimelineMarker.cpp
T
roytam1 32a8a44732 import changes from `dev' branch of rmottola/Arctic-Fox:
- remaining part of Bug 1146339 - Do anchor scrolling right before dispatching popstate (1123b0133)
- Bug 1170488 - Document URI should be updated before sending out onLocationChange. r=smaug (6f553c2ee)
- Bug 1144820 - Use nsTArray<UniquePtr<>> to hold timeline markers. r=smaug, r=fitzgen (e4b878ec3)
- Bug 1143004 - markers from console.timeStamp() should be rendered in the performance tool's timeline. r=vp (7d8d4cb0c)
- Bug 1170671 - ProfileTimelineMarkers that use TRACING_TIMESTAMP should capture stack information. r=smaug (dc7982a30)
- Bug 1141614 - Part 1: Maintain a list of docshells whose timeline markers are being observed; r=smaug (2dc04461c)
- Bug 1159779 - mozilla::AutoTimelineMarker shouldn't be copy-able; r=smaug (24aadecd4)
- Bug 1141614 - Part 2: Add mozilla::AutoGlobalTimelineMarker; r=smaug (c069191a5)
- Bug 1141614 - Part 3: Trace cycle collection with AutoGlobalTimelineMarker; r=smaug (2cdccd0fc)
- Bug 1160521 - The markers list sidebar should be wider by default, r=jsantell (c479c72c3)
- Bug 1150696 - Move all timeline tests that are still relevent into the performance tools tests. r=vp (276572541)
- Bug 1165504 - Refactor out marker details view into utilities, make marker definitions more declaritive. r=vp (42218191c)
- Bug 1166139 - properly display the generic class name for markers in the marker filter popup. r=vp (711b0032a)
- Bug 1157916 - Add tooltip for displaying start/end times on marker details' duration field. r=vp (c586757d5)
2021-05-06 09:10:28 +08:00

106 lines
2.7 KiB
C++

/* -*- 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