Skip to content

Commit

Permalink
Cherry pick PR #4058: [telemetry] Add telemetry to SbDrmCreateSystem (#…
Browse files Browse the repository at this point in the history
…4066)

Refer to the original PR: #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

Co-authored-by: Bo-Rong Chen <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and borongc authored Sep 30, 2024
1 parent d79a729 commit 9fb9073
Show file tree
Hide file tree
Showing 4 changed files with 40 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
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 @@ -232,6 +232,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 9fb9073

Please sign in to comment.