Skip to content

Commit

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

The rough range of each function:
1. SbDrmCreateSystem(): 26.307ms to 94.221ms

b/303328238

(cherry picked from commit 26975cf)
  • Loading branch information
borongc committed Sep 16, 2024
1 parent 73272fe commit ce5b949
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
22 changes: 20 additions & 2 deletions cobalt/media/base/drm_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
namespace cobalt {
namespace media {

SbDrmSystem CreateSbDrmSystemWithHistogram(
const char* key_system, void* context,
SbDrmSessionUpdateRequestFunc update_request_callback,
SbDrmSessionUpdatedFunc session_updated_callback,
SbDrmSessionKeyStatusesChangedFunc key_statuses_changed_callback,
SbDrmServerCertificateUpdatedFunc server_certificate_updated_callback,
SbDrmSessionClosedFunc session_closed_callback,
MediaMetricsProvider& media_metrics_provider) {
media_metrics_provider.StartTrackingAction(MediaAction::SBDRM_CREATE);
auto drm_system = SbDrmCreateSystem(
key_system, context, update_request_callback, session_updated_callback,
key_statuses_changed_callback, server_certificate_updated_callback,
session_closed_callback);
media_metrics_provider.EndTrackingAction(MediaAction::SBDRM_CREATE);
return drm_system;
}

DECLARE_INSTANCE_COUNTER(DrmSystem);

DrmSystem::Session::Session(
Expand Down Expand Up @@ -80,10 +97,11 @@ void DrmSystem::Session::Close() {
}

DrmSystem::DrmSystem(const char* key_system)
: wrapped_drm_system_(SbDrmCreateSystem(
: wrapped_drm_system_(CreateSbDrmSystemWithHistogram(
key_system, this, OnSessionUpdateRequestGeneratedFunc,
OnSessionUpdatedFunc, OnSessionKeyStatusesChangedFunc,
OnServerCertificateUpdatedFunc, OnSessionClosedFunc)),
OnServerCertificateUpdatedFunc, OnSessionClosedFunc,
media_metrics_provider_)),
task_runner_(base::SequencedTaskRunner::GetCurrentDefault()),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
weak_this_(weak_ptr_factory_.GetWeakPtr()) {
Expand Down
3 changes: 1 addition & 2 deletions cobalt/media/base/drm_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class DrmSystem : public base::RefCounted<DrmSystem> {
SbDrmStatus status,
const char* error_message);

MediaMetricsProvider media_metrics_provider_;
const SbDrmSystem wrapped_drm_system_;
scoped_refptr<base::SequencedTaskRunner> const task_runner_;

Expand All @@ -253,8 +254,6 @@ class DrmSystem : public base::RefCounted<DrmSystem> {
// Supports concurrent calls to |Session::Update|.
TicketToSessionUpdateMap ticket_to_session_update_map_;

MediaMetricsProvider media_metrics_provider_;

DISALLOW_COPY_AND_ASSIGN(DrmSystem);
};

Expand Down
6 changes: 6 additions & 0 deletions cobalt/media/base/metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ void MediaMetricsProvider::ReportActionLatencyUMA(
UMA_HISTOGRAM_TIMES("Cobalt.Media.SbPlayer.Destroy.LatencyTiming",
action_duration);
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;
case MediaAction::SBDRM_DESTROY:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbDrm.Destroy.LatencyTiming", action_duration,
Expand Down
1 change: 1 addition & 0 deletions cobalt/media/base/metrics_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum class MediaAction : uint8_t {
SBPLAYER_CREATE,
SBPLAYER_CREATE_URL_PLAYER,
SBPLAYER_DESTROY,
SBDRM_CREATE,
SBDRM_DESTROY,
SBDRM_GENERATE_SESSION_UPDATE_REQUEST,
SBDRM_UPDATE_SESSION,
Expand Down
10 changes: 10 additions & 0 deletions cobalt/media/base/metrics_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ TEST_F(MediaMetricsProviderTest, SbDrmCloseSession) {
std::string(kUmaPrefix) + "SbDrm.CloseSession.LatencyTiming", 570, 1);
}

TEST_F(MediaMetricsProviderTest, SbDrmCreate) {
metrics_.StartTrackingAction(MediaAction::SBDRM_CREATE);

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

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

TEST_F(MediaMetricsProviderTest, SbDrmDestroy) {
metrics_.StartTrackingAction(MediaAction::SBDRM_DESTROY);

Expand Down
9 changes: 9 additions & 0 deletions tools/metrics/histograms/metadata/cobalt/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ Always run the pretty print utility on this file after editing:
<summary>Timing data for closing session of SbDrm.</summary>
</histogram>

<histogram name="Cobalt.Media.SbDrm.Create.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 the creation of SbDrm.</summary>
</histogram>

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

0 comments on commit ce5b949

Please sign in to comment.