From ab61a1eb898ac6c61d6504e626b9be27ab984a28 Mon Sep 17 00:00:00 2001 From: Bo-Rong Chen Date: Thu, 29 Aug 2024 09:42:44 -0700 Subject: [PATCH] [telemetry] Add telemetry to SbDrmCreateSystem (#4058) 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 26975cf2193c6fa889f408b2849e288bf09f4f9f) --- cobalt/media/base/drm_system.cc | 22 +++++++++++++++++-- cobalt/media/base/drm_system.h | 3 +-- cobalt/media/base/metrics_provider.cc | 6 +++++ cobalt/media/base/metrics_provider.h | 1 + cobalt/media/base/metrics_provider_test.cc | 10 +++++++++ .../histograms/metadata/cobalt/histograms.xml | 9 ++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/cobalt/media/base/drm_system.cc b/cobalt/media/base/drm_system.cc index 21949bc57233..8f3ccd8f62b1 100644 --- a/cobalt/media/base/drm_system.cc +++ b/cobalt/media/base/drm_system.cc @@ -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( @@ -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()) { diff --git a/cobalt/media/base/drm_system.h b/cobalt/media/base/drm_system.h index db49a8fffd28..446735b8919c 100644 --- a/cobalt/media/base/drm_system.h +++ b/cobalt/media/base/drm_system.h @@ -232,6 +232,7 @@ class DrmSystem : public base::RefCounted { SbDrmStatus status, const char* error_message); + MediaMetricsProvider media_metrics_provider_; const SbDrmSystem wrapped_drm_system_; scoped_refptr const task_runner_; @@ -253,8 +254,6 @@ class DrmSystem : public base::RefCounted { // Supports concurrent calls to |Session::Update|. TicketToSessionUpdateMap ticket_to_session_update_map_; - MediaMetricsProvider media_metrics_provider_; - DISALLOW_COPY_AND_ASSIGN(DrmSystem); }; diff --git a/cobalt/media/base/metrics_provider.cc b/cobalt/media/base/metrics_provider.cc index b6b4d72a5916..f3602c83a4ca 100644 --- a/cobalt/media/base/metrics_provider.cc +++ b/cobalt/media/base/metrics_provider.cc @@ -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, diff --git a/cobalt/media/base/metrics_provider.h b/cobalt/media/base/metrics_provider.h index 56a5c8328f00..c883e7eca3ca 100644 --- a/cobalt/media/base/metrics_provider.h +++ b/cobalt/media/base/metrics_provider.h @@ -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, diff --git a/cobalt/media/base/metrics_provider_test.cc b/cobalt/media/base/metrics_provider_test.cc index 46a5470605fa..7fdb4b39739d 100644 --- a/cobalt/media/base/metrics_provider_test.cc +++ b/cobalt/media/base/metrics_provider_test.cc @@ -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); diff --git a/tools/metrics/histograms/metadata/cobalt/histograms.xml b/tools/metrics/histograms/metadata/cobalt/histograms.xml index 1cc9ae95c457..a2bff07be5cc 100644 --- a/tools/metrics/histograms/metadata/cobalt/histograms.xml +++ b/tools/metrics/histograms/metadata/cobalt/histograms.xml @@ -284,6 +284,15 @@ Always run the pretty print utility on this file after editing: Timing data for closing session of SbDrm. + + + + borongchen@google.com + cobalt-team@google.com + Timing data for the creation of SbDrm. + +