Commit 3b9ba02c authored by zhenw's avatar zhenw Committed by Commit bot

Add PLT measurement to Resource Prefetching for Mobile Web

histograms.xml is also updated. This update includes the ones for PLT measurement.

BUG=405690, 406200

Review URL: https://codereview.chromium.org/632033002

Cr-Commit-Position: refs/heads/master@{#302505}
parent 94a58f5d
......@@ -14,8 +14,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
using base::FieldTrialList;
......@@ -164,7 +164,7 @@ NavigationID::NavigationID(const NavigationID& other)
NavigationID::NavigationID(content::WebContents* web_contents)
: render_process_id(web_contents->GetRenderProcessHost()->GetID()),
render_frame_id(web_contents->GetRenderViewHost()->GetRoutingID()),
render_frame_id(web_contents->GetMainFrame()->GetRoutingID()),
main_frame_url(web_contents->GetURL()) {
}
......
......@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
......@@ -34,6 +35,7 @@
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/web_contents.h"
#include "net/base/mime_util.h"
#include "net/base/network_change_notifier.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context_getter.h"
......@@ -90,6 +92,49 @@ void RecordNavigationEvent(NavigationEvent event) {
NAVIGATION_EVENT_COUNT);
}
// These are additional connection types for
// net::NetworkChangeNotifier::ConnectionType. They have negative values in case
// the original network connection types expand.
enum AdditionalConnectionType {
CONNECTION_ALL = -2,
CONNECTION_CELLULAR = -1
};
std::string GetNetTypeStr() {
switch (net::NetworkChangeNotifier::GetConnectionType()) {
case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
return "Ethernet";
case net::NetworkChangeNotifier::CONNECTION_WIFI:
return "WiFi";
case net::NetworkChangeNotifier::CONNECTION_2G:
return "2G";
case net::NetworkChangeNotifier::CONNECTION_3G:
return "3G";
case net::NetworkChangeNotifier::CONNECTION_4G:
return "4G";
case net::NetworkChangeNotifier::CONNECTION_NONE:
return "None";
case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH:
return "Bluetooth";
case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
default:
break;
}
return "Unknown";
}
void ReportPrefetchedNetworkType(int type) {
UMA_HISTOGRAM_SPARSE_SLOWLY(
"ResourcePrefetchPredictor.NetworkType.Prefetched",
type);
}
void ReportNotPrefetchedNetworkType(int type) {
UMA_HISTOGRAM_SPARSE_SLOWLY(
"ResourcePrefetchPredictor.NetworkType.NotPrefetched",
type);
}
} // namespace
namespace predictors {
......@@ -525,6 +570,8 @@ void ResourcePrefetchPredictor::OnNavigationComplete(
RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_TRACKED_URL);
// Report any stats.
base::TimeDelta plt = base::TimeTicks::Now() - navigation_id.creation_time;
ReportPageLoadTimeStats(plt);
if (prefetch_manager_.get()) {
ResultsMap::iterator results_it = results_map_.find(navigation_id);
bool have_prefetch_results = results_it != results_map_.end();
......@@ -534,6 +581,17 @@ void ResourcePrefetchPredictor::OnNavigationComplete(
ReportAccuracyStats(results_it->second->key_type,
*(nav_it->second),
results_it->second->requests.get());
ReportPageLoadTimePrefetchStats(
plt,
true,
base::Bind(&ReportPrefetchedNetworkType),
results_it->second->key_type);
} else {
ReportPageLoadTimePrefetchStats(
plt,
false,
base::Bind(&ReportNotPrefetchedNetworkType),
PREFETCH_KEY_TYPE_URL);
}
} else {
scoped_ptr<ResourcePrefetcher::RequestVector> requests(
......@@ -1003,7 +1061,81 @@ void ResourcePrefetchPredictor::LearnNavigation(
}
////////////////////////////////////////////////////////////////////////////////
// Accuracy measurement.
// Page load time and accuracy measurement.
// This is essentially UMA_HISTOGRAM_MEDIUM_TIMES, but it avoids using the
// STATIC_HISTOGRAM_POINTER_BLOCK in UMA_HISTOGRAM definitions.
#define RPP_HISTOGRAM_MEDIUM_TIMES(name, page_load_time) \
do { \
base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( \
name, \
base::TimeDelta::FromMilliseconds(10), \
base::TimeDelta::FromMinutes(3), \
50, \
base::HistogramBase::kUmaTargetedHistogramFlag); \
histogram->AddTime(page_load_time); \
} while (0)
void ResourcePrefetchPredictor::ReportPageLoadTimeStats(
base::TimeDelta plt) const {
net::NetworkChangeNotifier::ConnectionType connection_type =
net::NetworkChangeNotifier::GetConnectionType();
RPP_HISTOGRAM_MEDIUM_TIMES("ResourcePrefetchPredictor.PLT", plt);
RPP_HISTOGRAM_MEDIUM_TIMES(
"ResourcePrefetchPredictor.PLT_" + GetNetTypeStr(), plt);
if (net::NetworkChangeNotifier::IsConnectionCellular(connection_type))
RPP_HISTOGRAM_MEDIUM_TIMES("ResourcePrefetchPredictor.PLT_Cellular", plt);
}
void ResourcePrefetchPredictor::ReportPageLoadTimePrefetchStats(
base::TimeDelta plt,
bool prefetched,
base::Callback<void(int)> report_network_type_callback,
PrefetchKeyType key_type) const {
net::NetworkChangeNotifier::ConnectionType connection_type =
net::NetworkChangeNotifier::GetConnectionType();
bool on_cellular =
net::NetworkChangeNotifier::IsConnectionCellular(connection_type);
report_network_type_callback.Run(CONNECTION_ALL);
report_network_type_callback.Run(connection_type);
if (on_cellular)
report_network_type_callback.Run(CONNECTION_CELLULAR);
std::string prefetched_str;
if (prefetched)
prefetched_str = "Prefetched";
else
prefetched_str = "NotPrefetched";
RPP_HISTOGRAM_MEDIUM_TIMES(
"ResourcePrefetchPredictor.PLT." + prefetched_str, plt);
RPP_HISTOGRAM_MEDIUM_TIMES(
"ResourcePrefetchPredictor.PLT." + prefetched_str + "_" + GetNetTypeStr(),
plt);
if (on_cellular) {
RPP_HISTOGRAM_MEDIUM_TIMES(
"ResourcePrefetchPredictor.PLT." + prefetched_str + "_Cellular", plt);
}
if (!prefetched)
return;
std::string type =
key_type == PREFETCH_KEY_TYPE_HOST ? "Host" : "Url";
RPP_HISTOGRAM_MEDIUM_TIMES(
"ResourcePrefetchPredictor.PLT.Prefetched." + type, plt);
RPP_HISTOGRAM_MEDIUM_TIMES(
"ResourcePrefetchPredictor.PLT.Prefetched." + type + "_"
+ GetNetTypeStr(),
plt);
if (on_cellular) {
RPP_HISTOGRAM_MEDIUM_TIMES(
"ResourcePrefetchPredictor.PLT.Prefetched." + type + "_Cellular",
plt);
}
}
void ResourcePrefetchPredictor::ReportAccuracyStats(
PrefetchKeyType key_type,
......@@ -1217,6 +1349,7 @@ void ResourcePrefetchPredictor::ReportPredictedAccuracyStatsHelper(
prefetch_network * 100.0 / total_resources_fetched_from_network);
}
#undef RPP_HISTOGRAM_MEDIUM_TIMES
#undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE
#undef RPP_PREDICTED_HISTOGRAM_COUNTS
}
......
......@@ -264,6 +264,16 @@ class ResourcePrefetchPredictor
size_t max_data_map_size,
PrefetchDataMap* data_map);
// Reports overall page load time.
void ReportPageLoadTimeStats(base::TimeDelta plt) const;
// Reports page load time for prefetched and not prefetched pages
void ReportPageLoadTimePrefetchStats(
base::TimeDelta plt,
bool prefetched,
base::Callback<void(int)> report_network_type_callback,
PrefetchKeyType key_type) const;
// Reports accuracy by comparing prefetched resources with resources that are
// actually used by the page.
void ReportAccuracyStats(PrefetchKeyType key_type,
......
......@@ -28411,6 +28411,24 @@ Therefore, the affected-histogram name has to have at least one dot in it.
</summary>
</histogram>
<histogram name="ResourcePrefetchPredictor.NetworkType"
enum="ResourcePrefetchPredictorNetworkType">
<owner>zhenw@chromium.org</owner>
<summary>
Records the number of pages on each type of network after a page is loaded.
</summary>
</histogram>
<histogram name="ResourcePrefetchPredictor.PLT" units="milliseconds">
<owner>zhenw@chromium.org</owner>
<summary>
Page load time. It starts from when the main frame URL request is sent out
to when the main frame document load is completed.
This is recorded for both prefetched and non-prefetched pages.
</summary>
</histogram>
<histogram name="ResourcePrefetchPredictor.PredictedPrefetchCount">
<obsolete>
Deprecated 01/2013. Replaced with specific ones for Url and Host.
......@@ -52231,6 +52249,19 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="2" label="NAVIGATION_STATUS_ABANDONED"/>
</enum>
<enum name="ResourcePrefetchPredictorNetworkType" type="int">
<int value="-2" label="CONNECTION_ALL"/>
<int value="-1" label="CONNECTION_CELLULAR"/>
<int value="0" label="CONNECTION_UNKNOWN"/>
<int value="1" label="CONNECTION_ETHERNET"/>
<int value="2" label="CONNECTION_WIFI"/>
<int value="3" label="CONNECTION_2G"/>
<int value="4" label="CONNECTION_3G"/>
<int value="5" label="CONNECTION_4G"/>
<int value="6" label="CONNECTION_NONE"/>
<int value="7" label="CONNECTION_BLUETOOTH"/>
</enum>
<enum name="ResourcePrefetchPredictorReportingEvent" type="int">
<int value="0" label="REPORTING_EVENT_ALL_HISTORY_CLEARED"/>
<int value="1" label="REPORTING_EVENT_PARTIAL_HISTORY_CLEARED"/>
......@@ -58647,6 +58678,48 @@ To add a new entry, add it with any value and run test to compute valid value.
<affected-histogram name="Event.Latency.Renderer2"/>
</histogram_suffixes>
<histogram_suffixes name="ResourcePrefetchPredictorNetworkTypePrefetch"
separator=".">
<suffix name="NotPrefetched"
label="Number of non-prefetched pages on each type of network."/>
<suffix name="Prefetched"
label="Number of prefetched pages on each type of network."/>
<affected-histogram name="ResourcePrefetchPredictor.NetworkType"/>
</histogram_suffixes>
<histogram_suffixes name="ResourcePrefetchPredictorPLTNetworkTypes">
<suffix name="2G" label="Page load time in 2G network."/>
<suffix name="3G" label="Page load time in 3G network."/>
<suffix name="4G" label="Page load time in 4G network."/>
<suffix name="Bluetooth" label="Page load time in bluetooth network."/>
<suffix name="Cellular" label="Page load time in cellular network."/>
<suffix name="Ethernet" label="Page load time in Ethernet."/>
<suffix name="None" label="Page load time without network connection."/>
<suffix name="Unknown" label="Page load time in unknown type of network."/>
<suffix name="WiFi" label="Page load time in WiFi network."/>
<affected-histogram name="ResourcePrefetchPredictor.PLT"/>
<affected-histogram name="ResourcePrefetchPredictor.PLT.NotPrefetched"/>
<affected-histogram name="ResourcePrefetchPredictor.PLT.Prefetched"/>
<affected-histogram name="ResourcePrefetchPredictor.PLT.Prefetched.Host"/>
<affected-histogram name="ResourcePrefetchPredictor.PLT.Prefetched.Url"/>
</histogram_suffixes>
<histogram_suffixes name="ResourcePrefetchPredictorPLTPrefetch" separator=".">
<suffix name="NotPrefetched"
label="Page load time for non-prefetched pages."/>
<suffix name="Prefetched" label="Page load time for prefetched pages."/>
<affected-histogram name="ResourcePrefetchPredictor.PLT"/>
</histogram_suffixes>
<histogram_suffixes name="ResourcePrefetchPredictorPLTPrefetchType"
separator=".">
<suffix name="Host"
label="Page load time for prefetched pages based on main frame host."/>
<suffix name="Url"
label="Page load time for prefetched pages based on main frame URL."/>
<affected-histogram name="ResourcePrefetchPredictor.PLT.Prefetched"/>
</histogram_suffixes>
<histogram_suffixes name="ResourcePrefetchPredictorPredictedStatsVariedMax">
<suffix name="25"
label="Covers statistics when the maximum subresources that can be
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment