Skip to content

Commit

Permalink
[telemetry] Add telemetry to SbPlayerWriteSamples (#4097)
Browse files Browse the repository at this point in the history
Adding additional Media Telemetry to cover SbPlayerWriteSamples.

The rough range of each function:
1. When batched write is enabled (Media.MaxAudioSamplesPerWrite=256,
#3271):
    1. SbPlayerWriteSamples()/audio: 1us to 98us
    2. SbPlayerWriteSamples()/video: 1us to 3.4ms
2. When batched write is disabled (Media.MaxAudioSamplesPerWrite=1,
#3271):
    1. SbPlayerWriteSamples()/audio: 9us to 65.47ms
    2. SbPlayerWriteSamples()/video: 8us to 28.07ms

b/303328238
  • Loading branch information
borongc authored Sep 30, 2024
1 parent 914a1b7 commit d79a729
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cobalt/media/base/metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) !=
Expand Down Expand Up @@ -211,6 +225,18 @@ void MediaMetricsProvider::ReportActionLatencyUMA(
base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(50), 50);
break;
case MediaAction::SBPLAYER_WRITE_SAMPLES_AUDIO:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"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_CREATE:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbDrm.Create.LatencyTiming", action_duration,
Expand Down
3 changes: 3 additions & 0 deletions cobalt/media/base/metrics_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ enum class MediaAction : uint8_t {
SBPLAYER_GET_INFO,
SBPLAYER_GET_CURRENT_FRAME,
SBPLAYER_GET_AUDIO_CONFIG,
SBPLAYER_WRITE_SAMPLES_AUDIO,
SBPLAYER_WRITE_SAMPLES_VIDEO,
SBDRM_CREATE,
SBDRM_DESTROY,
SBDRM_GENERATE_SESSION_UPDATE_REQUEST,
Expand Down Expand Up @@ -105,6 +107,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();
Expand Down
22 changes: 22 additions & 0 deletions cobalt/media/base/metrics_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions cobalt/media/base/sbplayer_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,19 @@ 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);
#else // SB_API_VERSION >= 15
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(
Expand Down
18 changes: 18 additions & 0 deletions tools/metrics/histograms/metadata/cobalt/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,24 @@ Always run the pretty print utility on this file after editing:
<summary>Timing data for writing end of video stream.</summary>
</histogram>

<histogram name="Cobalt.Media.SbPlayer.WriteSamples.Audio.LatencyTiming"
units="microseconds" expires_after="never">
<!-- expires-never: Needed for long-term tracking of SbPlayer latencies. -->

<owner>[email protected]</owner>
<owner>[email protected]</owner>
<summary>Timing data for writing single audio sample.</summary>
</histogram>

<histogram name="Cobalt.Media.SbPlayer.WriteSamples.Video.LatencyTiming"
units="microseconds" expires_after="never">
<!-- expires-never: Needed for long-term tracking of SbPlayer latencies. -->

<owner>[email protected]</owner>
<owner>[email protected]</owner>
<summary>Timing data for writing single video sample.</summary>
</histogram>

<histogram name="Cobalt.Media.SDR.Matrix" enum="MatrixID" expires_after="never">
<!-- expires-never: Needed for baseline Media pipeline health metric. -->

Expand Down

0 comments on commit d79a729

Please sign in to comment.