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
parent eafcdc60fb
commit 9c93c0380d
9 changed files with 146 additions and 106 deletions

View File

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

View File

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ObservedDocShell_h_ #ifndef mozilla_ObservedDocShell_h_
#define ObservedDocShell_h_ #define mozilla_ObservedDocShell_h_
#include "nsTArray.h" #include "nsTArray.h"
#include "mozilla/nsRefPtr.h" #include "mozilla/nsRefPtr.h"
@ -39,4 +39,4 @@ public:
} // namespace mozilla } // namespace mozilla
#endif /* ObservedDocShell_h_ */ #endif /* mozilla_ObservedDocShell_h_ */

View File

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

View File

@ -4,50 +4,94 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDocShell.h"
#include "TimelineMarker.h" #include "TimelineMarker.h"
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName, using mozilla::TimeStamp;
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();
}
}
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName, TimelineMarker::TimelineMarker(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,
TracingMetadata aMetaData, TracingMetadata aMetaData,
const nsAString& aCause,
TimelineStackRequest aStackRequest) TimelineStackRequest aStackRequest)
: mName(aName) : mName(aName)
, mMetaData(aMetaData) , mMetaData(aMetaData)
, mCause(aCause)
{ {
MOZ_COUNT_CTOR(TimelineMarker); MOZ_COUNT_CTOR(TimelineMarker);
MOZ_ASSERT(aName); MOZ_ASSERT(aName);
aDocShell->Now(&mTime);
if ((aMetaData == TRACING_INTERVAL_START || SetCurrentTime();
aMetaData == TRACING_TIMESTAMP) && CaptureStackIfNecessary(aMetaData, aStackRequest);
aStackRequest != NO_STACK) { }
CaptureStack();
} 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() TimelineMarker::~TimelineMarker()
{ {
MOZ_COUNT_DTOR(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();
}
}

View File

@ -8,54 +8,56 @@
#define TimelineMarker_h_ #define TimelineMarker_h_
#include "nsString.h" #include "nsString.h"
#include "GeckoProfiler.h"
#include "mozilla/dom/ProfileTimelineMarkerBinding.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "jsapi.h" #include "GeckoProfiler.h"
class nsDocShell; class nsDocShell;
// Objects of this type can be added to the timeline. The class can // Objects of this type can be added to the timeline if there is an interested
// also be subclassed to let a given marker creator provide custom // consumer. The class can also be subclassed to let a given marker creator
// details. // provide custom details.
class TimelineMarker class TimelineMarker
{ {
public: public:
enum TimelineStackRequest { STACK, NO_STACK }; enum TimelineStackRequest { STACK, NO_STACK };
TimelineMarker(nsDocShell* aDocShell, const char* aName, TimelineMarker(const char* aName,
TracingMetadata aMetaData);
TimelineMarker(nsDocShell* aDocShell, const char* aName,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData);
TimelineMarker(nsDocShell* aDocShell, const char* aName,
TracingMetadata aMetaData, 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, const nsAString& aCause,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest = STACK);
TimelineMarker(const char* aName,
const nsAString& aCause,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData,
TimelineStackRequest aStackRequest = STACK); TimelineStackRequest aStackRequest = STACK);
virtual ~TimelineMarker(); virtual ~TimelineMarker();
// Check whether two markers should be considered the same, // Check whether two markers should be considered the same, for the purpose
// for the purpose of pairing start and end markers. Normally // of pairing start and end markers. Normally this definition suffices.
// this definition suffices.
virtual bool Equals(const TimelineMarker& aOther) virtual bool Equals(const TimelineMarker& aOther)
{ {
return strcmp(mName, aOther.mName) == 0; return strcmp(mName, aOther.mName) == 0;
} }
// Add details specific to this marker type to aMarker. The // Add details specific to this marker type to aMarker. The standard elements
// standard elements have already been set. This method is // have already been set. This method is called on both the starting and
// called on both the starting and ending markers of a pair. // ending markers of a pair. Ordinarily the ending marker doesn't need to do
// Ordinarily the ending marker doesn't need to do anything // anything here.
// here. virtual void AddDetails(JSContext* aCx, mozilla::dom::ProfileTimelineMarker& aMarker)
virtual void AddDetails(JSContext* aCx,
mozilla::dom::ProfileTimelineMarker& aMarker)
{} {}
virtual void AddLayerRectangles( virtual void AddLayerRectangles(mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
mozilla::dom::Sequence<mozilla::dom::ProfileTimelineLayerRect>&)
{ {
MOZ_ASSERT_UNREACHABLE("can only be called on layer markers"); MOZ_ASSERT_UNREACHABLE("can only be called on layer markers");
} }
@ -89,15 +91,20 @@ protected:
private: private:
const char* mName; const char* mName;
TracingMetadata mMetaData;
DOMHighResTimeStamp mTime;
nsString mCause; nsString mCause;
DOMHighResTimeStamp mTime;
TracingMetadata mMetaData;
// While normally it is not a good idea to make a persistent root, // While normally it is not a good idea to make a persistent root,
// in this case changing nsDocShell to participate in cycle // in this case changing nsDocShell to participate in cycle
// collection was deemed too invasive, and the markers are only held // collection was deemed too invasive, and the markers are only held
// here temporarily to boot. // here temporarily to boot.
JS::PersistentRooted<JSObject*> mStackTrace; JS::PersistentRooted<JSObject*> mStackTrace;
void SetCurrentTime();
void SetCustomTime(const mozilla::TimeStamp& aTime);
void CaptureStackIfNecessary(TracingMetadata aMetaData,
TimelineStackRequest aStackRequest);
}; };
#endif /* TimelineMarker_h_ */ #endif /* TimelineMarker_h_ */

View File

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

View File

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

View File

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

View File

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