Bug 1344893 - Part 1: Report Navigation Timing into Telemetry. r=smaug, data-review=bsmedberg

We only need metric from top level content document, but we dont have
any information about it in nsDOMNavigationTiming, so I add a weak
reference which points to nsDocShell.

MozReview-Commit-ID: GiJigRLYHNV
This commit is contained in:
Wei-Cheng Pan 2017-04-19 02:00:00 -04:00
Родитель df0c2aae53
Коммит 1978d62be4
5 изменённых файлов: 126 добавлений и 4 удалений

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

@ -1788,7 +1788,7 @@ nsDocShell::MaybeInitTiming()
}
if (!mTiming) {
mTiming = new nsDOMNavigationTiming();
mTiming = new nsDOMNavigationTiming(this);
canBeReset = true;
}

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

@ -9,6 +9,8 @@
#include "GeckoProfiler.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIScriptSecurityManager.h"
#include "prtime.h"
#include "nsIURI.h"
@ -19,9 +21,11 @@
using namespace mozilla;
nsDOMNavigationTiming::nsDOMNavigationTiming()
nsDOMNavigationTiming::nsDOMNavigationTiming(nsDocShell* aDocShell)
{
Clear();
mDocShell = aDocShell;
}
nsDOMNavigationTiming::~nsDOMNavigationTiming()
@ -118,6 +122,11 @@ nsDOMNavigationTiming::NotifyLoadEventStart()
if (!mLoadEventStartSet) {
mLoadEventStart = DurationFromStart();
mLoadEventStartSet = true;
if (IsTopLevelContentDocument()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_LOAD_EVENT_START_MS,
mNavigationStartTimeStamp);
}
}
}
@ -127,6 +136,11 @@ nsDOMNavigationTiming::NotifyLoadEventEnd()
if (!mLoadEventEndSet) {
mLoadEventEnd = DurationFromStart();
mLoadEventEndSet = true;
if (IsTopLevelContentDocument()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_LOAD_EVENT_END_MS,
mNavigationStartTimeStamp);
}
}
}
@ -147,6 +161,11 @@ nsDOMNavigationTiming::NotifyDOMLoading(nsIURI* aURI)
mLoadedURI = aURI;
mDOMLoading = DurationFromStart();
mDOMLoadingSet = true;
if (IsTopLevelContentDocument()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_LOADING_MS,
mNavigationStartTimeStamp);
}
}
}
@ -157,6 +176,11 @@ nsDOMNavigationTiming::NotifyDOMInteractive(nsIURI* aURI)
mLoadedURI = aURI;
mDOMInteractive = DurationFromStart();
mDOMInteractiveSet = true;
if (IsTopLevelContentDocument()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_INTERACTIVE_MS,
mNavigationStartTimeStamp);
}
}
}
@ -167,6 +191,11 @@ nsDOMNavigationTiming::NotifyDOMComplete(nsIURI* aURI)
mLoadedURI = aURI;
mDOMComplete = DurationFromStart();
mDOMCompleteSet = true;
if (IsTopLevelContentDocument()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_COMPLETE_MS,
mNavigationStartTimeStamp);
}
}
}
@ -177,6 +206,11 @@ nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI)
mLoadedURI = aURI;
mDOMContentLoadedEventStart = DurationFromStart();
mDOMContentLoadedEventStartSet = true;
if (IsTopLevelContentDocument()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_CONTENT_LOADED_START_MS,
mNavigationStartTimeStamp);
}
}
}
@ -187,6 +221,11 @@ nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI)
mLoadedURI = aURI;
mDOMContentLoadedEventEnd = DurationFromStart();
mDOMContentLoadedEventEndSet = true;
if (IsTopLevelContentDocument()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_CONTENT_LOADED_END_MS,
mNavigationStartTimeStamp);
}
}
}
@ -249,3 +288,17 @@ nsDOMNavigationTiming::GetUnloadEventEnd()
}
return 0;
}
bool
nsDOMNavigationTiming::IsTopLevelContentDocument() const
{
if (!mDocShell) {
return false;
}
nsCOMPtr<nsIDocShellTreeItem> rootItem;
Unused << mDocShell->GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
if (rootItem.get() != static_cast<nsIDocShellTreeItem*>(mDocShell.get())) {
return false;
}
return rootItem->ItemType() == nsIDocShellTreeItem::typeContent;
}

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

@ -9,8 +9,10 @@
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/TimeStamp.h"
class nsDocShell;
class nsIURI;
typedef unsigned long long DOMTimeMilliSec;
@ -26,7 +28,7 @@ public:
TYPE_RESERVED = 255,
};
nsDOMNavigationTiming();
explicit nsDOMNavigationTiming(nsDocShell* aDocShell);
NS_INLINE_DECL_REFCOUNTING(nsDOMNavigationTiming)
@ -120,6 +122,10 @@ private:
void Clear();
bool IsTopLevelContentDocument() const;
mozilla::WeakPtr<nsDocShell> mDocShell;
nsCOMPtr<nsIURI> mUnloadedURI;
nsCOMPtr<nsIURI> mLoadedURI;

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

@ -361,7 +361,7 @@ SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest,
// For a root document, DocShell would do these sort of things
// automatically. Since there is no DocShell for this wrapped SVG document,
// we must set it up manually.
RefPtr<nsDOMNavigationTiming> timing = new nsDOMNavigationTiming();
RefPtr<nsDOMNavigationTiming> timing = new nsDOMNavigationTiming(nullptr);
timing->NotifyNavigationStart(nsDOMNavigationTiming::DocShellState::eInactive);
viewer->SetNavigationTiming(timing);

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

@ -11348,5 +11348,68 @@
"kind": "enumerated",
"n_values": 99,
"description": "Count of which display items are being used by type id"
},
"TIME_TO_DOM_LOADING_MS": {
"alert_emails": ["wpan@mozilla.com"],
"expires_in_version": "60",
"kind": "exponential",
"high": 50000,
"n_buckets": 100,
"bug_numbers": [1344893],
"description": "Time in milliseconds from navigationStart to domLoading."
},
"TIME_TO_DOM_INTERACTIVE_MS": {
"alert_emails": ["wpan@mozilla.com"],
"expires_in_version": "60",
"kind": "exponential",
"high": 50000,
"n_buckets": 100,
"bug_numbers": [1344893],
"description": "Time in milliseconds from navigationStart to domInteractive."
},
"TIME_TO_DOM_CONTENT_LOADED_START_MS": {
"alert_emails": ["wpan@mozilla.com"],
"expires_in_version": "60",
"kind": "exponential",
"high": 50000,
"n_buckets": 100,
"bug_numbers": [1344893],
"description": "Time in milliseconds from navigationStart to domContentLoadedEventStart."
},
"TIME_TO_DOM_CONTENT_LOADED_END_MS": {
"alert_emails": ["wpan@mozilla.com"],
"expires_in_version": "60",
"kind": "exponential",
"high": 50000,
"n_buckets": 100,
"bug_numbers": [1344893],
"description": "Time in milliseconds from navigationStart to domContentLoadedEventEnd."
},
"TIME_TO_DOM_COMPLETE_MS": {
"alert_emails": ["wpan@mozilla.com"],
"expires_in_version": "60",
"kind": "exponential",
"high": 50000,
"n_buckets": 100,
"bug_numbers": [1344893],
"description": "Time in milliseconds from navigationStart to domComplete."
},
"TIME_TO_LOAD_EVENT_START_MS": {
"alert_emails": ["wpan@mozilla.com"],
"expires_in_version": "60",
"kind": "exponential",
"high": 50000,
"n_buckets": 100,
"bug_numbers": [1344893],
"description": "Time in milliseconds from navigationStart to loadEventStart."
},
"TIME_TO_LOAD_EVENT_END_MS": {
"alert_emails": ["wpan@mozilla.com"],
"expires_in_version": "60",
"kind": "exponential",
"high": 50000,
"n_buckets": 100,
"bug_numbers": [1344893],
"description": "Time in milliseconds from navigationStart to loadEventEnd."
}
}