Skip to content

Commit

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

The rough range of each function:
1. SbPlayerGetPreferredOutputMode(): 1.5us to 13us
2. SbPlayerSeek(): 6us to 318us
3. SbPlayerWriteEndOfStream()/audio: 13us to 6.3ms
4. SbPlayerWriteEndOfStream()/video: 3us to 2.8ms
5. SbPlayerSetBounds(): 133us to 26.95ms
6. SbPlayerSetPlaybackRate(): 6us to 11.17ms
7. SbPlayerSetVolume(): 7us to 17.89ms
8. SbPlayerGetInfo(): 1us to 6.8ms
9. SbPlayerGetAudioConfiguration(): 2us to 22.7ms
10. SbPlayerGetCurrentFrame(): 5us to 61.7ms

b/303328238

(cherry picked from commit ea15d82)
  • Loading branch information
borongc authored and anonymous1-me committed Sep 6, 2024
1 parent 727a2b7 commit 7ddb17c
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 4 deletions.
69 changes: 69 additions & 0 deletions cobalt/media/base/metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,75 @@ void MediaMetricsProvider::ReportActionLatencyUMA(
UMA_HISTOGRAM_TIMES("Cobalt.Media.SbPlayer.Destroy.LatencyTiming",
action_duration);
break;
<<<<<<< HEAD
=======
case MediaAction::SBPLAYER_GET_PREFERRED_OUTPUT_MODE:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.GetPreferredOutputMode.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMicroseconds(100), 50);
break;
case MediaAction::SBPLAYER_SEEK:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.Seek.LatencyTiming", action_duration,
base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMicroseconds(800), 50);
break;
case MediaAction::SBPLAYER_WRITE_END_OF_STREAM_AUDIO:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.WriteEndOfStream.Audio.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(25), 50);
break;
case MediaAction::SBPLAYER_WRITE_END_OF_STREAM_VIDEO:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.WriteEndOfStream.Video.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(25), 50);
break;
case MediaAction::SBPLAYER_SET_BOUNDS:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.SetBounds.LatencyTiming", action_duration,
base::TimeDelta::FromMicroseconds(50),
base::TimeDelta::FromMilliseconds(60), 50);
break;
case MediaAction::SBPLAYER_SET_PLAYBACK_RATE:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.SetPlaybackRate.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(50), 50);
break;
case MediaAction::SBPLAYER_SET_VOLUME:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.SetVolume.LatencyTiming", action_duration,
base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(50), 50);
break;
case MediaAction::SBPLAYER_GET_INFO:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.GetInfo.LatencyTiming", action_duration,
base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(20), 50);
break;
case MediaAction::SBPLAYER_GET_CURRENT_FRAME:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.GetCurrentFrame.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(250), 50);
break;
case MediaAction::SBPLAYER_GET_AUDIO_CONFIG:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbPlayer.GetAudioConfig.LatencyTiming", action_duration,
base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(50), 50);
break;
case MediaAction::SBDRM_CREATE:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbDrm.Create.LatencyTiming", action_duration,
base::TimeDelta::FromMicroseconds(500),
base::TimeDelta::FromMilliseconds(250), 50);
break;
>>>>>>> ea15d824b29 ([telemetry] Add telemetry to SbPlayer functions (#4068))
case MediaAction::SBDRM_DESTROY:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbDrm.Destroy.LatencyTiming", action_duration,
Expand Down
14 changes: 14 additions & 0 deletions cobalt/media/base/metrics_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ enum class MediaAction : uint8_t {
SBPLAYER_CREATE,
SBPLAYER_CREATE_URL_PLAYER,
SBPLAYER_DESTROY,
<<<<<<< HEAD
=======
SBPLAYER_GET_PREFERRED_OUTPUT_MODE,
SBPLAYER_SEEK,
SBPLAYER_WRITE_END_OF_STREAM_AUDIO,
SBPLAYER_WRITE_END_OF_STREAM_VIDEO,
SBPLAYER_SET_BOUNDS,
SBPLAYER_SET_PLAYBACK_RATE,
SBPLAYER_SET_VOLUME,
SBPLAYER_GET_INFO,
SBPLAYER_GET_CURRENT_FRAME,
SBPLAYER_GET_AUDIO_CONFIG,
SBDRM_CREATE,
>>>>>>> ea15d824b29 ([telemetry] Add telemetry to SbPlayer functions (#4068))
SBDRM_DESTROY,
SBDRM_GENERATE_SESSION_UPDATE_REQUEST,
SBDRM_UPDATE_SESSION,
Expand Down
106 changes: 106 additions & 0 deletions cobalt/media/base/metrics_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,112 @@ TEST_F(MediaMetricsProviderTest, SbPlayerDestroy) {
std::string(kUmaPrefix) + "SbPlayer.Destroy.LatencyTiming", 100, 1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerGetPreferredOutputMode) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_GET_PREFERRED_OUTPUT_MODE);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_GET_PREFERRED_OUTPUT_MODE);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.GetPreferredOutputMode.LatencyTiming",
570, 1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerSeek) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_SEEK);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_SEEK);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.Seek.LatencyTiming", 570, 1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerSetBounds) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_SET_BOUNDS);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_SET_BOUNDS);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.SetBounds.LatencyTiming", 570, 1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerSetPlaybackRate) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_SET_PLAYBACK_RATE);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_SET_PLAYBACK_RATE);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.SetPlaybackRate.LatencyTiming", 570,
1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerSetVolume) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_SET_VOLUME);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_SET_VOLUME);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.SetVolume.LatencyTiming", 570, 1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerGetInfo) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_GET_INFO);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_GET_INFO);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.GetInfo.LatencyTiming", 570, 1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerGetCurrentFrame) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_GET_CURRENT_FRAME);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_GET_CURRENT_FRAME);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.GetCurrentFrame.LatencyTiming", 570,
1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerGetAudioConfig) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_GET_AUDIO_CONFIG);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_GET_AUDIO_CONFIG);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.GetAudioConfig.LatencyTiming", 570,
1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerWriteEndOfStreamAudio) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_WRITE_END_OF_STREAM_AUDIO);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_WRITE_END_OF_STREAM_AUDIO);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.WriteEndOfStream.Audio.LatencyTiming",
570, 1);
}

TEST_F(MediaMetricsProviderTest, SbPlayerWriteEndOfStreamVideo) {
metrics_.StartTrackingAction(MediaAction::SBPLAYER_WRITE_END_OF_STREAM_VIDEO);

clock_.Advance(base::TimeDelta::FromMicroseconds(570));
metrics_.EndTrackingAction(MediaAction::SBPLAYER_WRITE_END_OF_STREAM_VIDEO);

histogram_tester_.ExpectUniqueSample(
std::string(kUmaPrefix) + "SbPlayer.WriteEndOfStream.Video.LatencyTiming",
570, 1);
}

TEST_F(MediaMetricsProviderTest, SbDrmCloseSession) {
metrics_.StartTrackingAction(MediaAction::SBDRM_CLOSE_SESSION);

Expand Down
43 changes: 39 additions & 4 deletions cobalt/media/base/sbplayer_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ SbPlayer DefaultSbPlayerInterface::Create(

SbPlayerOutputMode DefaultSbPlayerInterface::GetPreferredOutputMode(
const SbPlayerCreationParam* creation_param) {
return SbPlayerGetPreferredOutputMode(creation_param);
media_metrics_provider_.StartTrackingAction(
MediaAction::SBPLAYER_GET_PREFERRED_OUTPUT_MODE);
auto output_mode = SbPlayerGetPreferredOutputMode(creation_param);
media_metrics_provider_.EndTrackingAction(
MediaAction::SBPLAYER_GET_PREFERRED_OUTPUT_MODE);
return output_mode;
}

void DefaultSbPlayerInterface::Destroy(SbPlayer player) {
Expand All @@ -91,11 +96,13 @@ void DefaultSbPlayerInterface::Destroy(SbPlayer player) {
void DefaultSbPlayerInterface::Seek(SbPlayer player,
base::TimeDelta seek_to_timestamp,
int ticket) {
media_metrics_provider_.StartTrackingAction(MediaAction::SBPLAYER_SEEK);
#if SB_API_VERSION >= 15
SbPlayerSeek(player, seek_to_timestamp.InMicroseconds(), ticket);
#else // SB_API_VERSION >= 15
SbPlayerSeek2(player, seek_to_timestamp.InMicroseconds(), ticket);
#endif // SB_API_VERSION >= 15
media_metrics_provider_.EndTrackingAction(MediaAction::SBPLAYER_SEEK);
}

bool DefaultSbPlayerInterface::IsEnhancedAudioExtensionEnabled() const {
Expand Down Expand Up @@ -131,35 +138,57 @@ int DefaultSbPlayerInterface::GetMaximumNumberOfSamplesPerWrite(

void DefaultSbPlayerInterface::WriteEndOfStream(SbPlayer player,
SbMediaType stream_type) {
auto media_action = (stream_type == kSbMediaTypeAudio)
? MediaAction::SBPLAYER_WRITE_END_OF_STREAM_AUDIO
: MediaAction::SBPLAYER_WRITE_END_OF_STREAM_VIDEO;
media_metrics_provider_.StartTrackingAction(media_action);
SbPlayerWriteEndOfStream(player, stream_type);
media_metrics_provider_.EndTrackingAction(media_action);
}

void DefaultSbPlayerInterface::SetBounds(SbPlayer player, int z_index, int x,
int y, int width, int height) {
media_metrics_provider_.StartTrackingAction(MediaAction::SBPLAYER_SET_BOUNDS);
SbPlayerSetBounds(player, z_index, x, y, width, height);
media_metrics_provider_.EndTrackingAction(MediaAction::SBPLAYER_SET_BOUNDS);
}

bool DefaultSbPlayerInterface::SetPlaybackRate(SbPlayer player,
double playback_rate) {
return SbPlayerSetPlaybackRate(player, playback_rate);
media_metrics_provider_.StartTrackingAction(
MediaAction::SBPLAYER_SET_PLAYBACK_RATE);
auto set_playback_rate = SbPlayerSetPlaybackRate(player, playback_rate);
media_metrics_provider_.EndTrackingAction(
MediaAction::SBPLAYER_SET_PLAYBACK_RATE);
return set_playback_rate;
}

void DefaultSbPlayerInterface::SetVolume(SbPlayer player, double volume) {
media_metrics_provider_.StartTrackingAction(MediaAction::SBPLAYER_SET_VOLUME);
SbPlayerSetVolume(player, volume);
media_metrics_provider_.EndTrackingAction(MediaAction::SBPLAYER_SET_VOLUME);
}

void DefaultSbPlayerInterface::GetInfo(SbPlayer player,
#if SB_API_VERSION >= 15
SbPlayerInfo* out_player_info) {
media_metrics_provider_.StartTrackingAction(MediaAction::SBPLAYER_GET_INFO);
SbPlayerGetInfo(player, out_player_info);
#else // SB_API_VERSION >= 15
SbPlayerInfo2* out_player_info2) {
media_metrics_provider_.StartTrackingAction(MediaAction::SBPLAYER_GET_INFO);
SbPlayerGetInfo2(player, out_player_info2);
#endif // SB_API_VERSION >= 15
media_metrics_provider_.EndTrackingAction(MediaAction::SBPLAYER_GET_INFO);
}

SbDecodeTarget DefaultSbPlayerInterface::GetCurrentFrame(SbPlayer player) {
return SbPlayerGetCurrentFrame(player);
media_metrics_provider_.StartTrackingAction(
MediaAction::SBPLAYER_GET_CURRENT_FRAME);
auto current_frame = SbPlayerGetCurrentFrame(player);
media_metrics_provider_.EndTrackingAction(
MediaAction::SBPLAYER_GET_CURRENT_FRAME);
return current_frame;
}

#if SB_HAS(PLAYER_WITH_URL)
Expand Down Expand Up @@ -199,7 +228,13 @@ void DefaultSbPlayerInterface::GetUrlPlayerExtraInfo(
bool DefaultSbPlayerInterface::GetAudioConfiguration(
SbPlayer player, int index,
SbMediaAudioConfiguration* out_audio_configuration) {
return SbPlayerGetAudioConfiguration(player, index, out_audio_configuration);
media_metrics_provider_.StartTrackingAction(
MediaAction::SBPLAYER_GET_AUDIO_CONFIG);
auto audio_configuration =
SbPlayerGetAudioConfiguration(player, index, out_audio_configuration);
media_metrics_provider_.EndTrackingAction(
MediaAction::SBPLAYER_GET_AUDIO_CONFIG);
return audio_configuration;
}

#endif // SB_API_VERSION >= 15
Expand Down
Loading

0 comments on commit 7ddb17c

Please sign in to comment.