From bdb4ff581677ad1cd411b55a68c87534f9a64882 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 22 Apr 2018 04:25:34 +0200 Subject: moebius#157: The Performance Observer (improvements) https://github.com/MoonchildProductions/moebius/pull/157 --- dom/performance/Performance.cpp | 21 ------ dom/performance/PerformanceEntry.h | 21 ++++++ dom/performance/PerformanceObserver.cpp | 14 +++- dom/performance/PerformanceObserverEntryList.cpp | 15 ++++- dom/performance/tests/mochitest.ini | 2 - dom/performance/tests/performance_observer.html | 74 ---------------------- .../tests/test_performance_observer.html | 52 +++++++++++++-- dom/performance/tests/test_worker_observer.html | 13 ++-- .../tests/worker_performance_observer.html | 32 ---------- 9 files changed, 100 insertions(+), 144 deletions(-) delete mode 100644 dom/performance/tests/performance_observer.html delete mode 100644 dom/performance/tests/worker_performance_observer.html (limited to 'dom/performance') diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 8dc239b05..497bdea27 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -38,27 +38,6 @@ using namespace workers; namespace { -// Helper classes -class MOZ_STACK_CLASS PerformanceEntryComparator final -{ -public: - bool Equals(const PerformanceEntry* aElem1, - const PerformanceEntry* aElem2) const - { - MOZ_ASSERT(aElem1 && aElem2, - "Trying to compare null performance entries"); - return aElem1->StartTime() == aElem2->StartTime(); - } - - bool LessThan(const PerformanceEntry* aElem1, - const PerformanceEntry* aElem2) const - { - MOZ_ASSERT(aElem1 && aElem2, - "Trying to compare null performance entries"); - return aElem1->StartTime() < aElem2->StartTime(); - } -}; - class PrefEnabledRunnable final : public WorkerCheckAPIExposureOnMainThreadRunnable { diff --git a/dom/performance/PerformanceEntry.h b/dom/performance/PerformanceEntry.h index bc4f84f1c..0af9f669e 100644 --- a/dom/performance/PerformanceEntry.h +++ b/dom/performance/PerformanceEntry.h @@ -90,6 +90,27 @@ protected: nsString mEntryType; }; +// Helper classes +class MOZ_STACK_CLASS PerformanceEntryComparator final +{ +public: + bool Equals(const PerformanceEntry* aElem1, + const PerformanceEntry* aElem2) const + { + MOZ_ASSERT(aElem1 && aElem2, + "Trying to compare null performance entries"); + return aElem1->StartTime() == aElem2->StartTime(); + } + + bool LessThan(const PerformanceEntry* aElem1, + const PerformanceEntry* aElem2) const + { + MOZ_ASSERT(aElem1 && aElem2, + "Trying to compare null performance entries"); + return aElem1->StartTime() < aElem2->StartTime(); + } +}; + } // namespace dom } // namespace mozilla diff --git a/dom/performance/PerformanceObserver.cpp b/dom/performance/PerformanceObserver.cpp index 11dd30ac2..d02acfb09 100644 --- a/dom/performance/PerformanceObserver.cpp +++ b/dom/performance/PerformanceObserver.cpp @@ -114,12 +114,13 @@ PerformanceObserver::Notify() RefPtr list = new PerformanceObserverEntryList(this, mQueuedEntries); + mQueuedEntries.Clear(); + ErrorResult rv; mCallback->Call(this, *list, *this, rv); if (NS_WARN_IF(rv.Failed())) { rv.SuppressException(); } - mQueuedEntries.Clear(); } void @@ -170,6 +171,17 @@ PerformanceObserver::Observe(const PerformanceObserverInit& aOptions, mEntryTypes.SwapElements(validEntryTypes); mPerformance->AddObserver(this); + + if (aOptions.mBuffered) { + for (auto entryType : mEntryTypes) { + nsTArray> existingEntries; + mPerformance->GetEntriesByType(entryType, existingEntries); + if (!existingEntries.IsEmpty()) { + mQueuedEntries.AppendElements(existingEntries); + } + } + } + mConnected = true; } diff --git a/dom/performance/PerformanceObserverEntryList.cpp b/dom/performance/PerformanceObserverEntryList.cpp index 349103f08..20e818f3d 100644 --- a/dom/performance/PerformanceObserverEntryList.cpp +++ b/dom/performance/PerformanceObserverEntryList.cpp @@ -66,6 +66,7 @@ PerformanceObserverEntryList::GetEntries( aRetval.AppendElement(entry); } + aRetval.Sort(PerformanceEntryComparator()); } void @@ -79,6 +80,7 @@ PerformanceObserverEntryList::GetEntriesByType( aRetval.AppendElement(entry); } } + aRetval.Sort(PerformanceEntryComparator()); } void @@ -88,9 +90,18 @@ PerformanceObserverEntryList::GetEntriesByName( nsTArray>& aRetval) { aRetval.Clear(); + const bool typePassed = aEntryType.WasPassed(); for (const RefPtr& entry : mEntries) { - if (entry->GetName().Equals(aName)) { - aRetval.AppendElement(entry); + if (!entry->GetName().Equals(aName)) { + continue; } + + if (typePassed && + !entry->GetEntryType().Equals(aEntryType.Value())) { + continue; + } + + aRetval.AppendElement(entry); } + aRetval.Sort(PerformanceEntryComparator()); } diff --git a/dom/performance/tests/mochitest.ini b/dom/performance/tests/mochitest.ini index 18f7f0e45..7005637e1 100644 --- a/dom/performance/tests/mochitest.ini +++ b/dom/performance/tests/mochitest.ini @@ -1,13 +1,11 @@ [DEFAULT] support-files = - performance_observer.html test_performance_observer.js test_performance_user_timing.js test_worker_performance_now.js worker_performance_user_timing.js worker_performance_observer.js sharedworker_performance_user_timing.js - worker_performance_observer.html [test_performance_observer.html] [test_performance_user_timing.html] diff --git a/dom/performance/tests/performance_observer.html b/dom/performance/tests/performance_observer.html deleted file mode 100644 index b8ced9296..000000000 --- a/dom/performance/tests/performance_observer.html +++ /dev/null @@ -1,74 +0,0 @@ - - - - - -Test for performance observer - - - - -
- - diff --git a/dom/performance/tests/test_performance_observer.html b/dom/performance/tests/test_performance_observer.html index d36878315..7df881bd4 100644 --- a/dom/performance/tests/test_performance_observer.html +++ b/dom/performance/tests/test_performance_observer.html @@ -3,15 +3,55 @@ http://creativecommons.org/publicdomain/zero/1.0/ --> + + Test for performance observer -
+ + +
+ + diff --git a/dom/performance/tests/test_worker_observer.html b/dom/performance/tests/test_worker_observer.html index b9ed0c964..9a55ef1d5 100644 --- a/dom/performance/tests/test_worker_observer.html +++ b/dom/performance/tests/test_worker_observer.html @@ -3,15 +3,16 @@ http://creativecommons.org/publicdomain/zero/1.0/ --> + + Test for performance observer in worker -
+ + +
+ diff --git a/dom/performance/tests/worker_performance_observer.html b/dom/performance/tests/worker_performance_observer.html deleted file mode 100644 index 613762f52..000000000 --- a/dom/performance/tests/worker_performance_observer.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - -Test for performance observer in worker - - -
- - -- cgit v1.2.3 From e040ed925030f899f845d458c226f7e439f4ec8b Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 11:49:50 +0200 Subject: moebius#158: The Performance Resource Timing (added support for "workerStart") https://github.com/MoonchildProductions/moebius/pull/158 --- dom/performance/PerformanceResourceTiming.cpp | 18 ++++++- dom/performance/PerformanceResourceTiming.h | 6 +++ dom/performance/PerformanceTiming.cpp | 71 ++++++++++++++++++++------- dom/performance/PerformanceTiming.h | 10 +++- 4 files changed, 82 insertions(+), 23 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/PerformanceResourceTiming.cpp b/dom/performance/PerformanceResourceTiming.cpp index 60a20ca28..94df27408 100644 --- a/dom/performance/PerformanceResourceTiming.cpp +++ b/dom/performance/PerformanceResourceTiming.cpp @@ -42,8 +42,22 @@ PerformanceResourceTiming::~PerformanceResourceTiming() DOMHighResTimeStamp PerformanceResourceTiming::StartTime() const { - DOMHighResTimeStamp startTime = mTiming->RedirectStartHighRes(); - return startTime ? startTime : mTiming->FetchStartHighRes(); + // Force the start time to be the earliest of: + // - RedirectStart + // - WorkerStart + // - AsyncOpen + // Ignore zero values. The RedirectStart and WorkerStart values + // can come from earlier redirected channels prior to the AsyncOpen + // time being recorded. + DOMHighResTimeStamp redirect = mTiming->RedirectStartHighRes(); + redirect = redirect ? redirect : DBL_MAX; + + DOMHighResTimeStamp worker = mTiming->WorkerStartHighRes(); + worker = worker ? worker : DBL_MAX; + + DOMHighResTimeStamp asyncOpen = mTiming->AsyncOpenHighRes(); + + return std::min(asyncOpen, std::min(redirect, worker)); } JSObject* diff --git a/dom/performance/PerformanceResourceTiming.h b/dom/performance/PerformanceResourceTiming.h index 2dd6b4a06..c2e6c0972 100644 --- a/dom/performance/PerformanceResourceTiming.h +++ b/dom/performance/PerformanceResourceTiming.h @@ -62,6 +62,12 @@ public: mNextHopProtocol = aNextHopProtocol; } + DOMHighResTimeStamp WorkerStart() const { + return mTiming && mTiming->TimingAllowed() + ? mTiming->WorkerStartHighRes() + : 0; + } + DOMHighResTimeStamp FetchStart() const { return mTiming ? mTiming->FetchStartHighRes() diff --git a/dom/performance/PerformanceTiming.cpp b/dom/performance/PerformanceTiming.cpp index e2f76a21f..887a23938 100755 --- a/dom/performance/PerformanceTiming.cpp +++ b/dom/performance/PerformanceTiming.cpp @@ -73,6 +73,7 @@ PerformanceTiming::InitializeTimingInfo(nsITimedChannel* aChannel) { if (aChannel) { aChannel->GetAsyncOpen(&mAsyncOpen); + aChannel->GetDispatchFetchEventStart(&mWorkerStart); aChannel->GetAllRedirectsSameOrigin(&mAllRedirectsSameOrigin); aChannel->GetRedirectCount(&mRedirectCount); aChannel->GetRedirectStart(&mRedirectStart); @@ -88,31 +89,39 @@ PerformanceTiming::InitializeTimingInfo(nsITimedChannel* aChannel) aChannel->GetResponseEnd(&mResponseEnd); aChannel->GetCacheReadEnd(&mCacheReadEnd); - // the performance timing api essentially requires that the event timestamps - // are >= asyncOpen().. but in truth the browser engages in a number of - // speculative activities that sometimes mean connections and lookups begin - // earlier. Workaround that here by just using asyncOpen as the minimum - // timestamp for dns and connection info. + // The performance timing api essentially requires that the event timestamps + // have a strict relation with each other. The truth, however, is the browser + // engages in a number of speculative activities that sometimes mean connections + // and lookups begin at different times. Workaround that here by clamping + // these values to what we expect FetchStart to be. This means the later of + // AsyncOpen or WorkerStart times. if (!mAsyncOpen.IsNull()) { - if (!mDomainLookupStart.IsNull() && mDomainLookupStart < mAsyncOpen) { - mDomainLookupStart = mAsyncOpen; + // We want to clamp to the expected FetchStart value. This is later of + // the AsyncOpen and WorkerStart values. + const TimeStamp* clampTime = &mAsyncOpen; + if (!mWorkerStart.IsNull() && mWorkerStart > mAsyncOpen) { + clampTime = &mWorkerStart; } - if (!mDomainLookupEnd.IsNull() && mDomainLookupEnd < mAsyncOpen) { - mDomainLookupEnd = mAsyncOpen; + if (!mDomainLookupStart.IsNull() && mDomainLookupStart < *clampTime) { + mDomainLookupStart = *clampTime; } - if (!mConnectStart.IsNull() && mConnectStart < mAsyncOpen) { - mConnectStart = mAsyncOpen; + if (!mDomainLookupEnd.IsNull() && mDomainLookupEnd < *clampTime) { + mDomainLookupEnd = *clampTime; + } + + if (!mConnectStart.IsNull() && mConnectStart < *clampTime) { + mConnectStart = *clampTime; } if (mSecureConnection && !mSecureConnectionStart.IsNull() && - mSecureConnectionStart < mAsyncOpen) { - mSecureConnectionStart = mAsyncOpen; + mSecureConnectionStart < *clampTime) { + mSecureConnectionStart = *clampTime; } - if (!mConnectEnd.IsNull() && mConnectEnd < mAsyncOpen) { - mConnectEnd = mAsyncOpen; + if (!mConnectEnd.IsNull() && mConnectEnd < *clampTime) { + mConnectEnd = *clampTime; } } } @@ -131,9 +140,13 @@ PerformanceTiming::FetchStartHighRes() } MOZ_ASSERT(!mAsyncOpen.IsNull(), "The fetch start time stamp should always be " "valid if the performance timing is enabled"); - mFetchStart = (!mAsyncOpen.IsNull()) - ? TimeStampToDOMHighRes(mAsyncOpen) - : 0.0; + if (!mAsyncOpen.IsNull()) { + if (!mWorkerStart.IsNull() && mWorkerStart > mAsyncOpen) { + mFetchStart = TimeStampToDOMHighRes(mWorkerStart); + } else { + mFetchStart = TimeStampToDOMHighRes(mAsyncOpen); + } + } } return TimerClamping::ReduceMsTimeValue(mFetchStart); } @@ -180,7 +193,7 @@ PerformanceTiming::TimingAllowed() const return mTimingAllowed; } -uint16_t +uint8_t PerformanceTiming::GetRedirectCount() const { if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized()) { @@ -205,6 +218,26 @@ PerformanceTiming::ShouldReportCrossOriginRedirect() const return (mRedirectCount != 0) && mReportCrossOriginRedirect; } +DOMHighResTimeStamp +PerformanceTiming::AsyncOpenHighRes() +{ + if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized() || + mAsyncOpen.IsNull()) { + return mZeroTime; + } + return TimeStampToReducedDOMHighResOrFetchStart(mAsyncOpen); +} + +DOMHighResTimeStamp +PerformanceTiming::WorkerStartHighRes() +{ + if (!nsContentUtils::IsPerformanceTimingEnabled() || !IsInitialized() || + mWorkerStart.IsNull()) { + return mZeroTime; + } + return TimeStampToReducedDOMHighResOrFetchStart(mWorkerStart); +} + /** * RedirectStartHighRes() is used by both the navigation timing and the * resource timing. Since, navigation timing and resource timing check and diff --git a/dom/performance/PerformanceTiming.h b/dom/performance/PerformanceTiming.h index fc7e7d5bd..584ae0816 100755 --- a/dom/performance/PerformanceTiming.h +++ b/dom/performance/PerformanceTiming.h @@ -139,7 +139,7 @@ public: return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetUnloadEventEnd()); } - uint16_t GetRedirectCount() const; + uint8_t GetRedirectCount() const; // Checks if the resource is either same origin as the page that started // the load, or if the response contains the Timing-Allow-Origin header @@ -155,7 +155,12 @@ public: // the timing-allow-origin check in HttpBaseChannel::TimingAllowCheck bool ShouldReportCrossOriginRedirect() const; + // The last channel's AsyncOpen time. This may occur before the FetchStart + // in some cases. + DOMHighResTimeStamp AsyncOpenHighRes(); + // High resolution (used by resource timing) + DOMHighResTimeStamp WorkerStartHighRes(); DOMHighResTimeStamp FetchStartHighRes(); DOMHighResTimeStamp RedirectStartHighRes(); DOMHighResTimeStamp RedirectEndHighRes(); @@ -253,6 +258,7 @@ private: DOMHighResTimeStamp mZeroTime; TimeStamp mAsyncOpen; + TimeStamp mWorkerStart; TimeStamp mRedirectStart; TimeStamp mRedirectEnd; TimeStamp mDomainLookupStart; @@ -265,7 +271,7 @@ private: TimeStamp mCacheReadStart; TimeStamp mResponseEnd; TimeStamp mCacheReadEnd; - uint16_t mRedirectCount; + uint8_t mRedirectCount; bool mTimingAllowed; bool mAllRedirectsSameOrigin; bool mInitialized; -- cgit v1.2.3 From de9560af3e0e0d0dc93c5401c9b6ca2f0a173e36 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 11:59:22 +0200 Subject: Bug 1317297 - nextHopProtocol is an empty string for local fetch https://hg.mozilla.org/mozilla-central/rev/9e5cd2bf4d66 --- dom/performance/PerformanceMainThread.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'dom/performance') diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index 86d42c5f8..fa03408c6 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -6,6 +6,7 @@ #include "PerformanceMainThread.h" #include "PerformanceNavigation.h" +#include "nsICacheInfoChannel.h" namespace mozilla { namespace dom { @@ -165,6 +166,17 @@ PerformanceMainThread::AddEntry(nsIHttpChannel* channel, nsAutoCString protocol; channel->GetProtocolVersion(protocol); + + // If this is a local fetch, nextHopProtocol should be set to empty string. + nsCOMPtr cachedChannel = do_QueryInterface(channel); + if (cachedChannel) { + bool isFromCache; + if (NS_SUCCEEDED(cachedChannel->IsFromCache(&isFromCache)) + && isFromCache) { + protocol.Truncate(); + } + } + performanceEntry->SetNextHopProtocol(NS_ConvertUTF8toUTF16(protocol)); uint64_t encodedBodySize = 0; -- cgit v1.2.3 From 7ee501103ad2efe1d28ef3c10b4111a685746c06 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:07:20 +0200 Subject: Bug 1322966 - Cleanup performance.cpp https://hg.mozilla.org/mozilla-central/rev/0ad76084c4c3 --- dom/performance/Performance.cpp | 6 ++---- dom/performance/Performance.h | 5 +---- dom/performance/PerformanceMainThread.cpp | 10 +++------- dom/performance/PerformanceMainThread.h | 9 +-------- dom/performance/PerformanceWorker.h | 6 ------ 5 files changed, 7 insertions(+), 29 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 497bdea27..074bffe8a 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -82,14 +82,12 @@ NS_IMPL_RELEASE_INHERITED(Performance, DOMEventTargetHelper) /* static */ already_AddRefed Performance::CreateForMainThread(nsPIDOMWindowInner* aWindow, nsDOMNavigationTiming* aDOMTiming, - nsITimedChannel* aChannel, - Performance* aParentPerformance) + nsITimedChannel* aChannel) { MOZ_ASSERT(NS_IsMainThread()); RefPtr performance = - new PerformanceMainThread(aWindow, aDOMTiming, aChannel, - aParentPerformance); + new PerformanceMainThread(aWindow, aDOMTiming, aChannel); return performance.forget(); } diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index bc70589a5..6a374c7f0 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -45,8 +45,7 @@ public: static already_AddRefed CreateForMainThread(nsPIDOMWindowInner* aWindow, nsDOMNavigationTiming* aDOMTiming, - nsITimedChannel* aChannel, - Performance* aParentPerformance); + nsITimedChannel* aChannel); static already_AddRefed CreateForWorker(workers::WorkerPrivate* aWorkerPrivate); @@ -101,8 +100,6 @@ public: virtual nsITimedChannel* GetChannel() const = 0; - virtual Performance* GetParentPerformance() const = 0; - protected: Performance(); explicit Performance(nsPIDOMWindowInner* aWindow); diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index fa03408c6..d67c0c906 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -16,8 +16,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceMainThread) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PerformanceMainThread, Performance) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTiming, - mNavigation, - mParentPerformance) + mNavigation) tmp->mMozMemory = nullptr; mozilla::DropJSObjects(this); NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -25,8 +24,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PerformanceMainThread, Performance) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTiming, - mNavigation, - mParentPerformance) + mNavigation) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -46,12 +44,10 @@ NS_INTERFACE_MAP_END_INHERITING(Performance) PerformanceMainThread::PerformanceMainThread(nsPIDOMWindowInner* aWindow, nsDOMNavigationTiming* aDOMTiming, - nsITimedChannel* aChannel, - Performance* aParentPerformance) + nsITimedChannel* aChannel) : Performance(aWindow) , mDOMTiming(aDOMTiming) , mChannel(aChannel) - , mParentPerformance(aParentPerformance) { MOZ_ASSERT(aWindow, "Parent window object should be provided"); } diff --git a/dom/performance/PerformanceMainThread.h b/dom/performance/PerformanceMainThread.h index 84773f29b..fcaa6b903 100644 --- a/dom/performance/PerformanceMainThread.h +++ b/dom/performance/PerformanceMainThread.h @@ -17,8 +17,7 @@ class PerformanceMainThread final : public Performance public: PerformanceMainThread(nsPIDOMWindowInner* aWindow, nsDOMNavigationTiming* aDOMTiming, - nsITimedChannel* aChannel, - Performance* aParentPerformance); + nsITimedChannel* aChannel); NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PerformanceMainThread, @@ -51,11 +50,6 @@ public: return mChannel; } - virtual Performance* GetParentPerformance() const override - { - return mParentPerformance; - } - protected: ~PerformanceMainThread(); @@ -77,7 +71,6 @@ protected: nsCOMPtr mChannel; RefPtr mTiming; RefPtr mNavigation; - RefPtr mParentPerformance; JS::Heap mMozMemory; }; diff --git a/dom/performance/PerformanceWorker.h b/dom/performance/PerformanceWorker.h index 7eef0d974..d8635e98a 100644 --- a/dom/performance/PerformanceWorker.h +++ b/dom/performance/PerformanceWorker.h @@ -64,12 +64,6 @@ public: return nullptr; } - virtual Performance* GetParentPerformance() const override - { - MOZ_CRASH("This should not be called on workers."); - return nullptr; - } - protected: ~PerformanceWorker(); -- cgit v1.2.3 From 39d4a11267fd707df04bb06a74e24f36e2dbcd28 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:11:55 +0200 Subject: Bug 1323941 - navigationStart should not be exposed to workers as timing attribute https://hg.mozilla.org/mozilla-central/rev/6be7eb833b11 --- dom/performance/Performance.h | 10 ++++++++-- dom/performance/PerformanceWorker.cpp | 23 ---------------------- dom/performance/PerformanceWorker.h | 5 ----- .../tests/test_performance_user_timing.js | 21 +++++++++++--------- 4 files changed, 20 insertions(+), 39 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index 6a374c7f0..04dd76bc7 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -123,10 +123,16 @@ protected: virtual DOMHighResTimeStamp CreationTime() const = 0; - virtual bool IsPerformanceTimingAttribute(const nsAString& aName) = 0; + virtual bool IsPerformanceTimingAttribute(const nsAString& aName) + { + return false; + } virtual DOMHighResTimeStamp - GetPerformanceTimingFromString(const nsAString& aTimingName) = 0; + GetPerformanceTimingFromString(const nsAString& aTimingName) + { + return 0; + } bool IsResourceEntryLimitReached() const { diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp index 85ca2ccd8..db9d6aa6e 100644 --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -31,29 +31,6 @@ PerformanceWorker::Now() const return RoundTime(duration.ToMilliseconds()); } -// To be removed once bug 1124165 lands -bool -PerformanceWorker::IsPerformanceTimingAttribute(const nsAString& aName) -{ - // In workers we just support navigationStart. - return aName.EqualsASCII("navigationStart"); -} - -DOMHighResTimeStamp -PerformanceWorker::GetPerformanceTimingFromString(const nsAString& aProperty) -{ - if (!IsPerformanceTimingAttribute(aProperty)) { - return 0; - } - - if (aProperty.EqualsLiteral("navigationStart")) { - return mWorkerPrivate->NowBaseTime(); - } - - MOZ_CRASH("IsPerformanceTimingAttribute and GetPerformanceTimingFromString are out of sync"); - return 0; -} - void PerformanceWorker::InsertUserEntry(PerformanceEntry* aEntry) { diff --git a/dom/performance/PerformanceWorker.h b/dom/performance/PerformanceWorker.h index d8635e98a..89bfea3ed 100644 --- a/dom/performance/PerformanceWorker.h +++ b/dom/performance/PerformanceWorker.h @@ -74,11 +74,6 @@ protected: void InsertUserEntry(PerformanceEntry* aEntry) override; - bool IsPerformanceTimingAttribute(const nsAString& aName) override; - - DOMHighResTimeStamp - GetPerformanceTimingFromString(const nsAString& aTimingName) override; - void DispatchBufferFullEvent() override { MOZ_CRASH("This should not be called on workers."); diff --git a/dom/performance/tests/test_performance_user_timing.js b/dom/performance/tests/test_performance_user_timing.js index cd8261bbd..a15dbebb6 100644 --- a/dom/performance/tests/test_performance_user_timing.js +++ b/dom/performance/tests/test_performance_user_timing.js @@ -126,15 +126,18 @@ var steps = [ }, // Test measure function () { - ok(true, "Running measure addition with no start/end time test"); - performance.measure("test"); - var measures = performance.getEntriesByType("measure"); - is(measures.length, 1, "number of measures should be 1"); - var measure = measures[0]; - is(measure.name, "test", "measure name should be 'test'"); - is(measure.entryType, "measure", "measure type should be 'measure'"); - is(measure.startTime, 0, "measure start time should be zero"); - ok(measure.duration >= 0, "measure duration should not be negative"); + // We don't have navigationStart in workers. + if ("window" in self) { + ok(true, "Running measure addition with no start/end time test"); + performance.measure("test", "navigationStart"); + var measures = performance.getEntriesByType("measure"); + is(measures.length, 1, "number of measures should be 1"); + var measure = measures[0]; + is(measure.name, "test", "measure name should be 'test'"); + is(measure.entryType, "measure", "measure type should be 'measure'"); + is(measure.startTime, 0, "measure start time should be zero"); + ok(measure.duration >= 0, "measure duration should not be negative"); + } }, function () { ok(true, "Running measure addition with only start time test"); -- cgit v1.2.3 From 98438fa32e4f93b59359662188e164c7c828acb7 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:15:36 +0200 Subject: Bug 1313420 - Implement Performance.timeOrigin - part 1 https://hg.mozilla.org/mozilla-central/rev/cf0f72f0b0be --- dom/performance/Performance.cpp | 14 +++++++++- dom/performance/Performance.h | 5 ++++ dom/performance/PerformanceService.cpp | 46 ++++++++++++++++++++++++++++++++ dom/performance/PerformanceService.h | 48 ++++++++++++++++++++++++++++++++++ dom/performance/moz.build | 2 ++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 dom/performance/PerformanceService.cpp create mode 100644 dom/performance/PerformanceService.h (limited to 'dom/performance') diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 074bffe8a..d1547dc06 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -13,6 +13,7 @@ #include "PerformanceMeasure.h" #include "PerformanceObserver.h" #include "PerformanceResourceTiming.h" +#include "PerformanceService.h" #include "PerformanceWorker.h" #include "mozilla/ErrorResult.h" #include "mozilla/dom/PerformanceBinding.h" @@ -119,6 +120,17 @@ Performance::Performance(nsPIDOMWindowInner* aWindow) Performance::~Performance() {} +DOMHighResTimeStamp +Performance::TimeOrigin() +{ + if (!mPerformanceService) { + mPerformanceService = PerformanceService::GetOrCreate(); + } + + MOZ_ASSERT(mPerformanceService); + return mPerformanceService->TimeOrigin(CreationTimeStamp()); +} + JSObject* Performance::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { @@ -243,7 +255,7 @@ Performance::ClearMarks(const Optional& aName) DOMHighResTimeStamp Performance::ResolveTimestampFromName(const nsAString& aName, - ErrorResult& aRv) + ErrorResult& aRv) { AutoTArray, 1> arr; DOMHighResTimeStamp ts; diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index 04dd76bc7..8495235a2 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -24,6 +24,7 @@ namespace dom { class PerformanceEntry; class PerformanceNavigation; class PerformanceObserver; +class PerformanceService; class PerformanceTiming; namespace workers { @@ -69,6 +70,8 @@ public: virtual DOMHighResTimeStamp Now() const = 0; + DOMHighResTimeStamp TimeOrigin(); + void Mark(const nsAString& aName, ErrorResult& aRv); void ClearMarks(const Optional& aName); @@ -157,6 +160,8 @@ private: uint64_t mResourceTimingBufferSize; static const uint64_t kDefaultResourceTimingBufferSize = 150; bool mPendingNotificationObserversTask; + + RefPtr mPerformanceService; }; } // namespace dom diff --git a/dom/performance/PerformanceService.cpp b/dom/performance/PerformanceService.cpp new file mode 100644 index 000000000..cf119af89 --- /dev/null +++ b/dom/performance/PerformanceService.cpp @@ -0,0 +1,46 @@ +/* -*- 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 "PerformanceService.h" + +#include "mozilla/ClearOnShutdown.h" +#include "mozilla/StaticMutex.h" +#include "mozilla/StaticPtr.h" + +namespace mozilla { +namespace dom { + +static StaticRefPtr gPerformanceService; +static StaticMutex gPerformanceServiceMutex; + +/* static */ PerformanceService* +PerformanceService::GetOrCreate() +{ + StaticMutexAutoLock al(gPerformanceServiceMutex); + + if (!gPerformanceService) { + gPerformanceService = new PerformanceService(); + ClearOnShutdown(&gPerformanceService); + } + + return gPerformanceService; +} + +DOMHighResTimeStamp +PerformanceService::TimeOrigin(const TimeStamp& aCreationTimeStamp) const +{ + return (aCreationTimeStamp - mCreationTimeStamp).ToMilliseconds() + + (mCreationEpochTime / PR_USEC_PER_MSEC); +} + +PerformanceService::PerformanceService() +{ + mCreationTimeStamp = TimeStamp::Now(); + mCreationEpochTime = PR_Now(); +} + +} // dom namespace +} // mozilla namespace diff --git a/dom/performance/PerformanceService.h b/dom/performance/PerformanceService.h new file mode 100644 index 000000000..9abbd674d --- /dev/null +++ b/dom/performance/PerformanceService.h @@ -0,0 +1,48 @@ +/* -*- 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/. */ + +#ifndef dom_performance_PerformanceService_h +#define dom_performance_PerformanceService_h + +#include "mozilla/TimeStamp.h" +#include "nsCOMPtr.h" +#include "nsDOMNavigationTiming.h" + +namespace mozilla { +namespace dom { + +// This class is thread-safe. + +// We use this singleton for having the correct value of performance.timeOrigin. +// This value must be calculated on top of the pair: +// - mCreationTimeStamp (monotonic clock) +// - mCreationEpochTime (unix epoch time) +// These 2 values must be taken "at the same time" in order to be used +// correctly. + +class PerformanceService +{ +public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PerformanceService) + + static PerformanceService* + GetOrCreate(); + + DOMHighResTimeStamp + TimeOrigin(const TimeStamp& aCreationTimeStamp) const; + +private: + PerformanceService(); + ~PerformanceService() = default; + + TimeStamp mCreationTimeStamp; + PRTime mCreationEpochTime; +}; + +} // dom namespace +} // mozilla namespace + +#endif // dom_performance_PerformanceService_h diff --git a/dom/performance/moz.build b/dom/performance/moz.build index 3286a0a4c..04f07f061 100644 --- a/dom/performance/moz.build +++ b/dom/performance/moz.build @@ -13,6 +13,7 @@ EXPORTS.mozilla.dom += [ 'PerformanceObserver.h', 'PerformanceObserverEntryList.h', 'PerformanceResourceTiming.h', + 'PerformanceService.h', 'PerformanceTiming.h', ] @@ -26,6 +27,7 @@ UNIFIED_SOURCES += [ 'PerformanceObserver.cpp', 'PerformanceObserverEntryList.cpp', 'PerformanceResourceTiming.cpp', + 'PerformanceService.cpp', 'PerformanceTiming.cpp', 'PerformanceWorker.cpp', ] -- cgit v1.2.3 From d564205c583cb6b95487c237fbe05e08ed53a915 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:18:35 +0200 Subject: Bug 1313420 - Implement Performance.timeOrigin - part 2 - tests https://hg.mozilla.org/mozilla-central/rev/c22f17e0db9d --- dom/performance/tests/mochitest.ini | 1 + dom/performance/tests/test_timeOrigin.html | 68 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 dom/performance/tests/test_timeOrigin.html (limited to 'dom/performance') diff --git a/dom/performance/tests/mochitest.ini b/dom/performance/tests/mochitest.ini index 7005637e1..bee0b2e70 100644 --- a/dom/performance/tests/mochitest.ini +++ b/dom/performance/tests/mochitest.ini @@ -13,3 +13,4 @@ support-files = [test_worker_observer.html] [test_sharedWorker_performance_user_timing.html] [test_worker_performance_now.html] +[test_timeOrigin.html] diff --git a/dom/performance/tests/test_timeOrigin.html b/dom/performance/tests/test_timeOrigin.html new file mode 100644 index 000000000..5a8a461f3 --- /dev/null +++ b/dom/performance/tests/test_timeOrigin.html @@ -0,0 +1,68 @@ + + + + Test for performance.timeOrigin + + + + + + + + + + + + + -- cgit v1.2.3 From 1ad6dc807cfff2d0c6d51068390289fd0f76a60a Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:19:25 +0200 Subject: Bug 1313420 - Implement Performance.timeOrigin - part 3 - tests https://hg.mozilla.org/mozilla-central/rev/0f869d4c93ef --- dom/performance/tests/test_timeOrigin.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/tests/test_timeOrigin.html b/dom/performance/tests/test_timeOrigin.html index 5a8a461f3..2c5de0d5d 100644 --- a/dom/performance/tests/test_timeOrigin.html +++ b/dom/performance/tests/test_timeOrigin.html @@ -32,7 +32,7 @@ function testWorker() { { type: "text/javascript" }); var w = new Worker(URL.createObjectURL(blob)); w.onmessage = function(e) { - ok (e.now + e.timeOrigin > now + performance.now, "Comparing worker.now and window.now"); + ok (e.now + e.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); next(); } } @@ -44,7 +44,7 @@ function testSharedWorker() { { type: "text/javascript" }); var w = new SharedWorker(URL.createObjectURL(blob)); w.port.onmessage = function(e) { - ok (e.now + e.timeOrigin > now + performance.now, "Comparing worker.now and window.now"); + ok (e.now + e.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); next(); } } -- cgit v1.2.3 From 30cf4c5d9356ddb7d474107af66a83826d403922 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:20:22 +0200 Subject: Bug 1313420 - Implement Performance.timeOrigin - part 4 - tests https://hg.mozilla.org/mozilla-central/rev/49305a317143 --- dom/performance/tests/test_timeOrigin.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/tests/test_timeOrigin.html b/dom/performance/tests/test_timeOrigin.html index 2c5de0d5d..73c5106f4 100644 --- a/dom/performance/tests/test_timeOrigin.html +++ b/dom/performance/tests/test_timeOrigin.html @@ -32,7 +32,7 @@ function testWorker() { { type: "text/javascript" }); var w = new Worker(URL.createObjectURL(blob)); w.onmessage = function(e) { - ok (e.now + e.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); + ok (e.data.now + e.data.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); next(); } } @@ -44,7 +44,7 @@ function testSharedWorker() { { type: "text/javascript" }); var w = new SharedWorker(URL.createObjectURL(blob)); w.port.onmessage = function(e) { - ok (e.now + e.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); + ok (e.data.now + e.data.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); next(); } } -- cgit v1.2.3 From 85a83305dd0caeb484687cf511f81024a683338b Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:26:49 +0200 Subject: Bug 1322292 - Some fixes for the Performance API in workers - part 1 - Centralized Performance.now() https://hg.mozilla.org/mozilla-central/rev/291a68ca4825 --- dom/performance/Performance.cpp | 7 +++++++ dom/performance/Performance.h | 2 +- dom/performance/PerformanceMainThread.cpp | 6 ------ dom/performance/PerformanceMainThread.h | 3 --- dom/performance/PerformanceWorker.cpp | 8 -------- dom/performance/PerformanceWorker.h | 3 --- dom/performance/tests/test_timeOrigin.html | 4 ++-- 7 files changed, 10 insertions(+), 23 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index d1547dc06..8f6a61c85 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -120,6 +120,13 @@ Performance::Performance(nsPIDOMWindowInner* aWindow) Performance::~Performance() {} +DOMHighResTimeStamp +Performance::Now() const +{ + TimeDuration duration = TimeStamp::Now() - CreationTimeStamp(); + return RoundTime(duration.ToMilliseconds()); +} + DOMHighResTimeStamp Performance::TimeOrigin() { diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index 8495235a2..32c689c6e 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -68,7 +68,7 @@ public: void ClearResourceTimings(); - virtual DOMHighResTimeStamp Now() const = 0; + DOMHighResTimeStamp Now() const; DOMHighResTimeStamp TimeOrigin(); diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index d67c0c906..5eac15afd 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -105,12 +105,6 @@ PerformanceMainThread::Navigation() return mNavigation; } -DOMHighResTimeStamp -PerformanceMainThread::Now() const -{ - return RoundTime(GetDOMTiming()->TimeStampToDOMHighRes(TimeStamp::Now())); -} - /** * An entry should be added only after the resource is loaded. * This method is not thread safe and can only be called on the main thread. diff --git a/dom/performance/PerformanceMainThread.h b/dom/performance/PerformanceMainThread.h index fcaa6b903..c5f8887a4 100644 --- a/dom/performance/PerformanceMainThread.h +++ b/dom/performance/PerformanceMainThread.h @@ -23,9 +23,6 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PerformanceMainThread, Performance) - // Performance WebIDL methods - DOMHighResTimeStamp Now() const override; - virtual PerformanceTiming* Timing() override; virtual PerformanceNavigation* Navigation() override; diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp index db9d6aa6e..17820d434 100644 --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -23,14 +23,6 @@ PerformanceWorker::~PerformanceWorker() mWorkerPrivate->AssertIsOnWorkerThread(); } -DOMHighResTimeStamp -PerformanceWorker::Now() const -{ - TimeDuration duration = - TimeStamp::Now() - mWorkerPrivate->NowBaseTimeStamp(); - return RoundTime(duration.ToMilliseconds()); -} - void PerformanceWorker::InsertUserEntry(PerformanceEntry* aEntry) { diff --git a/dom/performance/PerformanceWorker.h b/dom/performance/PerformanceWorker.h index 89bfea3ed..346bdd026 100644 --- a/dom/performance/PerformanceWorker.h +++ b/dom/performance/PerformanceWorker.h @@ -21,9 +21,6 @@ class PerformanceWorker final : public Performance public: explicit PerformanceWorker(workers::WorkerPrivate* aWorkerPrivate); - // Performance WebIDL methods - DOMHighResTimeStamp Now() const override; - virtual PerformanceTiming* Timing() override { MOZ_CRASH("This should not be called on workers."); diff --git a/dom/performance/tests/test_timeOrigin.html b/dom/performance/tests/test_timeOrigin.html index 73c5106f4..5a8a461f3 100644 --- a/dom/performance/tests/test_timeOrigin.html +++ b/dom/performance/tests/test_timeOrigin.html @@ -32,7 +32,7 @@ function testWorker() { { type: "text/javascript" }); var w = new Worker(URL.createObjectURL(blob)); w.onmessage = function(e) { - ok (e.data.now + e.data.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); + ok (e.now + e.timeOrigin > now + performance.now, "Comparing worker.now and window.now"); next(); } } @@ -44,7 +44,7 @@ function testSharedWorker() { { type: "text/javascript" }); var w = new SharedWorker(URL.createObjectURL(blob)); w.port.onmessage = function(e) { - ok (e.data.now + e.data.timeOrigin > now + performance.timeOrigin, "Comparing worker.now and window.now"); + ok (e.now + e.timeOrigin > now + performance.now, "Comparing worker.now and window.now"); next(); } } -- cgit v1.2.3 From 089a0bd9a4dace03e5800878055b86854eee5002 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 12:32:19 +0200 Subject: Bug 1322292 - Some fixes for the Performance API in workers - part 2 - Get rid of NowBaseTimeStamp() https://hg.mozilla.org/mozilla-central/rev/301231f4165a --- dom/performance/PerformanceMainThread.cpp | 2 +- dom/performance/PerformanceWorker.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index 5eac15afd..5c259cfb8 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -75,7 +75,7 @@ PerformanceTiming* PerformanceMainThread::Timing() { if (!mTiming) { - // For navigation timing, the third argument (an nsIHtttpChannel) is null + // For navigation timing, the third argument (an nsIHttpChannel) is null // since the cross-domain redirect were already checked. The last argument // (zero time) for performance.timing is the navigation start value. mTiming = new PerformanceTiming(this, mChannel, nullptr, diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp index 17820d434..f10c58446 100644 --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -41,13 +41,13 @@ PerformanceWorker::InsertUserEntry(PerformanceEntry* aEntry) TimeStamp PerformanceWorker::CreationTimeStamp() const { - return mWorkerPrivate->NowBaseTimeStamp(); + return mWorkerPrivate->CreationTimeStamp(); } DOMHighResTimeStamp PerformanceWorker::CreationTime() const { - return mWorkerPrivate->NowBaseTime(); + return mWorkerPrivate->CreationTime(); } } // dom namespace -- cgit v1.2.3 From 306db80410e802b0fe9a3b5273d4cf29586a1b17 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Apr 2018 14:15:18 +0200 Subject: moebius#161: The Performance Resource Timing (make timestamps be relative to startTime) https://github.com/MoonchildProductions/moebius/pull/161 --- dom/performance/Performance.cpp | 1 + dom/performance/Performance.h | 14 ++-- dom/performance/PerformanceMainThread.cpp | 99 ++++++++++++++++--------- dom/performance/PerformanceMainThread.h | 11 +++ dom/performance/PerformanceNavigationTiming.cpp | 96 ++++++++++++++++++++++++ dom/performance/PerformanceNavigationTiming.h | 71 ++++++++++++++++++ dom/performance/PerformanceResourceTiming.cpp | 31 +++++++- dom/performance/PerformanceResourceTiming.h | 6 +- dom/performance/PerformanceTiming.h | 8 ++ dom/performance/moz.build | 2 + 10 files changed, 295 insertions(+), 44 deletions(-) create mode 100644 dom/performance/PerformanceNavigationTiming.cpp create mode 100644 dom/performance/PerformanceNavigationTiming.h (limited to 'dom/performance') diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 8f6a61c85..93a6b7313 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -20,6 +20,7 @@ #include "mozilla/dom/PerformanceEntryEvent.h" #include "mozilla/dom/PerformanceNavigationBinding.h" #include "mozilla/dom/PerformanceObserverBinding.h" +#include "mozilla/dom/PerformanceNavigationTiming.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/Preferences.h" #include "mozilla/TimerClamping.h" diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index 32c689c6e..4debecc90 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -54,14 +54,14 @@ public: JSObject* WrapObject(JSContext *cx, JS::Handle aGivenProto) override; - void GetEntries(nsTArray>& aRetval); + virtual void GetEntries(nsTArray>& aRetval); - void GetEntriesByType(const nsAString& aEntryType, - nsTArray>& aRetval); + virtual void GetEntriesByType(const nsAString& aEntryType, + nsTArray>& aRetval); - void GetEntriesByName(const nsAString& aName, - const Optional& aEntryType, - nsTArray>& aRetval); + virtual void GetEntriesByName(const nsAString& aName, + const Optional& aEntryType, + nsTArray>& aRetval); virtual void AddEntry(nsIHttpChannel* channel, nsITimedChannel* timedChannel) = 0; @@ -153,7 +153,7 @@ protected: nsTObserverArray mObservers; -private: +protected: nsTArray> mUserEntries; nsTArray> mResourceEntries; diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index 5c259cfb8..64c06d3ea 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -16,7 +16,8 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceMainThread) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PerformanceMainThread, Performance) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTiming, - mNavigation) + mNavigation, + mDocEntry) tmp->mMozMemory = nullptr; mozilla::DropJSObjects(this); NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -24,7 +25,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PerformanceMainThread, Performance) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTiming, - mNavigation) + mNavigation, + mDocEntry) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -152,38 +154,7 @@ PerformanceMainThread::AddEntry(nsIHttpChannel* channel, // The PerformanceResourceTiming object will use the PerformanceTiming // object to get all the required timings. RefPtr performanceEntry = - new PerformanceResourceTiming(performanceTiming, this, entryName); - - nsAutoCString protocol; - channel->GetProtocolVersion(protocol); - - // If this is a local fetch, nextHopProtocol should be set to empty string. - nsCOMPtr cachedChannel = do_QueryInterface(channel); - if (cachedChannel) { - bool isFromCache; - if (NS_SUCCEEDED(cachedChannel->IsFromCache(&isFromCache)) - && isFromCache) { - protocol.Truncate(); - } - } - - performanceEntry->SetNextHopProtocol(NS_ConvertUTF8toUTF16(protocol)); - - uint64_t encodedBodySize = 0; - channel->GetEncodedBodySize(&encodedBodySize); - performanceEntry->SetEncodedBodySize(encodedBodySize); - - uint64_t transferSize = 0; - channel->GetTransferSize(&transferSize); - performanceEntry->SetTransferSize(transferSize); - - uint64_t decodedBodySize = 0; - channel->GetDecodedBodySize(&decodedBodySize); - if (decodedBodySize == 0) { - decodedBodySize = encodedBodySize; - } - performanceEntry->SetDecodedBodySize(decodedBodySize); - + new PerformanceResourceTiming(performanceTiming, this, entryName, channel); // If the initiator type had no valid value, then set it to the default // ("other") value. if (initiatorType.IsEmpty()) { @@ -337,5 +308,65 @@ PerformanceMainThread::CreationTime() const return GetDOMTiming()->GetNavigationStart(); } +void +PerformanceMainThread::EnsureDocEntry() +{ + if (!mDocEntry && nsContentUtils::IsPerformanceNavigationTimingEnabled()) { + nsCOMPtr httpChannel = do_QueryInterface(mChannel); + RefPtr timing = + new PerformanceTiming(this, mChannel, nullptr, 0); + mDocEntry = new PerformanceNavigationTiming(timing, this, + httpChannel); + } +} + + +void +PerformanceMainThread::GetEntries(nsTArray>& aRetval) +{ + aRetval = mResourceEntries; + aRetval.AppendElements(mUserEntries); + + EnsureDocEntry(); + if (mDocEntry) { + aRetval.AppendElement(mDocEntry); + } + + aRetval.Sort(PerformanceEntryComparator()); +} + +void +PerformanceMainThread::GetEntriesByType(const nsAString& aEntryType, + nsTArray>& aRetval) +{ + if (aEntryType.EqualsLiteral("navigation")) { + aRetval.Clear(); + EnsureDocEntry(); + if (mDocEntry) { + aRetval.AppendElement(mDocEntry); + } + return; + } + + Performance::GetEntriesByType(aEntryType, aRetval); +} + +void +PerformanceMainThread::GetEntriesByName(const nsAString& aName, + const Optional& aEntryType, + nsTArray>& aRetval) +{ + if (aName.EqualsLiteral("document")) { + aRetval.Clear(); + EnsureDocEntry(); + if (mDocEntry) { + aRetval.AppendElement(mDocEntry); + } + return; + } + + Performance::GetEntriesByName(aName, aEntryType, aRetval); +} + } // dom namespace } // mozilla namespace diff --git a/dom/performance/PerformanceMainThread.h b/dom/performance/PerformanceMainThread.h index c5f8887a4..9f0e185fc 100644 --- a/dom/performance/PerformanceMainThread.h +++ b/dom/performance/PerformanceMainThread.h @@ -47,6 +47,15 @@ public: return mChannel; } + // The GetEntries* methods need to be overriden in order to add the + // the document entry of type navigation. + virtual void GetEntries(nsTArray>& aRetval) override; + virtual void GetEntriesByType(const nsAString& aEntryType, + nsTArray>& aRetval) override; + virtual void GetEntriesByName(const nsAString& aName, + const Optional& aEntryType, + nsTArray>& aRetval) override; + protected: ~PerformanceMainThread(); @@ -63,7 +72,9 @@ protected: GetPerformanceTimingFromString(const nsAString& aTimingName) override; void DispatchBufferFullEvent() override; + void EnsureDocEntry(); + RefPtr mDocEntry; RefPtr mDOMTiming; nsCOMPtr mChannel; RefPtr mTiming; diff --git a/dom/performance/PerformanceNavigationTiming.cpp b/dom/performance/PerformanceNavigationTiming.cpp new file mode 100644 index 000000000..4e00b2bb2 --- /dev/null +++ b/dom/performance/PerformanceNavigationTiming.cpp @@ -0,0 +1,96 @@ +/* -*- 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/dom/PerformanceNavigationTiming.h" +#include "mozilla/dom/PerformanceNavigationTimingBinding.h" + +using namespace mozilla::dom; + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceNavigationTiming) +NS_INTERFACE_MAP_END_INHERITING(PerformanceResourceTiming) + +NS_IMPL_ADDREF_INHERITED(PerformanceNavigationTiming, PerformanceResourceTiming) +NS_IMPL_RELEASE_INHERITED(PerformanceNavigationTiming, PerformanceResourceTiming) + +JSObject* +PerformanceNavigationTiming::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return PerformanceNavigationTimingBinding::Wrap(aCx, this, aGivenProto); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::UnloadEventStart() const +{ + return mTiming->GetDOMTiming()->GetUnloadEventStartHighRes(); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::UnloadEventEnd() const +{ + return mTiming->GetDOMTiming()->GetUnloadEventEndHighRes(); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::DomInteractive() const +{ + return mTiming->GetDOMTiming()->GetDomInteractiveHighRes(); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::DomContentLoadedEventStart() const +{ + return mTiming->GetDOMTiming()->GetDomContentLoadedEventStartHighRes(); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::DomContentLoadedEventEnd() const +{ + return mTiming->GetDOMTiming()->GetDomContentLoadedEventEndHighRes(); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::DomComplete() const +{ + return mTiming->GetDOMTiming()->GetDomCompleteHighRes(); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::LoadEventStart() const +{ + return mTiming->GetDOMTiming()->GetLoadEventStartHighRes(); +} + +DOMHighResTimeStamp +PerformanceNavigationTiming::LoadEventEnd() const +{ + return mTiming->GetDOMTiming()->GetLoadEventEndHighRes(); +} + +NavigationType +PerformanceNavigationTiming::Type() const +{ + switch(mTiming->GetDOMTiming()->GetType()) { + case nsDOMNavigationTiming::TYPE_NAVIGATE: + return NavigationType::Navigate; + break; + case nsDOMNavigationTiming::TYPE_RELOAD: + return NavigationType::Reload; + break; + case nsDOMNavigationTiming::TYPE_BACK_FORWARD: + return NavigationType::Back_forward; + break; + default: + // The type is TYPE_RESERVED or some other value that was later added. + // We fallback to the default of Navigate. + return NavigationType::Navigate; + } +} + +uint16_t +PerformanceNavigationTiming::RedirectCount() const +{ + return mTiming->GetRedirectCount(); +} diff --git a/dom/performance/PerformanceNavigationTiming.h b/dom/performance/PerformanceNavigationTiming.h new file mode 100644 index 000000000..8555f1987 --- /dev/null +++ b/dom/performance/PerformanceNavigationTiming.h @@ -0,0 +1,71 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_PerformanceNavigationTiming_h___ +#define mozilla_dom_PerformanceNavigationTiming_h___ + +#include "nsCOMPtr.h" +#include "nsIChannel.h" +#include "nsITimedChannel.h" +#include "mozilla/dom/PerformanceResourceTiming.h" +#include "mozilla/dom/PerformanceNavigationTimingBinding.h" +#include "nsIHttpChannel.h" + +namespace mozilla { +namespace dom { + +// https://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming +class PerformanceNavigationTiming final + : public PerformanceResourceTiming +{ +public: + NS_DECL_ISUPPORTS_INHERITED + + // Note that aPerformanceTiming must be initalized with zeroTime = 0 + // so that timestamps are relative to startTime, as opposed to the + // performance.timing object for which timestamps are absolute and has a + // zeroTime initialized to navigationStart + explicit PerformanceNavigationTiming(PerformanceTiming* aPerformanceTiming, + Performance* aPerformance, + nsIHttpChannel* aChannel) + : PerformanceResourceTiming(aPerformanceTiming, aPerformance, + NS_LITERAL_STRING("document"), aChannel) { + SetEntryType(NS_LITERAL_STRING("navigation")); + SetInitiatorType(NS_LITERAL_STRING("navigation")); + } + + DOMHighResTimeStamp Duration() const override + { + return LoadEventEnd() - StartTime(); + } + + DOMHighResTimeStamp StartTime() const override + { + return 0; + } + + JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + + DOMHighResTimeStamp UnloadEventStart() const; + DOMHighResTimeStamp UnloadEventEnd() const; + + DOMHighResTimeStamp DomInteractive() const; + DOMHighResTimeStamp DomContentLoadedEventStart() const; + DOMHighResTimeStamp DomContentLoadedEventEnd() const; + DOMHighResTimeStamp DomComplete() const; + DOMHighResTimeStamp LoadEventStart() const; + DOMHighResTimeStamp LoadEventEnd() const; + NavigationType Type() const; + uint16_t RedirectCount() const; + +private: + ~PerformanceNavigationTiming() {} +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_PerformanceNavigationTiming_h___ diff --git a/dom/performance/PerformanceResourceTiming.cpp b/dom/performance/PerformanceResourceTiming.cpp index 94df27408..2eaa4eb9a 100644 --- a/dom/performance/PerformanceResourceTiming.cpp +++ b/dom/performance/PerformanceResourceTiming.cpp @@ -25,7 +25,8 @@ NS_IMPL_RELEASE_INHERITED(PerformanceResourceTiming, PerformanceEntry) PerformanceResourceTiming::PerformanceResourceTiming(PerformanceTiming* aPerformanceTiming, Performance* aPerformance, - const nsAString& aName) + const nsAString& aName, + nsIHttpChannel* aChannel) : PerformanceEntry(aPerformance, aName, NS_LITERAL_STRING("resource")), mTiming(aPerformanceTiming), mEncodedBodySize(0), @@ -33,6 +34,34 @@ PerformanceResourceTiming::PerformanceResourceTiming(PerformanceTiming* aPerform mDecodedBodySize(0) { MOZ_ASSERT(aPerformance, "Parent performance object should be provided"); + SetPropertiesFromChannel(aChannel); +} + +void +PerformanceResourceTiming::SetPropertiesFromChannel(nsIHttpChannel* aChannel) +{ + if (!aChannel) { + return; + } + + nsAutoCString protocol; + Unused << aChannel->GetProtocolVersion(protocol); + SetNextHopProtocol(NS_ConvertUTF8toUTF16(protocol)); + + uint64_t encodedBodySize = 0; + Unused << aChannel->GetEncodedBodySize(&encodedBodySize); + SetEncodedBodySize(encodedBodySize); + + uint64_t transferSize = 0; + Unused << aChannel->GetTransferSize(&transferSize); + SetTransferSize(transferSize); + + uint64_t decodedBodySize = 0; + Unused << aChannel->GetDecodedBodySize(&decodedBodySize); + if (decodedBodySize == 0) { + decodedBodySize = encodedBodySize; + } + SetDecodedBodySize(decodedBodySize); } PerformanceResourceTiming::~PerformanceResourceTiming() diff --git a/dom/performance/PerformanceResourceTiming.h b/dom/performance/PerformanceResourceTiming.h index c2e6c0972..98a03327e 100644 --- a/dom/performance/PerformanceResourceTiming.h +++ b/dom/performance/PerformanceResourceTiming.h @@ -18,7 +18,7 @@ namespace mozilla { namespace dom { // http://www.w3.org/TR/resource-timing/#performanceresourcetiming -class PerformanceResourceTiming final : public PerformanceEntry +class PerformanceResourceTiming : public PerformanceEntry { public: typedef mozilla::TimeStamp TimeStamp; @@ -30,7 +30,8 @@ public: PerformanceResourceTiming(PerformanceTiming* aPerformanceTiming, Performance* aPerformance, - const nsAString& aName); + const nsAString& aName, + nsIHttpChannel* aChannel = nullptr); virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; @@ -176,6 +177,7 @@ public: protected: virtual ~PerformanceResourceTiming(); + void SetPropertiesFromChannel(nsIHttpChannel* aChannel); nsString mInitiatorType; nsString mNextHopProtocol; diff --git a/dom/performance/PerformanceTiming.h b/dom/performance/PerformanceTiming.h index 584ae0816..435e1bca1 100755 --- a/dom/performance/PerformanceTiming.h +++ b/dom/performance/PerformanceTiming.h @@ -242,6 +242,14 @@ public: return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetLoadEventEnd()); } + DOMTimeMilliSec TimeToNonBlankPaint() const + { + if (!nsContentUtils::IsPerformanceTimingEnabled()) { + return 0; + } + return TimerClamping::ReduceMsTimeValue(GetDOMTiming()->GetTimeToNonBlankPaint()); + } + private: ~PerformanceTiming(); diff --git a/dom/performance/moz.build b/dom/performance/moz.build index 04f07f061..e1f96fec8 100644 --- a/dom/performance/moz.build +++ b/dom/performance/moz.build @@ -10,6 +10,7 @@ EXPORTS.mozilla.dom += [ 'PerformanceMark.h', 'PerformanceMeasure.h', 'PerformanceNavigation.h', + 'PerformanceNavigationTiming.h', 'PerformanceObserver.h', 'PerformanceObserverEntryList.h', 'PerformanceResourceTiming.h', @@ -24,6 +25,7 @@ UNIFIED_SOURCES += [ 'PerformanceMark.cpp', 'PerformanceMeasure.cpp', 'PerformanceNavigation.cpp', + 'PerformanceNavigationTiming.cpp', 'PerformanceObserver.cpp', 'PerformanceObserverEntryList.cpp', 'PerformanceResourceTiming.cpp', -- cgit v1.2.3 From a6de0846702b2eb21ce2f29ba42bf968fbd4fe2f Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 13 May 2018 21:48:05 +0200 Subject: Remove missed MOZ_WIDGET_GONK ifdef Tag #288 --- dom/performance/Performance.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'dom/performance') diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 93a6b7313..a1e28bc55 100755 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -27,11 +27,7 @@ #include "WorkerPrivate.h" #include "WorkerRunnable.h" -#ifdef MOZ_WIDGET_GONK -#define PERFLOG(msg, ...) __android_log_print(ANDROID_LOG_INFO, "PerformanceTiming", msg, ##__VA_ARGS__) -#else #define PERFLOG(msg, ...) printf_stderr(msg, ##__VA_ARGS__) -#endif namespace mozilla { namespace dom { -- cgit v1.2.3