Bug 1194707 - Remove the docshell param from TimelineMarker constructors, r=tromey

This commit is contained in:
Victor Porof 2015-08-31 11:42:35 +02:00
Родитель fe93f04c90
Коммит 4ce24e2588
9 изменённых файлов: 146 добавлений и 106 удалений

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

@ -1601,7 +1601,7 @@ nsDocShell::LoadStream(nsIInputStream* aStream, nsIURI* aURI,
(void)aLoadInfo->GetLoadType(&lt);
// Get the appropriate LoadType from nsIDocShellLoadInfo type
loadType = ConvertDocShellLoadInfoToLoadType(lt);
nsCOMPtr<nsISupports> owner;
aLoadInfo->GetOwner(getter_AddRefs(owner));
requestingPrincipal = do_QueryInterface(owner);
@ -13766,14 +13766,13 @@ nsDocShell::GetOpener()
class JavascriptTimelineMarker : public TimelineMarker
{
public:
JavascriptTimelineMarker(nsDocShell* aDocShell, const char* aName,
const char* aReason,
const char16_t* aFunctionName,
const char16_t* aFileName,
uint32_t aLineNumber)
: TimelineMarker(aDocShell, aName, TRACING_INTERVAL_START,
NS_ConvertUTF8toUTF16(aReason),
NO_STACK)
explicit JavascriptTimelineMarker(const char* aName,
const char* aReason,
const char16_t* aFunctionName,
const char16_t* aFileName,
uint32_t aLineNumber)
: TimelineMarker(aName, NS_ConvertUTF8toUTF16(aReason),
TRACING_INTERVAL_START, NO_STACK)
, mFunctionName(aFunctionName)
, mFileName(aFileName)
, mLineNumber(aLineNumber)
@ -13819,7 +13818,7 @@ nsDocShell::NotifyJSRunToCompletionStart(const char* aReason,
// If first start, mark interval start.
if (timelineOn && mJSRunToCompletionDepth == 0) {
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<JavascriptTimelineMarker>(this, "Javascript", aReason,
MakeUnique<JavascriptTimelineMarker>("Javascript", aReason,
aFunctionName, aFilename,
aLineNumber);
TimelineConsumers::AddMarkerForDocShell(this, Move(marker));

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

@ -4,8 +4,8 @@
* 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 ObservedDocShell_h_
#define ObservedDocShell_h_
#ifndef mozilla_ObservedDocShell_h_
#define mozilla_ObservedDocShell_h_
#include "nsTArray.h"
#include "mozilla/nsRefPtr.h"
@ -39,4 +39,4 @@ public:
} // namespace mozilla
#endif /* ObservedDocShell_h_ */
#endif /* mozilla_ObservedDocShell_h_ */

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

@ -71,7 +71,7 @@ TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
TracingMetadata aMetaData)
{
if (aDocShell->IsObserved()) {
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aDocShell, aName, aMetaData)));
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aName, aMetaData)));
}
}
@ -82,7 +82,7 @@ TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
TracingMetadata aMetaData)
{
if (aDocShell->IsObserved()) {
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aDocShell, aName, aTime, aMetaData)));
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aName, aTime, aMetaData)));
}
}

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

@ -4,50 +4,94 @@
* 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 || aMetaData == TRACING_TIMESTAMP) {
CaptureStack();
}
}
using mozilla::TimeStamp;
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData)
: TimelineMarker(aDocShell, aName, aMetaData)
{
bool isInconsistent = false;
mTime = (aTime - mozilla::TimeStamp::ProcessCreation(isInconsistent)).ToMilliseconds();
}
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
TimelineMarker::TimelineMarker(const char* aName,
TracingMetadata aMetaData,
const nsAString& aCause,
TimelineStackRequest aStackRequest)
: mName(aName)
, mMetaData(aMetaData)
, mCause(aCause)
{
MOZ_COUNT_CTOR(TimelineMarker);
MOZ_ASSERT(aName);
aDocShell->Now(&mTime);
if ((aMetaData == TRACING_INTERVAL_START ||
aMetaData == TRACING_TIMESTAMP) &&
aStackRequest != NO_STACK) {
CaptureStack();
}
SetCurrentTime();
CaptureStackIfNecessary(aMetaData, aStackRequest);
}
TimelineMarker::TimelineMarker(const char* aName,
const TimeStamp& aTime,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest)
: mName(aName)
, mMetaData(aMetaData)
{
MOZ_COUNT_CTOR(TimelineMarker);
MOZ_ASSERT(aName);
SetCustomTime(aTime);
CaptureStackIfNecessary(aMetaData, aStackRequest);
}
TimelineMarker::TimelineMarker(const char* aName,
const nsAString& aCause,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest)
: mName(aName)
, mCause(aCause)
, mMetaData(aMetaData)
{
MOZ_COUNT_CTOR(TimelineMarker);
MOZ_ASSERT(aName);
SetCurrentTime();
CaptureStackIfNecessary(aMetaData, aStackRequest);
}
TimelineMarker::TimelineMarker(const char* aName,
const nsAString& aCause,
const TimeStamp& aTime,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest)
: mName(aName)
, mCause(aCause)
, mMetaData(aMetaData)
{
MOZ_COUNT_CTOR(TimelineMarker);
MOZ_ASSERT(aName);
SetCustomTime(aTime);
CaptureStackIfNecessary(aMetaData, aStackRequest);
}
TimelineMarker::~TimelineMarker()
{
MOZ_COUNT_DTOR(TimelineMarker);
}
void
TimelineMarker::SetCurrentTime()
{
TimeStamp now = TimeStamp::Now();
SetCustomTime(now);
}
void
TimelineMarker::SetCustomTime(const TimeStamp& aTime)
{
bool isInconsistent = false;
mTime = (aTime - TimeStamp::ProcessCreation(isInconsistent)).ToMilliseconds();
}
void
TimelineMarker::CaptureStackIfNecessary(TracingMetadata aMetaData,
TimelineStackRequest aStackRequest)
{
if ((aMetaData == TRACING_INTERVAL_START ||
aMetaData == TRACING_TIMESTAMP) &&
aStackRequest != NO_STACK) {
CaptureStack();
}
}

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

@ -8,54 +8,56 @@
#define TimelineMarker_h_
#include "nsString.h"
#include "GeckoProfiler.h"
#include "mozilla/dom/ProfileTimelineMarkerBinding.h"
#include "nsContentUtils.h"
#include "jsapi.h"
#include "GeckoProfiler.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.
// Objects of this type can be added to the timeline if there is an interested
// consumer. The class can also be subclassed to let a given marker creator
// provide custom details.
class TimelineMarker
{
public:
enum TimelineStackRequest { STACK, NO_STACK };
TimelineMarker(nsDocShell* aDocShell, const char* aName,
TracingMetadata aMetaData);
TimelineMarker(nsDocShell* aDocShell, const char* aName,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData);
TimelineMarker(nsDocShell* aDocShell, const char* aName,
TimelineMarker(const char* aName,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest = STACK);
TimelineMarker(const char* aName,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest = STACK);
TimelineMarker(const char* aName,
const nsAString& aCause,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest = STACK);
TimelineMarker(const char* aName,
const nsAString& aCause,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest = STACK);
virtual ~TimelineMarker();
// Check whether two markers should be considered the same,
// for the purpose of pairing start and end markers. Normally
// this definition suffices.
// 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& aOther)
{
return strcmp(mName, aOther.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(JSContext* aCx,
mozilla::dom::ProfileTimelineMarker& aMarker)
// 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(JSContext* aCx, mozilla::dom::ProfileTimelineMarker& aMarker)
{}
virtual void AddLayerRectangles(
mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
virtual void AddLayerRectangles(mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
{
MOZ_ASSERT_UNREACHABLE("can only be called on layer markers");
}
@ -89,15 +91,20 @@ protected:
private:
const char* mName;
TracingMetadata mMetaData;
DOMHighResTimeStamp mTime;
nsString mCause;
DOMHighResTimeStamp mTime;
TracingMetadata mMetaData;
// 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, and the markers are only held
// here temporarily to boot.
JS::PersistentRooted<JSObject*> mStackTrace;
void SetCurrentTime();
void SetCustomTime(const mozilla::TimeStamp& aTime);
void CaptureStackIfNecessary(TracingMetadata aMetaData,
TimelineStackRequest aStackRequest);
};
#endif /* TimelineMarker_h_ */

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

@ -988,10 +988,9 @@ ReifyStack(nsIStackFrame* aStack, nsTArray<ConsoleStackEntry>& aRefiedStack)
class ConsoleTimelineMarker : public TimelineMarker
{
public:
ConsoleTimelineMarker(nsDocShell* aDocShell,
TracingMetadata aMetaData,
const nsAString& aCause)
: TimelineMarker(aDocShell, "ConsoleTime", aMetaData, aCause)
explicit ConsoleTimelineMarker(const nsAString& aCause,
TracingMetadata aMetaData)
: TimelineMarker("ConsoleTime", aCause, aMetaData)
{
if (aMetaData == TRACING_INTERVAL_END) {
CaptureStack();
@ -1021,12 +1020,9 @@ public:
class TimestampTimelineMarker : public TimelineMarker
{
public:
TimestampTimelineMarker(nsDocShell* aDocShell,
TracingMetadata aMetaData,
const nsAString& aCause)
: TimelineMarker(aDocShell, "TimeStamp", aMetaData, aCause)
explicit TimestampTimelineMarker(const nsAString& aCause)
: TimelineMarker("TimeStamp", aCause, TRACING_TIMESTAMP)
{
MOZ_ASSERT(aMetaData == TRACING_TIMESTAMP);
}
virtual void AddDetails(JSContext* aCx,
@ -1145,7 +1141,7 @@ Console::Method(JSContext* aCx, MethodName aMethodName,
}
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<TimestampTimelineMarker>(docShell, TRACING_TIMESTAMP, key);
MakeUnique<TimestampTimelineMarker>(key);
TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
}
// For `console.time(foo)` and `console.timeEnd(foo)`
@ -1156,9 +1152,8 @@ Console::Method(JSContext* aCx, MethodName aMethodName,
nsAutoJSString key;
if (key.init(aCx, jsString)) {
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<ConsoleTimelineMarker>(docShell,
aMethodName == MethodTime ? TRACING_INTERVAL_START : TRACING_INTERVAL_END,
key);
MakeUnique<ConsoleTimelineMarker>(key,
aMethodName == MethodTime ? TRACING_INTERVAL_START : TRACING_INTERVAL_END);
TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
}
}

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

@ -1059,9 +1059,9 @@ EventListenerManager::GetDocShellForTarget()
class EventTimelineMarker : public TimelineMarker
{
public:
EventTimelineMarker(nsDocShell* aDocShell, TracingMetadata aMetaData,
uint16_t aPhase, const nsAString& aCause)
: TimelineMarker(aDocShell, "DOMEvent", aMetaData, aCause)
explicit EventTimelineMarker(TracingMetadata aMetaData,
uint16_t aPhase, const nsAString& aCause)
: TimelineMarker("DOMEvent", aCause, aMetaData)
, mPhase(aPhase)
{
}
@ -1150,7 +1150,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
uint16_t phase;
(*aDOMEvent)->GetEventPhase(&phase);
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<EventTimelineMarker>(ds, TRACING_INTERVAL_START,
MakeUnique<EventTimelineMarker>(TRACING_INTERVAL_START,
phase, typeStr);
TimelineConsumers::AddMarkerForDocShell(ds, Move(marker));
}

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

@ -5500,8 +5500,8 @@ static void DrawForcedBackgroundColor(DrawTarget& aDrawTarget,
class LayerTimelineMarker : public TimelineMarker
{
public:
LayerTimelineMarker(nsDocShell* aDocShell, const nsIntRegion& aRegion)
: TimelineMarker(aDocShell, "Layer", TRACING_EVENT)
explicit LayerTimelineMarker(const nsIntRegion& aRegion)
: TimelineMarker("Layer", TRACING_EVENT)
, mRegion(aRegion)
{
}
@ -5688,7 +5688,7 @@ FrameLayerBuilder::DrawPaintedLayer(PaintedLayer* aLayer,
docShell->GetRecordProfileTimelineMarkers(&isRecording);
if (isRecording) {
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<LayerTimelineMarker>(docShell, aRegionToDraw);
MakeUnique<LayerTimelineMarker>(aRegionToDraw);
TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
}
}

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

@ -100,10 +100,9 @@ struct RestyleCollector {
class RestyleTimelineMarker : public TimelineMarker
{
public:
RestyleTimelineMarker(nsDocShell* aDocShell,
TracingMetadata aMetaData,
nsRestyleHint aRestyleHint)
: TimelineMarker(aDocShell, "Styles", aMetaData)
explicit RestyleTimelineMarker(TracingMetadata aMetaData,
nsRestyleHint aRestyleHint)
: TimelineMarker("Styles", aMetaData)
{
if (aRestyleHint) {
mRestyleHint.AssignWithConversion(RestyleManager::RestyleHintToString(aRestyleHint));
@ -359,8 +358,7 @@ RestyleTracker::DoProcessRestyles()
if (isTimelineRecording) {
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<RestyleTimelineMarker>(docShell,
TRACING_INTERVAL_START,
MakeUnique<RestyleTimelineMarker>(TRACING_INTERVAL_START,
data->mRestyleHint);
TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
}
@ -377,8 +375,7 @@ RestyleTracker::DoProcessRestyles()
if (isTimelineRecording) {
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<RestyleTimelineMarker>(docShell,
TRACING_INTERVAL_END,
MakeUnique<RestyleTimelineMarker>(TRACING_INTERVAL_END,
data->mRestyleHint);
TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
}
@ -424,8 +421,7 @@ RestyleTracker::DoProcessRestyles()
#endif
if (isTimelineRecording) {
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<RestyleTimelineMarker>(docShell,
TRACING_INTERVAL_START,
MakeUnique<RestyleTimelineMarker>(TRACING_INTERVAL_START,
currentRestyle->mRestyleHint);
TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
}
@ -437,8 +433,7 @@ RestyleTracker::DoProcessRestyles()
if (isTimelineRecording) {
mozilla::UniquePtr<TimelineMarker> marker =
MakeUnique<RestyleTimelineMarker>(docShell,
TRACING_INTERVAL_END,
MakeUnique<RestyleTimelineMarker>(TRACING_INTERVAL_END,
currentRestyle->mRestyleHint);
TimelineConsumers::AddMarkerForDocShell(docShell, Move(marker));
}