Commit 255eda8f authored by Peiyong Lin's avatar Peiyong Lin Committed by Commit Bot

[GRC] Add UKM report for background tabs audibility.

This patch adds UKM reports for background tabs audibility. Currently we
collect audible signal at frame-level, both main frame and child frames
are using the same source id to report UKM.

BUG=731270, 753486

Change-Id: I461ea2d8a6ef742fcb2850250ad68a5b71c89600
Reviewed-on: https://chromium-review.googlesource.com/604515
Commit-Queue: lpy <lpy@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarOystein Eftevaag <oysteine@chromium.org>
Reviewed-by: default avatarZhen Wang <zhenw@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496491}
parent ee3738ff
......@@ -104,13 +104,23 @@ void MetricsCollector::OnFramePropertyChanged(
if (frame_data.last_audible_time + kMaxAudioSlientTime < now) {
MetricsReportRecord& record =
metrics_report_record_map_[web_contents_cu->id()];
auto duration =
now -
web_contents_data_map_[web_contents_cu->id()].last_invisible_time;
if (!record.first_audible_after_backgrounded_reported) {
const WebContentsData& web_contents_data =
web_contents_data_map_[web_contents_cu->id()];
HEURISTICS_HISTOGRAM(kTabFromBackgroundedToFirstAudioStartsUMA,
now - web_contents_data.last_invisible_time);
duration);
record.first_audible_after_backgrounded_reported = true;
}
bool is_main_frame = frame_cu->IsMainFrame();
ReportAudibilityUKMIfNeeded(
web_contents_cu,
is_main_frame
? &record.main_frame_first_audible_after_backgrounded_reported
: &record.child_frame_first_audible_after_backgrounded_reported,
is_main_frame, duration);
}
}
}
......@@ -239,6 +249,25 @@ void MetricsCollector::RecordCPUUsageForUkm(
.Record(coordination_unit_manager().ukm_recorder());
}
void MetricsCollector::ReportAudibilityUKMIfNeeded(
const WebContentsCoordinationUnitImpl* web_contents_cu,
bool* reported,
bool is_main_frame,
base::TimeDelta duration) {
if (*reported)
return;
int64_t ukm_source_id = -1;
if (!web_contents_cu->GetProperty(mojom::PropertyType::kUKMSourceId,
&ukm_source_id)) {
return;
}
ukm::builders::TabManager_Background_FirstAudioStarts(ukm_source_id)
.SetIsMainFrame(is_main_frame)
.SetTimeFromBackgrounded(duration.InMilliseconds())
.Record(coordination_unit_manager().ukm_recorder());
*reported = true;
}
void MetricsCollector::UpdateUkmSourceIdForWebContents(
const CoordinationUnitID& web_contents_cu_id,
ukm::SourceId ukm_source_id) {
......@@ -273,7 +302,9 @@ MetricsCollector::MetricsReportRecord::MetricsReportRecord()
first_favicon_updated_after_backgrounded_reported(false),
first_non_persistent_notification_created_after_backgrounded_reported(
false),
first_title_updated_after_backgrounded_reported(false) {}
first_title_updated_after_backgrounded_reported(false),
main_frame_first_audible_after_backgrounded_reported(false),
child_frame_first_audible_after_backgrounded_reported(false) {}
void MetricsCollector::MetricsReportRecord::Reset() {
first_alert_fired_after_backgrounded_reported = false;
......@@ -281,6 +312,8 @@ void MetricsCollector::MetricsReportRecord::Reset() {
first_favicon_updated_after_backgrounded_reported = false;
first_non_persistent_notification_created_after_backgrounded_reported = false;
first_title_updated_after_backgrounded_reported = false;
main_frame_first_audible_after_backgrounded_reported = false;
child_frame_first_audible_after_backgrounded_reported = false;
}
} // namespace resource_coordinator
......@@ -54,11 +54,16 @@ class MetricsCollector : public CoordinationUnitGraphObserver {
struct MetricsReportRecord {
MetricsReportRecord();
void Reset();
// UMA histograms report.
bool first_alert_fired_after_backgrounded_reported;
bool first_audible_after_backgrounded_reported;
bool first_favicon_updated_after_backgrounded_reported;
bool first_non_persistent_notification_created_after_backgrounded_reported;
bool first_title_updated_after_backgrounded_reported;
// UKM collection report.
bool main_frame_first_audible_after_backgrounded_reported;
bool child_frame_first_audible_after_backgrounded_reported;
};
struct FrameData {
......@@ -80,6 +85,11 @@ class MetricsCollector : public CoordinationUnitGraphObserver {
void RecordCPUUsageForUkm(const CoordinationUnitID& web_contents_cu_id,
double cpu_usage,
size_t num_coresident_tabs);
void ReportAudibilityUKMIfNeeded(
const WebContentsCoordinationUnitImpl* web_contents_cu,
bool* reported,
bool is_main_frame,
base::TimeDelta duration);
void UpdateUkmSourceIdForWebContents(
const CoordinationUnitID& web_contents_cu_id,
ukm::SourceId ukm_source_id);
......
......@@ -1086,4 +1086,24 @@ be describing additional metrics about the same event.
</metric>
</event>
<event name="TabManager.Background.FirstAudioStarts">
<owner>chrisha@chromium.org</owner>
<owner>lpy@chromium.org</owner>
<summary>
Collects the duration in MS from when the tab is backgrounded to when audio
starts to play. Only recorded when the tab is in the background.
</summary>
<metric name="IsMainFrame">
<summary>
Indicates whether the the audio stream belongs to the main frame.
</summary>
</metric>
<metric name="TimeFromBackgrounded">
<summary>
Duration in MS from when the tab is backgrounded to when audio starts to
play. Only recorded when the tab is in the background.
</summary>
</metric>
</event>
</ukm-configuration>
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