Commit 2779ce87 authored by Hongbo Song's avatar Hongbo Song Committed by Commit Bot

Record PageForegroundSession Input Delay UKM.

We need to know total input delay and number of inputs for each page visit. To better align with `PageForegroundSession.ForegroundDuration`, we plan to add TotalInputDelay, TotalAdjustedInputDelay,  NumInputEvents UKM for each PageForegroundSession.

UKM privacy review: https://docs.google.com/document/d/1F4ZImXniH_YZA6Z4FcONHbwe-ze0q0Bp0W6RKxDf-Kg/edit?usp=sharing

Change-Id: I010d8b7b35af3d3f611f8a29542dd10956c2ab7f
Bug: 1069304
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144362
Commit-Queue: Hongbo Song <hbsong@google.com>
Reviewed-by: default avatarBryan McQuade <bmcquade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758228}
parent c75a03a3
......@@ -13,7 +13,8 @@
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source.h"
ForegroundDurationUKMObserver::ForegroundDurationUKMObserver() {}
ForegroundDurationUKMObserver::ForegroundDurationUKMObserver()
: last_page_input_timing_(page_load_metrics::mojom::InputTiming()) {}
ForegroundDurationUKMObserver::~ForegroundDurationUKMObserver() {}
......@@ -77,9 +78,27 @@ void ForegroundDurationUKMObserver::RecordUkmIfInForeground(
if (!currently_in_foreground_)
return;
base::TimeDelta foreground_duration = end_time - last_time_shown_;
ukm::builders::PageForegroundSession ukm_builder(source_id_);
ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get();
ukm::builders::PageForegroundSession(source_id_)
.SetForegroundDuration(foreground_duration.InMilliseconds())
.Record(ukm_recorder);
ukm_builder.SetForegroundDuration(foreground_duration.InMilliseconds());
RecordInputTimingMetrics(&ukm_builder);
ukm_builder.Record(ukm_recorder);
currently_in_foreground_ = false;
}
void ForegroundDurationUKMObserver::RecordInputTimingMetrics(
ukm::builders::PageForegroundSession* ukm_builder) {
ukm_builder
->SetForegroundNumInputEvents(
GetDelegate().GetPageInputTiming().num_input_events -
last_page_input_timing_.num_input_events)
.SetForegroundTotalInputDelay(
(GetDelegate().GetPageInputTiming().total_input_delay -
last_page_input_timing_.total_input_delay)
.InMilliseconds())
.SetForegroundTotalAdjustedInputDelay(
(GetDelegate().GetPageInputTiming().total_adjusted_input_delay -
last_page_input_timing_.total_adjusted_input_delay)
.InMilliseconds());
last_page_input_timing_ = GetDelegate().GetPageInputTiming();
}
\ No newline at end of file
......@@ -7,6 +7,8 @@
#include "base/time/time.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer.h"
#include "components/page_load_metrics/common/page_load_metrics.mojom.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
// Observer responsible for appending previews information to the PLM UKM
......@@ -35,7 +37,10 @@ class ForegroundDurationUKMObserver
bool currently_in_foreground_ = false;
base::TimeTicks last_time_shown_;
ukm::SourceId source_id_ = ukm::kInvalidSourceId;
page_load_metrics::mojom::InputTiming last_page_input_timing_;
void RecordUkmIfInForeground(base::TimeTicks end_time);
void RecordInputTimingMetrics(
ukm::builders::PageForegroundSession* ukm_builder);
DISALLOW_COPY_AND_ASSIGN(ForegroundDurationUKMObserver);
};
......
......@@ -47,8 +47,8 @@ class ForegroundDurationUKMObserverBrowserTest : public InProcessBrowserTest {
for (auto* entry :
test_ukm_recorder_->GetEntriesByName(UkmEntry::kEntryName)) {
auto* source = test_ukm_recorder_->GetSourceForSourceId(entry->source_id);
if (source && source->url() == url) {
test_ukm_recorder_->EntryHasMetric(entry, metric_name);
if (source && source->url() == url &&
test_ukm_recorder_->EntryHasMetric(entry, metric_name)) {
count++;
}
}
......@@ -80,6 +80,9 @@ IN_PROC_BROWSER_TEST_F(ForegroundDurationUKMObserverBrowserTest, RecordSimple) {
ui_test_utils::NavigateToURL(browser(), url);
CloseAllTabs();
ExpectMetricCountForUrl(url, "ForegroundDuration", 1);
ExpectMetricCountForUrl(url, "ForegroundNumInputEvents", 1);
ExpectMetricCountForUrl(url, "ForegroundTotalInputDelay", 1);
ExpectMetricCountForUrl(url, "ForegroundTotalAdjustedInputDelay", 1);
}
IN_PROC_BROWSER_TEST_F(ForegroundDurationUKMObserverBrowserTest, TabSwitching) {
......@@ -102,5 +105,11 @@ IN_PROC_BROWSER_TEST_F(ForegroundDurationUKMObserverBrowserTest, TabSwitching) {
tab_strip_model->ActivateTabAt(1, {TabStripModel::GestureType::kOther});
tab_strip_model->CloseAllTabs();
ExpectMetricCountForUrl(url1, "ForegroundDuration", 3);
ExpectMetricCountForUrl(url1, "ForegroundNumInputEvents", 3);
ExpectMetricCountForUrl(url1, "ForegroundTotalInputDelay", 3);
ExpectMetricCountForUrl(url1, "ForegroundTotalAdjustedInputDelay", 3);
ExpectMetricCountForUrl(url2, "ForegroundDuration", 3);
ExpectMetricCountForUrl(url2, "ForegroundNumInputEvents", 3);
ExpectMetricCountForUrl(url2, "ForegroundTotalInputDelay", 3);
ExpectMetricCountForUrl(url2, "ForegroundTotalAdjustedInputDelay", 3);
}
......@@ -7108,6 +7108,62 @@ be describing additional metrics about the same event.
</history>
</aggregation>
</metric>
<metric name="ForegroundNumInputEvents">
<summary>
The number of Input Events, recorded each time the page is backgrounded.
</summary>
<aggregation>
<history>
<index fields="profile.country"/>
<index fields="profile.country,profile.system_ram"/>
<index fields="profile.is_dominant_version"/>
<index fields="profile.is_latest_version"/>
<index fields="profile.system_ram"/>
<statistics>
<quantiles type="std-percentiles"/>
</statistics>
</history>
</aggregation>
</metric>
<metric name="ForegroundTotalAdjustedInputDelay">
<summary>
sum(max(Input Delay - 50, 0)), recorded each time the page is
backgrounded. The Input Delay refers to the duration between the hardware
timestamp and the start of event processing on the main thread for the
meaningful input. In ms.
</summary>
<aggregation>
<history>
<index fields="profile.country"/>
<index fields="profile.country,profile.system_ram"/>
<index fields="profile.is_dominant_version"/>
<index fields="profile.is_latest_version"/>
<index fields="profile.system_ram"/>
<statistics>
<quantiles type="std-percentiles"/>
</statistics>
</history>
</aggregation>
</metric>
<metric name="ForegroundTotalInputDelay">
<summary>
sum(Input Delay), recorded each time the page is backgrounded. The Input
Delay refers to the duration between the hardware timestamp and the start
of event processing on the main thread for the meaningful input. In ms.
</summary>
<aggregation>
<history>
<index fields="profile.country"/>
<index fields="profile.country,profile.system_ram"/>
<index fields="profile.is_dominant_version"/>
<index fields="profile.is_latest_version"/>
<index fields="profile.system_ram"/>
<statistics>
<quantiles type="std-percentiles"/>
</statistics>
</history>
</aggregation>
</metric>
</event>
<event name="PageInfoBubble">
......
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