diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-04-29 14:44:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-29 14:44:39 +0200 |
commit | 64aec5a353b4eb58e075c01b2d6d948aa142e6ff (patch) | |
tree | d1e865c31c0864837f47f2eb1c99edd3a011c5d8 /dom/base/nsDOMNavigationTiming.cpp | |
parent | 6fe08dcf34417e825b7b9b6b33141a4a3b46ba24 (diff) | |
parent | 306db80410e802b0fe9a3b5273d4cf29586a1b17 (diff) | |
download | UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar.gz UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar.lz UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.tar.xz UXP-64aec5a353b4eb58e075c01b2d6d948aa142e6ff.zip |
Merge pull request #294 from janekptacijarabaci/js_dom_performance-resource-timing_2
moebius#161: The Performance Resource Timing (make timestamps be relative to startTime)
Diffstat (limited to 'dom/base/nsDOMNavigationTiming.cpp')
-rw-r--r-- | dom/base/nsDOMNavigationTiming.cpp | 138 |
1 files changed, 66 insertions, 72 deletions
diff --git a/dom/base/nsDOMNavigationTiming.cpp b/dom/base/nsDOMNavigationTiming.cpp index 31b2932fb..32ce8a8cb 100644 --- a/dom/base/nsDOMNavigationTiming.cpp +++ b/dom/base/nsDOMNavigationTiming.cpp @@ -15,6 +15,9 @@ #include "nsPrintfCString.h" #include "mozilla/dom/PerformanceNavigation.h" #include "mozilla/TimeStamp.h" +#include "mozilla/Telemetry.h" + +using namespace mozilla; nsDOMNavigationTiming::nsDOMNavigationTiming() { @@ -30,47 +33,36 @@ nsDOMNavigationTiming::Clear() { mNavigationType = TYPE_RESERVED; mNavigationStartHighRes = 0; - mBeforeUnloadStart = 0; - mUnloadStart = 0; - mUnloadEnd = 0; - mLoadEventStart = 0; - mLoadEventEnd = 0; - mDOMLoading = 0; - mDOMInteractive = 0; - mDOMContentLoadedEventStart = 0; - mDOMContentLoadedEventEnd = 0; - mDOMComplete = 0; - - mLoadEventStartSet = false; - mLoadEventEndSet = false; - mDOMLoadingSet = false; - mDOMInteractiveSet = false; - mDOMContentLoadedEventStartSet = false; - mDOMContentLoadedEventEndSet = false; - mDOMCompleteSet = false; + mBeforeUnloadStart = TimeStamp(); + mUnloadStart = TimeStamp(); + mUnloadEnd = TimeStamp(); + mLoadEventStart = TimeStamp(); + mLoadEventEnd = TimeStamp(); + mDOMLoading = TimeStamp(); + mDOMInteractive = TimeStamp(); + mDOMContentLoadedEventStart = TimeStamp(); + mDOMContentLoadedEventEnd = TimeStamp(); + mDOMComplete = TimeStamp(); + mDocShellHasBeenActiveSinceNavigationStart = false; } DOMTimeMilliSec -nsDOMNavigationTiming::TimeStampToDOM(mozilla::TimeStamp aStamp) const +nsDOMNavigationTiming::TimeStampToDOM(TimeStamp aStamp) const { if (aStamp.IsNull()) { return 0; } - mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp; - return GetNavigationStart() + static_cast<int64_t>(duration.ToMilliseconds()); -} -DOMTimeMilliSec nsDOMNavigationTiming::DurationFromStart() -{ - return TimeStampToDOM(mozilla::TimeStamp::Now()); + TimeDuration duration = aStamp - mNavigationStart; + return GetNavigationStart() + static_cast<int64_t>(duration.ToMilliseconds()); } void nsDOMNavigationTiming::NotifyNavigationStart(DocShellState aDocShellState) { mNavigationStartHighRes = (double)PR_Now() / PR_USEC_PER_MSEC; - mNavigationStartTimeStamp = mozilla::TimeStamp::Now(); + mNavigationStart = TimeStamp::Now(); mDocShellHasBeenActiveSinceNavigationStart = (aDocShellState == DocShellState::eActive); } @@ -86,7 +78,7 @@ nsDOMNavigationTiming::NotifyFetchStart(nsIURI* aURI, Type aNavigationType) void nsDOMNavigationTiming::NotifyBeforeUnload() { - mBeforeUnloadStart = DurationFromStart(); + mBeforeUnloadStart = TimeStamp::Now(); } void @@ -99,105 +91,107 @@ nsDOMNavigationTiming::NotifyUnloadAccepted(nsIURI* aOldURI) void nsDOMNavigationTiming::NotifyUnloadEventStart() { - mUnloadStart = DurationFromStart(); + mUnloadStart = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyUnloadEventEnd() { - mUnloadEnd = DurationFromStart(); + mUnloadEnd = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyLoadEventStart() { - if (!mLoadEventStartSet) { - mLoadEventStart = DurationFromStart(); - mLoadEventStartSet = true; + if (!mLoadEventStart.IsNull()) { + return; } + mLoadEventStart = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyLoadEventEnd() { - if (!mLoadEventEndSet) { - mLoadEventEnd = DurationFromStart(); - mLoadEventEndSet = true; + if (!mLoadEventEnd.IsNull()) { + return; } + mLoadEventEnd = TimeStamp::Now(); } void -nsDOMNavigationTiming::SetDOMLoadingTimeStamp(nsIURI* aURI, mozilla::TimeStamp aValue) +nsDOMNavigationTiming::SetDOMLoadingTimeStamp(nsIURI* aURI, TimeStamp aValue) { - if (!mDOMLoadingSet) { - mLoadedURI = aURI; - mDOMLoading = TimeStampToDOM(aValue); - mDOMLoadingSet = true; + if (!mDOMLoading.IsNull()) { + return; } + mLoadedURI = aURI; + mDOMLoading = aValue; } void nsDOMNavigationTiming::NotifyDOMLoading(nsIURI* aURI) { - if (!mDOMLoadingSet) { - mLoadedURI = aURI; - mDOMLoading = DurationFromStart(); - mDOMLoadingSet = true; + if (!mDOMLoading.IsNull()) { + return; } + mLoadedURI = aURI; + mDOMLoading = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyDOMInteractive(nsIURI* aURI) { - if (!mDOMInteractiveSet) { - mLoadedURI = aURI; - mDOMInteractive = DurationFromStart(); - mDOMInteractiveSet = true; + if (!mDOMInteractive.IsNull()) { + return; } + mLoadedURI = aURI; + mDOMInteractive = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyDOMComplete(nsIURI* aURI) { - if (!mDOMCompleteSet) { - mLoadedURI = aURI; - mDOMComplete = DurationFromStart(); - mDOMCompleteSet = true; + if (!mDOMComplete.IsNull()) { + return; } + mLoadedURI = aURI; + mDOMComplete = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI) { - if (!mDOMContentLoadedEventStartSet) { - mLoadedURI = aURI; - mDOMContentLoadedEventStart = DurationFromStart(); - mDOMContentLoadedEventStartSet = true; + if (!mDOMContentLoadedEventStart.IsNull()) { + return; } + + mLoadedURI = aURI; + mDOMContentLoadedEventStart = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI) { - if (!mDOMContentLoadedEventEndSet) { - mLoadedURI = aURI; - mDOMContentLoadedEventEnd = DurationFromStart(); - mDOMContentLoadedEventEndSet = true; + if (!mDOMContentLoadedEventEnd.IsNull()) { + return; } + + mLoadedURI = aURI; + mDOMContentLoadedEventEnd = TimeStamp::Now(); } void nsDOMNavigationTiming::NotifyNonBlankPaintForRootContentDocument() { MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(!mNavigationStartTimeStamp.IsNull()); + MOZ_ASSERT(!mNavigationStart.IsNull()); - if (!mNonBlankPaintTimeStamp.IsNull()) { + if (!mNonBlankPaint.IsNull()) { return; } - mNonBlankPaintTimeStamp = TimeStamp::Now(); - TimeDuration elapsed = mNonBlankPaintTimeStamp - mNavigationStartTimeStamp; + mNonBlankPaint = TimeStamp::Now(); + TimeDuration elapsed = mNonBlankPaint - mNavigationStart; if (profiler_is_active()) { nsAutoCString spec; @@ -212,8 +206,8 @@ nsDOMNavigationTiming::NotifyNonBlankPaintForRootContentDocument() if (mDocShellHasBeenActiveSinceNavigationStart) { Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_NON_BLANK_PAINT_MS, - mNavigationStartTimeStamp, - mNonBlankPaintTimeStamp); + mNavigationStart, + mNonBlankPaint); } } @@ -224,24 +218,24 @@ nsDOMNavigationTiming::NotifyDocShellStateChanged(DocShellState aDocShellState) (aDocShellState == DocShellState::eActive); } -DOMTimeMilliSec -nsDOMNavigationTiming::GetUnloadEventStart() +mozilla::TimeStamp +nsDOMNavigationTiming::GetUnloadEventStartTimeStamp() const { nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false); if (NS_SUCCEEDED(rv)) { return mUnloadStart; } - return 0; + return mozilla::TimeStamp(); } -DOMTimeMilliSec -nsDOMNavigationTiming::GetUnloadEventEnd() +mozilla::TimeStamp +nsDOMNavigationTiming::GetUnloadEventEndTimeStamp() const { nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false); if (NS_SUCCEEDED(rv)) { return mUnloadEnd; } - return 0; + return mozilla::TimeStamp(); } |