Index: media/base/audio_renderer_mixer.cc |
diff --git a/media/base/audio_renderer_mixer.cc b/media/base/audio_renderer_mixer.cc |
index e4c1e8005cdf30220bf156de29b4148a1c35a0ac..bdd49813878d27bc607454dd3a0900b69c10ef1c 100644 |
--- a/media/base/audio_renderer_mixer.cc |
+++ b/media/base/audio_renderer_mixer.cc |
@@ -10,20 +10,52 @@ |
#include "base/bind_helpers.h" |
#include "base/logging.h" |
#include "base/memory/ptr_util.h" |
+#include "base/metrics/histogram_macros.h" |
namespace media { |
enum { kPauseDelaySeconds = 10 }; |
+// Tracks the maximum value of a counter and logs it into a UMA histogram upon |
+// the destruciton. |
+class AudioRendererMixer::UMAMaxValueTracker { |
+ public: |
+ UMAMaxValueTracker(const std::string& histogram_name) |
+ : histogram_name_(histogram_name), count_(0), max_count_(0) {} |
+ |
+ ~UMAMaxValueTracker() { |
+ if (max_count_ && !histogram_name_.empty()) |
+ LOCAL_HISTOGRAM_CUSTOM_COUNTS(histogram_name_, max_count_, 1, 100, 100); |
tommi (sloooow) - chröme
2016/06/28 14:14:54
see other comment about using a variable here
o1ka
2016/06/29 10:11:26
Done.
|
+ } |
+ |
+ // Increments the counter, updates the maximum. |
+ void Increment() { |
tommi (sloooow) - chröme
2016/06/28 14:14:54
thread checks?
o1ka
2016/06/29 10:11:26
Updated a comment. It's used under a lock from mul
|
+ ++count_; |
+ if (max_count_ < count_) |
+ max_count_ = count_; |
+ } |
+ |
+ // Decrements the counter. |
+ void Decrement() { --count_; } |
+ |
+ private: |
+ const std::string histogram_name_; |
tommi (sloooow) - chröme
2016/06/28 14:14:54
const char*
o1ka
2016/06/29 10:11:26
Acknowledged.
|
+ int count_; |
+ int max_count_; |
+ DISALLOW_COPY_AND_ASSIGN(UMAMaxValueTracker); |
+}; |
+ |
AudioRendererMixer::AudioRendererMixer(const AudioParameters& output_params, |
- scoped_refptr<AudioRendererSink> sink) |
+ scoped_refptr<AudioRendererSink> sink, |
+ const std::string& histogram_name) |
: output_params_(output_params), |
audio_sink_(std::move(sink)), |
master_converter_(output_params, output_params, true), |
pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)), |
last_play_time_(base::TimeTicks::Now()), |
// Initialize |playing_| to true since Start() results in an auto-play. |
- playing_(true) { |
+ playing_(true), |
+ input_count_tracker_(new UMAMaxValueTracker(histogram_name)) { |
DCHECK(audio_sink_); |
audio_sink_->Initialize(output_params, this); |
audio_sink_->Start(); |
@@ -70,6 +102,8 @@ void AudioRendererMixer::AddMixerInput(const AudioParameters& input_params, |
} |
converter->second->AddInput(input); |
} |
+ |
+ input_count_tracker_->Increment(); |
} |
void AudioRendererMixer::RemoveMixerInput( |
@@ -91,6 +125,8 @@ void AudioRendererMixer::RemoveMixerInput( |
converters_.erase(converter); |
} |
} |
+ |
+ input_count_tracker_->Decrement(); |
} |
void AudioRendererMixer::AddErrorCallback(const base::Closure& error_cb) { |