Commit 9190ef1c authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding PLM UKM for body size

This tracks network and cache bytes and rounds them to a lower bounding
exponential bucket threshold before reporting them to UKM.

Bug: 723703
Change-Id: Ica14f0c7e396c9086e71f6cdc3c9b869cf75d0a8
Reviewed-on: https://chromium-review.googlesource.com/791529
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523533}
parent 1278739a
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "chrome/browser/page_load_metrics/observers/ukm_page_load_metrics_observer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
......@@ -10,6 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "components/metrics/net/network_metrics_provider.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_entry_builder.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
......@@ -150,6 +152,16 @@ void UkmPageLoadMetricsObserver::OnComplete(
RecordTimingMetrics(timing, info.source_id);
}
void UkmPageLoadMetricsObserver::OnLoadedResource(
const page_load_metrics::ExtraRequestCompleteInfo&
extra_request_complete_info) {
if (extra_request_complete_info.was_cached) {
cache_bytes_ += extra_request_complete_info.raw_body_bytes;
} else {
network_bytes_ += extra_request_complete_info.raw_body_bytes;
}
}
void UkmPageLoadMetricsObserver::RecordTimingMetrics(
const page_load_metrics::mojom::PageLoadTiming& timing,
ukm::SourceId source_id) {
......@@ -179,6 +191,12 @@ void UkmPageLoadMetricsObserver::RecordTimingMetrics(
builder.SetExperimental_PaintTiming_NavigationToFirstMeaningfulPaint(
timing.paint_timing->first_meaningful_paint.value().InMilliseconds());
}
// Use a bucket spacing factor of 1.3 for bytes.
builder.SetNet_CacheBytes(ukm::GetExponentialBucketMin(cache_bytes_, 1.3));
builder.SetNet_NetworkBytes(
ukm::GetExponentialBucketMin(network_bytes_, 1.3));
builder.Record(ukm::UkmRecorder::Get());
}
......
......@@ -75,6 +75,9 @@ class UkmPageLoadMetricsObserver
void OnComplete(const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info) override;
void OnLoadedResource(const page_load_metrics::ExtraRequestCompleteInfo&
extra_request_complete_info) override;
private:
// Records page load timing related metrics available in PageLoadTiming, such
// as first contentful paint.
......@@ -92,6 +95,11 @@ class UkmPageLoadMetricsObserver
net::NetworkQualityEstimator::NetworkQualityProvider* const
network_quality_provider_;
// The number of body (not header) prefilter bytes consumed by requests for
// the page.
int64_t cache_bytes_ = 0;
int64_t network_bytes_ = 0;
// Network quality estimates.
net::EffectiveConnectionType effective_connection_type_ =
net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
......
......@@ -15,6 +15,7 @@
#include "content/public/test/navigation_simulator.h"
#include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_quality_provider.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/metrics_proto/system_profile.pb.h"
......@@ -317,3 +318,64 @@ TEST_F(UkmPageLoadMetricsObserverTest, PageTransitionReload) {
ui::PAGE_TRANSITION_RELOAD);
}
}
TEST_F(UkmPageLoadMetricsObserverTest, BodySizeMetrics) {
NavigateAndCommit(GURL(kTestUrl1));
page_load_metrics::ExtraRequestCompleteInfo resources[] = {
// Cached request.
{GURL(kResourceUrl),
net::HostPortPair(),
-1 /* frame_tree_node_id */,
true /* was_cached */,
1024 * 20 /* raw_body_bytes */,
0 /* original_network_content_length */,
nullptr /* data_reduction_proxy_data */,
content::ResourceType::RESOURCE_TYPE_SCRIPT,
0,
{} /* load_timing_info */},
// Uncached non-proxied request.
{GURL(kResourceUrl),
net::HostPortPair(),
-1 /* frame_tree_node_id */,
false /* was_cached */,
1024 * 40 /* raw_body_bytes */,
1024 * 40 /* original_network_content_length */,
nullptr /* data_reduction_proxy_data */,
content::ResourceType::RESOURCE_TYPE_SCRIPT,
0,
{} /* load_timing_info */},
};
int64_t network_bytes = 0;
int64_t cache_bytes = 0;
for (const auto& request : resources) {
SimulateLoadedResource(request);
if (!request.was_cached) {
network_bytes += request.raw_body_bytes;
} else {
cache_bytes += request.raw_body_bytes;
}
}
// Simulate closing the tab.
DeleteContents();
int64_t bucketed_network_bytes =
ukm::GetExponentialBucketMin(network_bytes, 1.3);
int64_t bucketed_cache_bytes = ukm::GetExponentialBucketMin(cache_bytes, 1.3);
std::map<ukm::SourceId, ukm::mojom::UkmEntryPtr> merged_entries =
test_ukm_recorder().GetMergedEntriesByName(
internal::kUkmPageLoadEventName);
EXPECT_EQ(1ul, merged_entries.size());
for (const auto& kv : merged_entries) {
test_ukm_recorder().ExpectEntrySourceHasUrl(kv.second.get(),
GURL(kTestUrl1));
test_ukm_recorder().ExpectEntryMetric(kv.second.get(), "Net.NetworkBytes",
bucketed_network_bytes);
test_ukm_recorder().ExpectEntryMetric(kv.second.get(), "Net.CacheBytes",
bucketed_cache_bytes);
}
}
......@@ -9,6 +9,8 @@ component("metrics_cpp") {
"delegating_ukm_recorder.cc",
"delegating_ukm_recorder.h",
"metrics_export.h",
"metrics_utils.cc",
"metrics_utils.h",
"mojo_ukm_recorder.cc",
"mojo_ukm_recorder.h",
"ukm_entry_builder.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/metrics/public/cpp/metrics_utils.h"
#include <math.h>
#include <cmath>
namespace ukm {
int64_t GetExponentialBucketMin(int64_t sample, double bucket_spacing) {
if (sample <= 0) {
return 0;
}
// This is similar to the bucketing methodology used in histograms, but
// instead of iteratively calculating each bucket, this calculates the lower
// end of the specific bucket for network and cached bytes.
return std::ceil(std::pow(
bucket_spacing, std::floor(std::log(sample) / std::log(bucket_spacing))));
}
} // namespace ukm
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_METRICS_PUBLIC_CPP_METRICS_UTILS_H_
#define SERVICES_METRICS_PUBLIC_CPP_METRICS_UTILS_H_
#include <stdint.h>
#include "services/metrics/public/cpp/metrics_export.h"
namespace ukm {
// Calculates the exponential bucket |sample| falls in and returns the lower
// threshold of that bucket. |bucket_spacing| is the exponential spacing factor
// from one bucket to the next. Only returns a non-negative value.
int64_t METRICS_EXPORT GetExponentialBucketMin(int64_t sample,
double bucket_spacing);
} // namespace ukm
#endif // SERVICES_METRICS_PUBLIC_CPP_METRICS_UTILS_H_
......@@ -1193,6 +1193,13 @@ be describing additional metrics about the same event.
The |ui::PageTransition| for the main frame navigation of this page load.
</summary>
</metric>
<metric name="Net.CacheBytes">
<summary>
The total number of body bytes loaded from cache for all resources on the
page. This is rounded down to the nearest exponential bucket (with a
bucket spacing factor of 1.3).
</summary>
</metric>
<metric name="Net.DownstreamKbpsEstimate.OnNavigationStart">
<owner>tbansal@chromium.org</owner>
<summary>
......@@ -1228,6 +1235,13 @@ be describing additional metrics about the same event.
navigation for this page load was initiated.
</summary>
</metric>
<metric name="Net.NetworkBytes">
<summary>
The total number of body bytes loaded from the network for all resources
on the page. This is rounded down to the nearest exponential bucket (with
a bucket spacing factor of 1.3).
</summary>
</metric>
<metric name="Net.TransportRttEstimate.OnNavigationStart">
<summary>
The transport round trip time estimate for this page load, at the time the
......
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