Commit ebcceaf6 authored by Rodney Ding's avatar Rodney Ding Committed by Commit Bot

Add UKM for max JS Bytes

Captures maximum decoded byte sizes of all JS resources per page load.

Bug: 1033626
Change-Id: Ib4717fcdcfab6cdc81f8a0416dc3227643a5fdd4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2005812
Commit-Queue: Rodney Ding <rodneyding@google.com>
Reviewed-by: default avatarJohn Delaney <johnidel@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarJason Chase <chasej@chromium.org>
Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735910}
parent cea4019c
......@@ -230,6 +230,8 @@ void UkmPageLoadMetricsObserver::OnResourceDataUseObserved(
continue;
if (blink::IsSupportedJavascriptMimeType(resource->mime_type)) {
js_decoded_bytes_ += resource->decoded_body_length;
if (resource->decoded_body_length > js_max_decoded_bytes_)
js_max_decoded_bytes_ = resource->decoded_body_length;
}
if (resource->cache_type !=
page_load_metrics::mojom::CacheType::kNotCached) {
......@@ -362,6 +364,8 @@ void UkmPageLoadMetricsObserver::RecordTimingMetrics(
// Use a bucket spacing factor of 10 for JS bytes.
builder.SetNet_JavaScriptBytes(
ukm::GetExponentialBucketMin(js_decoded_bytes_, 10));
builder.SetNet_JavaScriptMaxBytes(
ukm::GetExponentialBucketMin(js_max_decoded_bytes_, 10));
if (main_frame_timing_)
ReportMainResourceTimingMetrics(timing, &builder);
......
......@@ -137,6 +137,9 @@ class UkmPageLoadMetricsObserver
// Sum of decoded body lengths of JS resources in bytes.
int64_t js_decoded_bytes_ = 0;
// Max decoded body length of JS resources in bytes.
int64_t js_max_decoded_bytes_ = 0;
// Network quality estimates.
net::EffectiveConnectionType effective_connection_type_ =
net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
......
......@@ -1213,7 +1213,7 @@ TEST_F(UkmPageLoadMetricsObserverTest, JSSizeMetrics) {
DeleteContents();
// Metrics look at decoded body length.
// 30 + 50 = 80 kilobytes
// 30 + 50 = 80 kilobytes.
int64_t bucketed_network_js_bytes =
ukm::GetExponentialBucketMin(80 * 1024, 10);
......@@ -1230,6 +1230,57 @@ TEST_F(UkmPageLoadMetricsObserverTest, JSSizeMetrics) {
}
}
TEST_F(UkmPageLoadMetricsObserverTest, JSMaxSizeMetrics) {
NavigateAndCommit(GURL(kTestUrl1));
std::vector<page_load_metrics::mojom::ResourceDataUpdatePtr> resources;
// 30 kilobytes after decoding.
resources.push_back(CreateResource(true /* was_cached */, 0 /* delta_bytes */,
20 * 1024 /* encoded_body_length */,
30 * 1024 /* decoded_body_length */,
true /* is_complete */));
// 500 kilobytes after decoding.
resources.push_back(CreateResource(
false /* was_cached */, 400 * 1024 /* delta_bytes */,
400 * 1024 /* encoded_body_length */,
500 * 1024 /* decoded_body_length */, true /* is_complete */));
// 120 kilobytes after decoding, not JS.
resources.push_back(CreateResource(
false /* was_cached */, 40 * 1024 /* delta_bytes */,
100 * 1024 /* encoded_body_length */,
120 * 1024 /* decoded_body_length */, true /* is_complete */));
resources[0]->mime_type = "application/javascript";
resources[1]->mime_type = "application/javascript";
resources[2]->mime_type = "test";
tester()->SimulateResourceDataUseUpdate(resources);
// Simulate closing the tab.
DeleteContents();
// Metrics look at max decoded body length.
// max(30,500) = 500 kilobytes.
int64_t bucketed_network_js_max_bytes =
ukm::GetExponentialBucketMin(500 * 1024, 10);
std::map<ukm::SourceId, ukm::mojom::UkmEntryPtr> merged_entries =
tester()->test_ukm_recorder().GetMergedEntriesByName(
PageLoad::kEntryName);
EXPECT_EQ(1ul, merged_entries.size());
for (const auto& kv : merged_entries) {
tester()->test_ukm_recorder().ExpectEntrySourceHasUrl(kv.second.get(),
GURL(kTestUrl1));
tester()->test_ukm_recorder().ExpectEntryMetric(
kv.second.get(), "Net.JavaScriptMaxBytes",
bucketed_network_js_max_bytes);
}
}
TEST_F(UkmPageLoadMetricsObserverTest, CpuTimeMetrics) {
NavigateAndCommit(GURL(kTestUrl1));
......
......@@ -6956,6 +6956,14 @@ be describing additional metrics about the same event.
bytes up until the page/app is backgrounded.
</summary>
</metric>
<metric name="Net.JavaScriptMaxBytes">
<summary>
The max of decoded body lengths of all JavaScript resouces that completed
loading on the page. This is rounded down to the nearest exponential
bucket (with a bucket spacing factor of 10). On mobile this only records
bytes up until the page/app is backgrounded.
</summary>
</metric>
<metric name="Net.NetworkBytes">
<obsolete>
Deprecated 03/2019 in favor of Net.NetworkBytes2.
......
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