Bug 1344893 - Part 2: Add time to first byte metric. r?smaug
MozReview-Commit-ID: 6a30Xofr6p1
--- a/dom/performance/PerformanceTiming.cpp
+++ b/dom/performance/PerformanceTiming.cpp
@@ -1,16 +1,18 @@
/* -*- 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 "PerformanceTiming.h"
#include "mozilla/dom/PerformanceTimingBinding.h"
+#include "mozilla/Telemetry.h"
+#include "nsIDocument.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PerformanceTiming, mPerformance)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PerformanceTiming, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PerformanceTiming, Release)
@@ -42,16 +44,22 @@ PerformanceTiming::PerformanceTiming(Per
if (aHttpChannel) {
mTimingAllowed = CheckAllowedOrigin(aHttpChannel, aChannel);
bool redirectsPassCheck = false;
aChannel->GetAllRedirectsPassTimingAllowCheck(&redirectsPassCheck);
mReportCrossOriginRedirect = mTimingAllowed && redirectsPassCheck;
}
InitializeTimingInfo(aChannel);
+
+ // Do not collect for subresources and non-top-level content document.
+ if (!aHttpChannel && IsTopLevelContentDocument()) {
+ Telemetry::Accumulate(Telemetry::TIME_TO_RESPONSE_START_MS,
+ ResponseStartHighRes() - mZeroTime);
+ }
}
// Copy the timing info from the channel so we don't need to keep the channel
// alive just to get the timestamps.
void
PerformanceTiming::InitializeTimingInfo(nsITimedChannel* aChannel)
{
if (aChannel) {
@@ -352,10 +360,20 @@ PerformanceTiming::IsInitialized() const
}
JSObject*
PerformanceTiming::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
{
return PerformanceTimingBinding::Wrap(cx, this, aGivenProto);
}
+bool
+PerformanceTiming::IsTopLevelContentDocument() const
+{
+ nsCOMPtr<nsIDocument> document = mPerformance->GetDocumentIfCurrent();
+ if (!document) {
+ return false;
+ }
+ return document->GetTopLevelContentDocument() == document;
+}
+
} // dom namespace
} // mozilla namespace
--- a/dom/performance/PerformanceTiming.h
+++ b/dom/performance/PerformanceTiming.h
@@ -235,16 +235,18 @@ public:
}
private:
~PerformanceTiming();
bool IsInitialized() const;
void InitializeTimingInfo(nsITimedChannel* aChannel);
+ bool IsTopLevelContentDocument() const;
+
RefPtr<Performance> mPerformance;
DOMHighResTimeStamp mFetchStart;
// This is an offset that will be added to each timing ([ms] resolution).
// There are only 2 possible values: (1) logicaly equal to navigationStart
// TimeStamp (results are absolute timstamps - wallclock); (2) "0" (results
// are relative to the navigation start).
DOMHighResTimeStamp mZeroTime;
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -11334,10 +11334,19 @@
"TIME_TO_LOAD_EVENT_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."
+ },
+ "TIME_TO_RESPONSE_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 responseStart."
}
}