From 7f9fbc411f0df941182f9120d6b130b496687db4 Mon Sep 17 00:00:00 2001 From: Bo-Rong Chen Date: Mon, 9 Sep 2024 13:58:27 -0700 Subject: [PATCH] [telemetry] Add telemetry to SbPlayerWriteSamples Adding additional Media Telemetry to cover SbPlayerWriteSamples. The rough range of each function: 1. When batched write is enabled (Media.MaxAudioSamplesPerWrite=256): 1. SbPlayerWriteSamples()/audio: 1us to 98us 2. SbPlayerWriteSamples()/video: 1us to 3.4ms 2. When batched write is disabled (Media.MaxAudioSamplesPerWrite=1): 1. SbPlayerWriteSamples()/audio: 9us to 65.47ms 2. SbPlayerWriteSamples()/video: 8us to 28.07ms b/303328238 --- cobalt/media/base/metrics_provider.cc | 28 ++++++++++++++++--- cobalt/media/base/metrics_provider.h | 4 ++- cobalt/media/base/metrics_provider_test.cc | 22 +++++++++++++++ cobalt/media/base/sbplayer_interface.cc | 6 ++++ .../histograms/metadata/cobalt/histograms.xml | 18 ++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) diff --git a/cobalt/media/base/metrics_provider.cc b/cobalt/media/base/metrics_provider.cc index 7bc8896377dc..1e9bdfa9987a 100644 --- a/cobalt/media/base/metrics_provider.cc +++ b/cobalt/media/base/metrics_provider.cc @@ -122,6 +122,20 @@ void MediaMetricsProvider::EndTrackingAction(MediaAction action) { tracked_actions_start_times_.erase(action); } +void MediaMetricsProvider::EndTrackingAction(MediaAction action, + int number_of_samples) { + DCHECK(IsActionCurrentlyTracked(action)); + base::AutoLock scoped_lock(mutex_); + + auto duration = clock_->NowTicks() - tracked_actions_start_times_[action]; + if (number_of_samples > 0) { + // Report latency UMA if it writes non-zero samples. + auto duration_per_sample = duration / number_of_samples; + ReportActionLatencyUMA(action, duration_per_sample); + } + tracked_actions_start_times_.erase(action); +} + bool MediaMetricsProvider::IsActionCurrentlyTracked(MediaAction action) { base::AutoLock scoped_lock(mutex_); return tracked_actions_start_times_.find(action) != @@ -211,11 +225,17 @@ void MediaMetricsProvider::ReportActionLatencyUMA( base::TimeDelta::FromMicroseconds(1), base::TimeDelta::FromMilliseconds(50), 50); break; - case MediaAction::SBDRM_CREATE: + case MediaAction::SBPLAYER_WRITE_SAMPLES_AUDIO: UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES( - "Cobalt.Media.SbDrm.Create.LatencyTiming", action_duration, - base::TimeDelta::FromMicroseconds(500), - base::TimeDelta::FromMilliseconds(250), 50); + "Cobalt.Media.SbPlayer.WriteSamples.Audio.LatencyTiming", + action_duration, base::TimeDelta::FromMicroseconds(1), + base::TimeDelta::FromMilliseconds(100), 50); + break; + case MediaAction::SBPLAYER_WRITE_SAMPLES_VIDEO: + UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES( + "Cobalt.Media.SbPlayer.WriteSamples.Video.LatencyTiming", + action_duration, base::TimeDelta::FromMicroseconds(1), + base::TimeDelta::FromMilliseconds(100), 50); break; case MediaAction::SBDRM_DESTROY: UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES( diff --git a/cobalt/media/base/metrics_provider.h b/cobalt/media/base/metrics_provider.h index 135b2601716f..53497b878ec2 100644 --- a/cobalt/media/base/metrics_provider.h +++ b/cobalt/media/base/metrics_provider.h @@ -54,7 +54,8 @@ enum class MediaAction : uint8_t { SBPLAYER_GET_INFO, SBPLAYER_GET_CURRENT_FRAME, SBPLAYER_GET_AUDIO_CONFIG, - SBDRM_CREATE, + SBPLAYER_WRITE_SAMPLES_AUDIO, + SBPLAYER_WRITE_SAMPLES_VIDEO, SBDRM_DESTROY, SBDRM_GENERATE_SESSION_UPDATE_REQUEST, SBDRM_UPDATE_SESSION, @@ -98,6 +99,7 @@ class MediaMetricsProvider { // Used to record the latency of an action in the WebMediaPlayer. void StartTrackingAction(MediaAction action); void EndTrackingAction(MediaAction action); + void EndTrackingAction(MediaAction action, int number_of_samples); bool IsActionCurrentlyTracked(MediaAction action); void Reset(); diff --git a/cobalt/media/base/metrics_provider_test.cc b/cobalt/media/base/metrics_provider_test.cc index cd490f1c1aa1..a2268bb42f91 100644 --- a/cobalt/media/base/metrics_provider_test.cc +++ b/cobalt/media/base/metrics_provider_test.cc @@ -200,6 +200,28 @@ TEST_F(MediaMetricsProviderTest, SbPlayerWriteEndOfStreamVideo) { 570, 1); } +TEST_F(MediaMetricsProviderTest, SbPlayerWriteSamplesAudio) { + metrics_.StartTrackingAction(MediaAction::SBPLAYER_WRITE_SAMPLES_AUDIO); + + clock_.Advance(base::TimeDelta::FromMicroseconds(570)); + metrics_.EndTrackingAction(MediaAction::SBPLAYER_WRITE_SAMPLES_AUDIO); + + histogram_tester_.ExpectUniqueSample( + std::string(kUmaPrefix) + "SbPlayer.WriteSamples.Audio.LatencyTiming", + 570, 1); +} + +TEST_F(MediaMetricsProviderTest, SbPlayerWriteSamplesVideoAudio) { + metrics_.StartTrackingAction(MediaAction::SBPLAYER_WRITE_SAMPLES_VIDEO); + + clock_.Advance(base::TimeDelta::FromMicroseconds(570)); + metrics_.EndTrackingAction(MediaAction::SBPLAYER_WRITE_SAMPLES_VIDEO); + + histogram_tester_.ExpectUniqueSample( + std::string(kUmaPrefix) + "SbPlayer.WriteSamples.Video.LatencyTiming", + 570, 1); +} + TEST_F(MediaMetricsProviderTest, SbDrmCloseSession) { metrics_.StartTrackingAction(MediaAction::SBDRM_CLOSE_SESSION); diff --git a/cobalt/media/base/sbplayer_interface.cc b/cobalt/media/base/sbplayer_interface.cc index 6b367d4c15ef..fbb2ae5f192f 100644 --- a/cobalt/media/base/sbplayer_interface.cc +++ b/cobalt/media/base/sbplayer_interface.cc @@ -113,6 +113,10 @@ void DefaultSbPlayerInterface::WriteSamples( SbPlayer player, SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, int number_of_sample_infos) { DCHECK(!IsEnhancedAudioExtensionEnabled()); + auto media_action = (sample_type == kSbMediaTypeAudio) + ? MediaAction::SBPLAYER_WRITE_SAMPLES_AUDIO + : MediaAction::SBPLAYER_WRITE_SAMPLES_VIDEO; + media_metrics_provider_.StartTrackingAction(media_action); #if SB_API_VERSION >= 15 SbPlayerWriteSamples(player, sample_type, sample_infos, number_of_sample_infos); @@ -120,6 +124,8 @@ void DefaultSbPlayerInterface::WriteSamples( SbPlayerWriteSample2(player, sample_type, sample_infos, number_of_sample_infos); #endif // SB_API_VERSION >= 15 + media_metrics_provider_.EndTrackingAction(media_action, + number_of_sample_infos); } void DefaultSbPlayerInterface::WriteSamples( diff --git a/tools/metrics/histograms/metadata/cobalt/histograms.xml b/tools/metrics/histograms/metadata/cobalt/histograms.xml index b2930b763b72..da7dfd696a09 100644 --- a/tools/metrics/histograms/metadata/cobalt/histograms.xml +++ b/tools/metrics/histograms/metadata/cobalt/histograms.xml @@ -428,6 +428,24 @@ Always run the pretty print utility on this file after editing: Timing data for writing end of video stream. + + + + borongchen@google.com + cobalt-team@google.com + Timing data for writing single audio sample. + + + + + + borongchen@google.com + cobalt-team@google.com + Timing data for writing single video sample. + +