diff --git a/cobalt/media/base/metrics_provider.cc b/cobalt/media/base/metrics_provider.cc
index b6b4d72a5916..427a02f99301 100644
--- a/cobalt/media/base/metrics_provider.cc
+++ b/cobalt/media/base/metrics_provider.cc
@@ -172,6 +172,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;
diff --git a/cobalt/media/base/metrics_provider.h b/cobalt/media/base/metrics_provider.h
index 56a5c8328f00..57818876fb9b 100644
--- a/cobalt/media/base/metrics_provider.h
+++ b/cobalt/media/base/metrics_provider.h
@@ -48,6 +48,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 {
diff --git a/cobalt/media/base/metrics_provider_test.cc b/cobalt/media/base/metrics_provider_test.cc
index 46a5470605fa..69952a6a823a 100644
--- a/cobalt/media/base/metrics_provider_test.cc
+++ b/cobalt/media/base/metrics_provider_test.cc
@@ -138,6 +138,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
diff --git a/cobalt/media/decoder_buffer_allocator.cc b/cobalt/media/decoder_buffer_allocator.cc
index 6c91b45a3592..87f9759cc85b 100644
--- a/cobalt/media/decoder_buffer_allocator.cc
+++ b/cobalt/media/decoder_buffer_allocator.cc
@@ -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);
@@ -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 {
@@ -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 {
diff --git a/cobalt/media/decoder_buffer_allocator.h b/cobalt/media/decoder_buffer_allocator.h
index da9877cce5ad..fb7cc5611b69 100644
--- a/cobalt/media/decoder_buffer_allocator.h
+++ b/cobalt/media/decoder_buffer_allocator.h
@@ -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"
@@ -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_;
diff --git a/tools/metrics/histograms/metadata/cobalt/histograms.xml b/tools/metrics/histograms/metadata/cobalt/histograms.xml
index 1cc9ae95c457..8cf39c3825be 100644
--- a/tools/metrics/histograms/metadata/cobalt/histograms.xml
+++ b/tools/metrics/histograms/metadata/cobalt/histograms.xml
@@ -311,6 +311,72 @@ Always run the pretty print utility on this file after editing:
Timing data for updating session of SbDrm.
+
+
+
+ borongchen@google.com
+ cobalt-team@google.com
+ Timing data for allocating buffer pool on demand.
+
+
+
+
+
+ borongchen@google.com
+ cobalt-team@google.com
+ Timing data for getting audio buffer budget.
+
+
+
+
+
+ borongchen@google.com
+ cobalt-team@google.com
+ Timing data for getting buffer allocation unit.
+
+
+
+
+
+ borongchen@google.com
+ cobalt-team@google.com
+
+ Timing data for getting buffer garbage collection duration threshold.
+
+
+
+
+
+
+ borongchen@google.com
+ cobalt-team@google.com
+ Timing data for getting initial buffer capacity.
+
+
+
+
+
+ borongchen@google.com
+ cobalt-team@google.com
+ Timing data for getting progressive buffer budget.
+
+
+
+
+
+ borongchen@google.com
+ cobalt-team@google.com
+ Timing data for getting video buffer budget.
+
+