зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1113706 - move TimelineMarker to a new header; r=smaug
This commit is contained in:
Родитель
fe1c2f8645
Коммит
14484f49ae
|
@ -0,0 +1,42 @@
|
|||
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: set ts=2 sw=2 tw=80 et:
|
||||
*
|
||||
* 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 "nsDocShell.h"
|
||||
#include "TimelineMarker.h"
|
||||
|
||||
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
|
||||
TracingMetadata aMetaData)
|
||||
: mName(aName)
|
||||
, mMetaData(aMetaData)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TimelineMarker);
|
||||
MOZ_ASSERT(aName);
|
||||
aDocShell->Now(&mTime);
|
||||
if (aMetaData == TRACING_INTERVAL_START) {
|
||||
CaptureStack();
|
||||
}
|
||||
}
|
||||
|
||||
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
|
||||
TracingMetadata aMetaData,
|
||||
const nsAString& aCause)
|
||||
: mName(aName)
|
||||
, mMetaData(aMetaData)
|
||||
, mCause(aCause)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TimelineMarker);
|
||||
MOZ_ASSERT(aName);
|
||||
aDocShell->Now(&mTime);
|
||||
if (aMetaData == TRACING_INTERVAL_START) {
|
||||
CaptureStack();
|
||||
}
|
||||
}
|
||||
|
||||
TimelineMarker::~TimelineMarker()
|
||||
{
|
||||
MOZ_COUNT_DTOR(TimelineMarker);
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: set ts=2 sw=2 tw=80 et:
|
||||
*
|
||||
* 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 TimelineMarker_h__
|
||||
#define TimelineMarker_h__
|
||||
|
||||
#include "nsString.h"
|
||||
#include "GeckoProfiler.h"
|
||||
#include "mozilla/dom/ProfileTimelineMarkerBinding.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
class nsDocShell;
|
||||
|
||||
// Objects of this type can be added to the timeline. The class can
|
||||
// also be subclassed to let a given marker creator provide custom
|
||||
// details.
|
||||
class TimelineMarker
|
||||
{
|
||||
public:
|
||||
TimelineMarker(nsDocShell* aDocShell, const char* aName,
|
||||
TracingMetadata aMetaData);
|
||||
|
||||
TimelineMarker(nsDocShell* aDocShell, const char* aName,
|
||||
TracingMetadata aMetaData,
|
||||
const nsAString& aCause);
|
||||
|
||||
virtual ~TimelineMarker();
|
||||
|
||||
// Check whether two markers should be considered the same,
|
||||
// for the purpose of pairing start and end markers. Normally
|
||||
// this definition suffices.
|
||||
virtual bool Equals(const TimelineMarker* other)
|
||||
{
|
||||
return strcmp(mName, other->mName) == 0;
|
||||
}
|
||||
|
||||
// Add details specific to this marker type to aMarker. The
|
||||
// standard elements have already been set. This method is
|
||||
// called on both the starting and ending markers of a pair.
|
||||
// Ordinarily the ending marker doesn't need to do anything
|
||||
// here.
|
||||
virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void AddLayerRectangles(mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
|
||||
{
|
||||
MOZ_ASSERT_UNREACHABLE("can only be called on layer markers");
|
||||
}
|
||||
|
||||
const char* GetName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
TracingMetadata GetMetaData() const
|
||||
{
|
||||
return mMetaData;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp GetTime() const
|
||||
{
|
||||
return mTime;
|
||||
}
|
||||
|
||||
const nsString& GetCause() const
|
||||
{
|
||||
return mCause;
|
||||
}
|
||||
|
||||
JSObject* GetStack()
|
||||
{
|
||||
if (mStackTrace) {
|
||||
return mStackTrace->get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void CaptureStack()
|
||||
{
|
||||
JSContext* ctx = nsContentUtils::GetCurrentJSContext();
|
||||
if (ctx) {
|
||||
JS::RootedObject stack(ctx);
|
||||
if (JS::CaptureCurrentStack(ctx, &stack)) {
|
||||
mStackTrace.emplace(ctx, stack.get());
|
||||
} else {
|
||||
JS_ClearPendingException(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
const char* mName;
|
||||
TracingMetadata mMetaData;
|
||||
DOMHighResTimeStamp mTime;
|
||||
nsString mCause;
|
||||
|
||||
// While normally it is not a good idea to make a persistent
|
||||
// root, in this case changing nsDocShell to participate in
|
||||
// cycle collection was deemed too invasive, the stack trace
|
||||
// can't actually cause a cycle, and the markers are only held
|
||||
// here temporarily to boot.
|
||||
mozilla::Maybe<JS::PersistentRooted<JSObject*>> mStackTrace;
|
||||
};
|
||||
|
||||
#endif /* TimelineMarker_h__ */
|
|
@ -62,6 +62,7 @@ UNIFIED_SOURCES += [
|
|||
'nsDSURIContentListener.cpp',
|
||||
'nsWebNavigationInfo.cpp',
|
||||
'SerializedLoadContext.cpp',
|
||||
'TimelineMarker.cpp',
|
||||
]
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "nsAutoPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "TimelineMarker.h"
|
||||
|
||||
// Threshold value in ms for META refresh based redirects
|
||||
#define REFRESH_REDIRECT_TIMER 15000
|
||||
|
@ -260,125 +261,6 @@ public:
|
|||
// is no longer applied
|
||||
void NotifyAsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos);
|
||||
|
||||
// Objects of this type can be added to the timeline. The class
|
||||
// can also be subclassed to let a given marker creator provide
|
||||
// custom details.
|
||||
class TimelineMarker
|
||||
{
|
||||
public:
|
||||
TimelineMarker(nsDocShell* aDocShell, const char* aName,
|
||||
TracingMetadata aMetaData)
|
||||
: mName(aName)
|
||||
, mMetaData(aMetaData)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TimelineMarker);
|
||||
MOZ_ASSERT(aName);
|
||||
aDocShell->Now(&mTime);
|
||||
if (aMetaData == TRACING_INTERVAL_START) {
|
||||
CaptureStack();
|
||||
}
|
||||
}
|
||||
|
||||
TimelineMarker(nsDocShell* aDocShell, const char* aName,
|
||||
TracingMetadata aMetaData,
|
||||
const nsAString& aCause)
|
||||
: mName(aName)
|
||||
, mMetaData(aMetaData)
|
||||
, mCause(aCause)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TimelineMarker);
|
||||
MOZ_ASSERT(aName);
|
||||
aDocShell->Now(&mTime);
|
||||
if (aMetaData == TRACING_INTERVAL_START) {
|
||||
CaptureStack();
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~TimelineMarker()
|
||||
{
|
||||
MOZ_COUNT_DTOR(TimelineMarker);
|
||||
}
|
||||
|
||||
// Check whether two markers should be considered the same,
|
||||
// for the purpose of pairing start and end markers. Normally
|
||||
// this definition suffices.
|
||||
virtual bool Equals(const TimelineMarker* other)
|
||||
{
|
||||
return strcmp(mName, other->mName) == 0;
|
||||
}
|
||||
|
||||
// Add details specific to this marker type to aMarker. The
|
||||
// standard elements have already been set. This method is
|
||||
// called on both the starting and ending markers of a pair.
|
||||
// Ordinarily the ending marker doesn't need to do anything
|
||||
// here.
|
||||
virtual void AddDetails(mozilla::dom::ProfileTimelineMarker& aMarker)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void AddLayerRectangles(mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
|
||||
{
|
||||
MOZ_ASSERT_UNREACHABLE("can only be called on layer markers");
|
||||
}
|
||||
|
||||
const char* GetName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
TracingMetadata GetMetaData() const
|
||||
{
|
||||
return mMetaData;
|
||||
}
|
||||
|
||||
DOMHighResTimeStamp GetTime() const
|
||||
{
|
||||
return mTime;
|
||||
}
|
||||
|
||||
const nsString& GetCause() const
|
||||
{
|
||||
return mCause;
|
||||
}
|
||||
|
||||
JSObject* GetStack()
|
||||
{
|
||||
if (mStackTrace) {
|
||||
return mStackTrace->get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void CaptureStack()
|
||||
{
|
||||
JSContext* ctx = nsContentUtils::GetCurrentJSContext();
|
||||
if (ctx) {
|
||||
JS::RootedObject stack(ctx);
|
||||
if (JS::CaptureCurrentStack(ctx, &stack)) {
|
||||
mStackTrace.emplace(ctx, stack.get());
|
||||
} else {
|
||||
JS_ClearPendingException(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
const char* mName;
|
||||
TracingMetadata mMetaData;
|
||||
DOMHighResTimeStamp mTime;
|
||||
nsString mCause;
|
||||
|
||||
// While normally it is not a good idea to make a persistent
|
||||
// root, in this case changing nsDocShell to participate in
|
||||
// cycle collection was deemed too invasive, the stack trace
|
||||
// can't actually cause a cycle, and the markers are only held
|
||||
// here temporarily to boot.
|
||||
mozilla::Maybe<JS::PersistentRooted<JSObject*>> mStackTrace;
|
||||
};
|
||||
|
||||
// Add new profile timeline markers to this docShell. This will only add
|
||||
// markers if the docShell is currently recording profile timeline markers.
|
||||
// See nsIDocShell::recordProfileTimelineMarkers
|
||||
|
|
|
@ -805,22 +805,22 @@ ReifyStack(nsIStackFrame* aStack, nsTArray<ConsoleStackEntry>& aRefiedStack)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class ConsoleTimelineMarker : public nsDocShell::TimelineMarker
|
||||
class ConsoleTimelineMarker : public TimelineMarker
|
||||
{
|
||||
public:
|
||||
ConsoleTimelineMarker(nsDocShell* aDocShell,
|
||||
TracingMetadata aMetaData,
|
||||
const nsAString& aCause)
|
||||
: nsDocShell::TimelineMarker(aDocShell, "ConsoleTime", aMetaData, aCause)
|
||||
: TimelineMarker(aDocShell, "ConsoleTime", aMetaData, aCause)
|
||||
{
|
||||
if (aMetaData == TRACING_INTERVAL_END) {
|
||||
CaptureStack();
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Equals(const nsDocShell::TimelineMarker* aOther)
|
||||
virtual bool Equals(const TimelineMarker* aOther)
|
||||
{
|
||||
if (!nsDocShell::TimelineMarker::Equals(aOther)) {
|
||||
if (!TimelineMarker::Equals(aOther)) {
|
||||
return false;
|
||||
}
|
||||
// Console markers must have matching causes as well.
|
||||
|
@ -969,7 +969,7 @@ Console::Method(JSContext* aCx, MethodName aMethodName,
|
|||
if (jsString) {
|
||||
nsAutoJSString key;
|
||||
if (key.init(aCx, jsString)) {
|
||||
mozilla::UniquePtr<nsDocShell::TimelineMarker> marker =
|
||||
mozilla::UniquePtr<TimelineMarker> marker =
|
||||
MakeUnique<ConsoleTimelineMarker>(docShell,
|
||||
aMethodName == MethodTime ? TRACING_INTERVAL_START : TRACING_INTERVAL_END,
|
||||
key);
|
||||
|
|
|
@ -1024,12 +1024,12 @@ EventListenerManager::GetDocShellForTarget()
|
|||
return docShell;
|
||||
}
|
||||
|
||||
class EventTimelineMarker : public nsDocShell::TimelineMarker
|
||||
class EventTimelineMarker : public TimelineMarker
|
||||
{
|
||||
public:
|
||||
EventTimelineMarker(nsDocShell* aDocShell, TracingMetadata aMetaData,
|
||||
uint16_t aPhase, const nsAString& aCause)
|
||||
: nsDocShell::TimelineMarker(aDocShell, "DOMEvent", aMetaData, aCause)
|
||||
: TimelineMarker(aDocShell, "DOMEvent", aMetaData, aCause)
|
||||
, mPhase(aPhase)
|
||||
{
|
||||
}
|
||||
|
@ -1114,7 +1114,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
|
|||
(*aDOMEvent)->GetType(typeStr);
|
||||
uint16_t phase;
|
||||
(*aDOMEvent)->GetEventPhase(&phase);
|
||||
mozilla::UniquePtr<nsDocShell::TimelineMarker> marker =
|
||||
mozilla::UniquePtr<TimelineMarker> marker =
|
||||
MakeUnique<EventTimelineMarker>(ds, TRACING_INTERVAL_START,
|
||||
phase, typeStr);
|
||||
ds->AddProfileTimelineMarker(marker);
|
||||
|
|
|
@ -4471,11 +4471,11 @@ static void DrawForcedBackgroundColor(DrawTarget& aDrawTarget,
|
|||
}
|
||||
}
|
||||
|
||||
class LayerTimelineMarker : public nsDocShell::TimelineMarker
|
||||
class LayerTimelineMarker : public TimelineMarker
|
||||
{
|
||||
public:
|
||||
LayerTimelineMarker(nsDocShell* aDocShell, const nsIntRegion& aRegion)
|
||||
: nsDocShell::TimelineMarker(aDocShell, "Layer", TRACING_EVENT)
|
||||
: TimelineMarker(aDocShell, "Layer", TRACING_EVENT)
|
||||
, mRegion(aRegion)
|
||||
{
|
||||
}
|
||||
|
@ -4653,7 +4653,7 @@ FrameLayerBuilder::DrawPaintedLayer(PaintedLayer* aLayer,
|
|||
bool isRecording;
|
||||
docShell->GetRecordProfileTimelineMarkers(&isRecording);
|
||||
if (isRecording) {
|
||||
mozilla::UniquePtr<nsDocShell::TimelineMarker> marker =
|
||||
mozilla::UniquePtr<TimelineMarker> marker =
|
||||
MakeUnique<LayerTimelineMarker>(docShell, aRegionToDraw);
|
||||
docShell->AddProfileTimelineMarker(marker);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче