From 21e320dce38776d1088f89fa028df6cb6ab46f19 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Tue, 12 Oct 2021 09:03:56 +0000 Subject: [PATCH] Bug 1678373 - Add telemetry probes for audible and muted media. r=alwu data-review=chutten Differential Revision: https://phabricator.services.mozilla.com/D125694 --- .../chrome/test_accumulated_play_time.html | 36 +++++++++++++++++-- dom/media/utils/TelemetryProbesReporter.cpp | 12 +++++-- toolkit/components/telemetry/Histograms.json | 26 ++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/dom/media/test/chrome/test_accumulated_play_time.html b/dom/media/test/chrome/test_accumulated_play_time.html index 4a39ea807e76..05f99cca0a09 100644 --- a/dom/media/test/chrome/test_accumulated_play_time.html +++ b/dom/media/test/chrome/test_accumulated_play_time.html @@ -16,9 +16,22 @@ * - VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE * - VIDEO_VISIBLE_PLAY_TIME_MS * - MEDIA_PLAY_TIME_MS + * - MUTED_PLAY_TIME_PERCENT + * - AUDIBLE_PLAY_TIME_PERCENT */ -const videoHistNames = ["VIDEO_PLAY_TIME_MS", "VIDEO_HIDDEN_PLAY_TIME_MS"]; -const videoKeyedHistNames = ["VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE", "VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE", "VIDEO_VISIBLE_PLAY_TIME_MS"]; +const videoHistNames = [ + "VIDEO_PLAY_TIME_MS", + "VIDEO_HIDDEN_PLAY_TIME_MS" +]; +const videoKeyedHistNames = [ + "VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE", + "VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE", + "VIDEO_VISIBLE_PLAY_TIME_MS" +]; +const audioKeyedHistNames = [ + "MUTED_PLAY_TIME_PERCENT", + "AUDIBLE_PLAY_TIME_PERCENT" +]; add_task(async function setTestPref() { await SpecialPowers.pushPrefEnv({ @@ -466,6 +479,25 @@ async function checkReportedTelemetry(media, reportExpected, hasVideo) { ok(!reportExpected, "MEDIA_PLAY_TIME_MS should always be reported if a report is expected"); } } + + for (const name of audioKeyedHistNames) { + try { + const hist = SpecialPowers.Services.telemetry.getKeyedHistogramById(name); + const items = Object.entries(hist.snapshot()); + if (items.length > 0) { + for (const [key, value] of items) { + const entriesNums = Object.entries(value.values).length; + ok(reportExpected && entriesNums > 0, `Reported ${key} for ${name}`); + } + } else { + ok(!reportExpected, `No audio telemetry expected, none reported`); + } + // Avoid to pollute next test task. + hist.clear(); + } catch (e) { + ok(false , `keyed histogram '${name}' doesn't exist`); + } + } } function once(target, name) { diff --git a/dom/media/utils/TelemetryProbesReporter.cpp b/dom/media/utils/TelemetryProbesReporter.cpp index 4366db0f4599..7f770e9bae10 100644 --- a/dom/media/utils/TelemetryProbesReporter.cpp +++ b/dom/media/utils/TelemetryProbesReporter.cpp @@ -439,13 +439,13 @@ void TelemetryProbesReporter::ReportResultForVideo() { void TelemetryProbesReporter::ReportResultForAudio() { // Don't record telemetry for a media that didn't have a valid audio or video // to play, or hasn't played. - if (!HasOwnerHadValidMedia() || - (mTotalAudioPlayTime.PeekTotal() == 0.0 && - mTotalVideoPlayTime.PeekTotal() == 0.0)) { + if (!HasOwnerHadValidMedia() || (mTotalAudioPlayTime.PeekTotal() == 0.0 && + mTotalVideoPlayTime.PeekTotal() == 0.0)) { return; } nsCString key; + nsCString avKey; const double totalAudioPlayTimeS = mTotalAudioPlayTime.GetAndClearTotal(); const double inaudiblePlayTimeS = mInaudibleAudioPlayTime.GetAndClearTotal(); const double mutedPlayTimeS = mMutedAudioPlayTime.GetAndClearTotal(); @@ -476,9 +476,11 @@ void TelemetryProbesReporter::ReportResultForAudio() { // Media element had an audible audio track key.AppendASCII("A"); } + avKey.AppendASCII("A"); } if (mMediaContent & MediaContent::MEDIA_HAS_VIDEO) { key.AppendASCII("V"); + avKey.AppendASCII("V"); } LOG("Key: %s", key.get()); @@ -491,6 +493,10 @@ void TelemetryProbesReporter::ReportResultForAudio() { mutedPlayTimeS, audiblePercentage, unmutedPercentage); Telemetry::Accumulate(Telemetry::MEDIA_PLAY_TIME_MS, key, SECONDS_TO_MS(totalAudioPlayTimeS)); + Telemetry::Accumulate(Telemetry::MUTED_PLAY_TIME_PERCENT, avKey, + 100 - unmutedPercentage); + Telemetry::Accumulate(Telemetry::AUDIBLE_PLAY_TIME_PERCENT, avKey, + audiblePercentage); } else { MOZ_ASSERT(mMediaContent & MediaContent::MEDIA_HAS_VIDEO); Telemetry::Accumulate(Telemetry::MEDIA_PLAY_TIME_MS, key, diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 03f2f6ba34f0..94b9cb9057dc 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -13322,6 +13322,32 @@ "bug_numbers": [1678373], "releaseChannelCollection": "opt-out" }, + "AUDIBLE_PLAY_TIME_PERCENT": { + "record_in_processes": ["main", "content"], + "products": ["firefox"], + "alert_emails": ["alwu@mozilla.com", "padenot@mozilla.com"], + "expires_in_version": "never", + "description": "Percentage of time spent playing media with an audible audio track, regardless of the volume. Keyed by audio-only or video presence.", + "keyed": true, + "kind": "linear", + "high": 100, + "n_buckets": 50, + "bug_numbers": [1678373], + "releaseChannelCollection": "opt-out" + }, + "MUTED_PLAY_TIME_PERCENT": { + "record_in_processes": ["main", "content"], + "products": ["firefox"], + "alert_emails": ["alwu@mozilla.com", "padenot@mozilla.com"], + "expires_in_version": "never", + "description": "Percentage of time spent playing media that has an audio track, with the audio muted. Keyed by audio-only or video presence.", + "keyed": true, + "kind": "linear", + "high": 100, + "n_buckets": 50, + "bug_numbers": [1678373], + "releaseChannelCollection": "opt-out" + }, "VIDEO_VISIBLE_PLAY_TIME_MS" : { "record_in_processes": ["main", "content"], "products": ["firefox"],