Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[telemetry] Add telemetry to SbMedia functions #4101

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions cobalt/media/base/metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,49 @@ void MediaMetricsProvider::ReportActionLatencyUMA(
base::TimeDelta::FromMicroseconds(500),
base::TimeDelta::FromMilliseconds(50), 50);
break;
case MediaAction::SBMEDIA_BUFFER_POOL_ALLOCATE_ON_DEMAND:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbMedia.BufferPoolAllocateOnDemand.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(5), 50);
break;
case MediaAction::SBMEDIA_GET_INIT_BUFFER_CAPACITY:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbMedia.GetInitBufferCapacity.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(5), 50);
break;
case MediaAction::SBMEDIA_GET_BUFFER_ALLOCATION_UNIT:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbMedia.GetBufferAllocationUnit.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(5), 50);
break;
case MediaAction::SBMEDIA_GET_AUDIO_BUFFER_BUDGET:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbMedia.GetAudioBufferBudget.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(20), 50);
break;
case MediaAction::SBMEDIA_GET_BUFFER_GARBAGE_COLLECTION_DURATION_THRESHOLD:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbMedia.GetBufferGarbageCollectionDurationThreshold."
"LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(20), 50);
break;
case MediaAction::SBMEDIA_GET_PROGRESSIVE_BUFFER_BUDGET:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbMedia.GetProgressiveBufferBudget.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(20), 50);
break;
case MediaAction::SBMEDIA_GET_VIDEO_BUFFER_BUDGET:
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Cobalt.Media.SbMedia.GetVideoBufferBudget.LatencyTiming",
action_duration, base::TimeDelta::FromMicroseconds(1),
base::TimeDelta::FromMilliseconds(20), 50);
break;
case MediaAction::UNKNOWN_ACTION:
default:
break;
Expand Down
7 changes: 7 additions & 0 deletions cobalt/media/base/metrics_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ enum class MediaAction : uint8_t {
SBDRM_GENERATE_SESSION_UPDATE_REQUEST,
SBDRM_UPDATE_SESSION,
SBDRM_CLOSE_SESSION,
SBMEDIA_BUFFER_POOL_ALLOCATE_ON_DEMAND,
SBMEDIA_GET_INIT_BUFFER_CAPACITY,
SBMEDIA_GET_BUFFER_ALLOCATION_UNIT,
SBMEDIA_GET_AUDIO_BUFFER_BUDGET,
SBMEDIA_GET_BUFFER_GARBAGE_COLLECTION_DURATION_THRESHOLD,
SBMEDIA_GET_PROGRESSIVE_BUFFER_BUDGET,
SBMEDIA_GET_VIDEO_BUFFER_BUDGET,
};

class MediaMetricsProvider {
Expand Down
86 changes: 86 additions & 0 deletions cobalt/media/base/metrics_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,92 @@ TEST_F(MediaMetricsProviderTest, SbDrmUpdateSession) {
std::string(kUmaPrefix) + "SbDrm.UpdateSession.LatencyTiming", 100, 1);
}

TEST_F(MediaMetricsProviderTest, SbMediaIsBufferPoolAllocateOnDemand) {
metrics_.StartTrackingAction(
MediaAction::SBMEDIA_BUFFER_POOL_ALLOCATE_ON_DEMAND);

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

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

TEST_F(MediaMetricsProviderTest, SbMediaGetInitialBufferCapacity) {
metrics_.StartTrackingAction(MediaAction::SBMEDIA_GET_INIT_BUFFER_CAPACITY);

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

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

TEST_F(MediaMetricsProviderTest, SbMediaGetBufferAllocationUnit) {
metrics_.StartTrackingAction(MediaAction::SBMEDIA_GET_BUFFER_ALLOCATION_UNIT);

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

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

TEST_F(MediaMetricsProviderTest, SbMediaGetAudioBufferBudget) {
metrics_.StartTrackingAction(MediaAction::SBMEDIA_GET_AUDIO_BUFFER_BUDGET);

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

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

TEST_F(MediaMetricsProviderTest,
SbMediaGetBufferGarbageCollectionDurationThreshold) {
metrics_.StartTrackingAction(
MediaAction::SBMEDIA_GET_BUFFER_GARBAGE_COLLECTION_DURATION_THRESHOLD);

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

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

TEST_F(MediaMetricsProviderTest, SbMediaGetProgressiveBufferBudget) {
metrics_.StartTrackingAction(
MediaAction::SBMEDIA_GET_PROGRESSIVE_BUFFER_BUDGET);

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

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

TEST_F(MediaMetricsProviderTest, SbMediaGetVideoBufferBudget) {
metrics_.StartTrackingAction(MediaAction::SBMEDIA_GET_VIDEO_BUFFER_BUDGET);

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

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

} // namespace
} // namespace media
Expand Down
73 changes: 64 additions & 9 deletions cobalt/media/decoder_buffer_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,45 @@ const size_t kSmallAllocationThreshold = 512;

} // namespace

bool CreateSbMediaIsBufferPoolAllocateOnDemandWithHistogram(
MediaMetricsProvider& media_metrics_provider) {
media_metrics_provider.StartTrackingAction(
MediaAction::SBMEDIA_BUFFER_POOL_ALLOCATE_ON_DEMAND);
auto is_memory_pool_allocated_on_demand =
SbMediaIsBufferPoolAllocateOnDemand();
media_metrics_provider.EndTrackingAction(
MediaAction::SBMEDIA_BUFFER_POOL_ALLOCATE_ON_DEMAND);
return is_memory_pool_allocated_on_demand;
}

int CreateSbMediaGetInitialBufferCapacityWithHistogram(
MediaMetricsProvider& media_metrics_provider) {
media_metrics_provider.StartTrackingAction(
MediaAction::SBMEDIA_GET_INIT_BUFFER_CAPACITY);
auto initial_capacity = SbMediaGetInitialBufferCapacity();
media_metrics_provider.EndTrackingAction(
MediaAction::SBMEDIA_GET_INIT_BUFFER_CAPACITY);
return initial_capacity;
}

bool CreateSbMediaGetBufferAllocationUnitWithHistogram(
MediaMetricsProvider& media_metrics_provider) {
media_metrics_provider.StartTrackingAction(
MediaAction::SBMEDIA_GET_BUFFER_ALLOCATION_UNIT);
auto allocation_unit = SbMediaGetBufferAllocationUnit();
media_metrics_provider.EndTrackingAction(
MediaAction::SBMEDIA_GET_BUFFER_ALLOCATION_UNIT);
return allocation_unit;
}

DecoderBufferAllocator::DecoderBufferAllocator()
: is_memory_pool_allocated_on_demand_(
SbMediaIsBufferPoolAllocateOnDemand()),
initial_capacity_(SbMediaGetInitialBufferCapacity()),
allocation_unit_(SbMediaGetBufferAllocationUnit()) {
CreateSbMediaIsBufferPoolAllocateOnDemandWithHistogram(
media_metrics_provider_)),
initial_capacity_(CreateSbMediaGetInitialBufferCapacityWithHistogram(
media_metrics_provider_)),
allocation_unit_(CreateSbMediaGetBufferAllocationUnitWithHistogram(
media_metrics_provider_)) {
if (is_memory_pool_allocated_on_demand_) {
DLOG(INFO) << "Allocated media buffer pool on demand.";
Allocator::Set(this);
Expand Down Expand Up @@ -124,7 +158,12 @@ void DecoderBufferAllocator::Free(void* p, size_t size) {
}

int DecoderBufferAllocator::GetAudioBufferBudget() const {
return SbMediaGetAudioBufferBudget();
media_metrics_provider_.StartTrackingAction(
MediaAction::SBMEDIA_GET_AUDIO_BUFFER_BUDGET);
int audio_buffer_budget = SbMediaGetAudioBufferBudget();
media_metrics_provider_.EndTrackingAction(
MediaAction::SBMEDIA_GET_AUDIO_BUFFER_BUDGET);
return audio_buffer_budget;
}

int DecoderBufferAllocator::GetBufferAlignment() const {
Expand All @@ -141,23 +180,39 @@ int DecoderBufferAllocator::GetBufferPadding() const {

base::TimeDelta
DecoderBufferAllocator::GetBufferGarbageCollectionDurationThreshold() const {
media_metrics_provider_.StartTrackingAction(
MediaAction::SBMEDIA_GET_BUFFER_GARBAGE_COLLECTION_DURATION_THRESHOLD);
int64_t buffer_garbage_collection_duration_threshold =
SbMediaGetBufferGarbageCollectionDurationThreshold();
media_metrics_provider_.EndTrackingAction(
MediaAction::SBMEDIA_GET_BUFFER_GARBAGE_COLLECTION_DURATION_THRESHOLD);
return base::TimeDelta::FromMicroseconds(
SbMediaGetBufferGarbageCollectionDurationThreshold());
buffer_garbage_collection_duration_threshold);
}

int DecoderBufferAllocator::GetProgressiveBufferBudget(
SbMediaVideoCodec codec, int resolution_width, int resolution_height,
int bits_per_pixel) const {
return SbMediaGetProgressiveBufferBudget(codec, resolution_width,
resolution_height, bits_per_pixel);
media_metrics_provider_.StartTrackingAction(
MediaAction::SBMEDIA_GET_PROGRESSIVE_BUFFER_BUDGET);
int progressive_buffer_budget = SbMediaGetProgressiveBufferBudget(
codec, resolution_width, resolution_height, bits_per_pixel);
media_metrics_provider_.EndTrackingAction(
MediaAction::SBMEDIA_GET_PROGRESSIVE_BUFFER_BUDGET);
return progressive_buffer_budget;
}

int DecoderBufferAllocator::GetVideoBufferBudget(SbMediaVideoCodec codec,
int resolution_width,
int resolution_height,
int bits_per_pixel) const {
return SbMediaGetVideoBufferBudget(codec, resolution_width, resolution_height,
bits_per_pixel);
media_metrics_provider_.StartTrackingAction(
MediaAction::SBMEDIA_GET_VIDEO_BUFFER_BUDGET);
int video_buffer_budget = SbMediaGetVideoBufferBudget(
codec, resolution_width, resolution_height, bits_per_pixel);
media_metrics_provider_.EndTrackingAction(
MediaAction::SBMEDIA_GET_VIDEO_BUFFER_BUDGET);
return video_buffer_budget;
}

size_t DecoderBufferAllocator::GetAllocatedMemory() const {
Expand Down
3 changes: 3 additions & 0 deletions cobalt/media/decoder_buffer_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/compiler_specific.h"
#include "base/synchronization/lock.h"
#include "base/time/time.h"
#include "cobalt/media/base/metrics_provider.h"
#include "cobalt/media/bidirectional_fit_reuse_allocator.h"
#include "cobalt/media/decoder_buffer_memory_info.h"
#include "cobalt/media/starboard_memory_allocator.h"
Expand Down Expand Up @@ -63,6 +64,8 @@ class DecoderBufferAllocator : public ::media::DecoderBuffer::Allocator,
private:
void EnsureReuseAllocatorIsCreated();

mutable MediaMetricsProvider media_metrics_provider_;

const bool is_memory_pool_allocated_on_demand_;
const int initial_capacity_;
const int allocation_unit_;
Expand Down
66 changes: 66 additions & 0 deletions tools/metrics/histograms/metadata/cobalt/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,72 @@ Always run the pretty print utility on this file after editing:
<summary>Timing data for updating session of SbDrm.</summary>
</histogram>

<histogram name="Cobalt.Media.SbMedia.BufferPoolAllocateOnDemand.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 allocating buffer pool on demand.</summary>
</histogram>

<histogram name="Cobalt.Media.SbMedia.GetAudioBufferBudget.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 getting audio buffer budget.</summary>
</histogram>

<histogram name="Cobalt.Media.SbMedia.GetBufferAllocationUnit.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 getting buffer allocation unit.</summary>
</histogram>

<histogram
name="Cobalt.Media.SbMedia.GetBufferGarbageCollectionDurationThreshold.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 getting buffer garbage collection duration threshold.
</summary>
</histogram>

<histogram name="Cobalt.Media.SbMedia.GetInitBufferCapacity.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 getting initial buffer capacity.</summary>
</histogram>

<histogram name="Cobalt.Media.SbMedia.GetProgressiveBufferBudget.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 getting progressive buffer budget.</summary>
</histogram>

<histogram name="Cobalt.Media.SbMedia.GetVideoBufferBudget.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 getting video buffer budget.</summary>
</histogram>

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