Bug 1113706 - move TimelineMarker to a new header; r=smaug

This commit is contained in:
Tom Tromey 2015-01-05 09:39:16 -08:00
Родитель fe1c2f8645
Коммит 14484f49ae
7 изменённых файлов: 169 добавлений и 130 удалений

Просмотреть файл

@ -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', 'nsDSURIContentListener.cpp',
'nsWebNavigationInfo.cpp', 'nsWebNavigationInfo.cpp',
'SerializedLoadContext.cpp', 'SerializedLoadContext.cpp',
'TimelineMarker.cpp',
] ]
FAIL_ON_WARNINGS = True FAIL_ON_WARNINGS = True

Просмотреть файл

@ -32,6 +32,7 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "TimelineMarker.h"
// Threshold value in ms for META refresh based redirects // Threshold value in ms for META refresh based redirects
#define REFRESH_REDIRECT_TIMER 15000 #define REFRESH_REDIRECT_TIMER 15000
@ -260,125 +261,6 @@ public:
// is no longer applied // is no longer applied
void NotifyAsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos); 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 // Add new profile timeline markers to this docShell. This will only add
// markers if the docShell is currently recording profile timeline markers. // markers if the docShell is currently recording profile timeline markers.
// See nsIDocShell::recordProfileTimelineMarkers // See nsIDocShell::recordProfileTimelineMarkers

Просмотреть файл

@ -805,22 +805,22 @@ ReifyStack(nsIStackFrame* aStack, nsTArray<ConsoleStackEntry>& aRefiedStack)
return NS_OK; return NS_OK;
} }
class ConsoleTimelineMarker : public nsDocShell::TimelineMarker class ConsoleTimelineMarker : public TimelineMarker
{ {
public: public:
ConsoleTimelineMarker(nsDocShell* aDocShell, ConsoleTimelineMarker(nsDocShell* aDocShell,
TracingMetadata aMetaData, TracingMetadata aMetaData,
const nsAString& aCause) const nsAString& aCause)
: nsDocShell::TimelineMarker(aDocShell, "ConsoleTime", aMetaData, aCause) : TimelineMarker(aDocShell, "ConsoleTime", aMetaData, aCause)
{ {
if (aMetaData == TRACING_INTERVAL_END) { if (aMetaData == TRACING_INTERVAL_END) {
CaptureStack(); 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; return false;
} }
// Console markers must have matching causes as well. // Console markers must have matching causes as well.
@ -969,7 +969,7 @@ Console::Method(JSContext* aCx, MethodName aMethodName,
if (jsString) { if (jsString) {
nsAutoJSString key; nsAutoJSString key;
if (key.init(aCx, jsString)) { if (key.init(aCx, jsString)) {
mozilla::UniquePtr<nsDocShell::TimelineMarker> marker = mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<ConsoleTimelineMarker>(docShell, MakeUnique<ConsoleTimelineMarker>(docShell,
aMethodName == MethodTime ? TRACING_INTERVAL_START : TRACING_INTERVAL_END, aMethodName == MethodTime ? TRACING_INTERVAL_START : TRACING_INTERVAL_END,
key); key);

Просмотреть файл

@ -1024,12 +1024,12 @@ EventListenerManager::GetDocShellForTarget()
return docShell; return docShell;
} }
class EventTimelineMarker : public nsDocShell::TimelineMarker class EventTimelineMarker : public TimelineMarker
{ {
public: public:
EventTimelineMarker(nsDocShell* aDocShell, TracingMetadata aMetaData, EventTimelineMarker(nsDocShell* aDocShell, TracingMetadata aMetaData,
uint16_t aPhase, const nsAString& aCause) uint16_t aPhase, const nsAString& aCause)
: nsDocShell::TimelineMarker(aDocShell, "DOMEvent", aMetaData, aCause) : TimelineMarker(aDocShell, "DOMEvent", aMetaData, aCause)
, mPhase(aPhase) , mPhase(aPhase)
{ {
} }
@ -1114,7 +1114,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
(*aDOMEvent)->GetType(typeStr); (*aDOMEvent)->GetType(typeStr);
uint16_t phase; uint16_t phase;
(*aDOMEvent)->GetEventPhase(&phase); (*aDOMEvent)->GetEventPhase(&phase);
mozilla::UniquePtr<nsDocShell::TimelineMarker> marker = mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<EventTimelineMarker>(ds, TRACING_INTERVAL_START, MakeUnique<EventTimelineMarker>(ds, TRACING_INTERVAL_START,
phase, typeStr); phase, typeStr);
ds->AddProfileTimelineMarker(marker); ds->AddProfileTimelineMarker(marker);

Просмотреть файл

@ -4471,11 +4471,11 @@ static void DrawForcedBackgroundColor(DrawTarget& aDrawTarget,
} }
} }
class LayerTimelineMarker : public nsDocShell::TimelineMarker class LayerTimelineMarker : public TimelineMarker
{ {
public: public:
LayerTimelineMarker(nsDocShell* aDocShell, const nsIntRegion& aRegion) LayerTimelineMarker(nsDocShell* aDocShell, const nsIntRegion& aRegion)
: nsDocShell::TimelineMarker(aDocShell, "Layer", TRACING_EVENT) : TimelineMarker(aDocShell, "Layer", TRACING_EVENT)
, mRegion(aRegion) , mRegion(aRegion)
{ {
} }
@ -4653,7 +4653,7 @@ FrameLayerBuilder::DrawPaintedLayer(PaintedLayer* aLayer,
bool isRecording; bool isRecording;
docShell->GetRecordProfileTimelineMarkers(&isRecording); docShell->GetRecordProfileTimelineMarkers(&isRecording);
if (isRecording) { if (isRecording) {
mozilla::UniquePtr<nsDocShell::TimelineMarker> marker = mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<LayerTimelineMarker>(docShell, aRegionToDraw); MakeUnique<LayerTimelineMarker>(docShell, aRegionToDraw);
docShell->AddProfileTimelineMarker(marker); docShell->AddProfileTimelineMarker(marker);
} }