Chromium Code Reviews| Index: media/base/android/media_statistics.cc |
| diff --git a/media/base/android/media_statistics.cc b/media/base/android/media_statistics.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5dc832b4da3ab65b7a5e3c85fa113d12e992bb61 |
| --- /dev/null |
| +++ b/media/base/android/media_statistics.cc |
| @@ -0,0 +1,116 @@ |
| +#include "media/base/android/media_statistics.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/metrics/histogram_macros.h" |
| +#include "media/base/android/demuxer_stream_player_params.h" |
| + |
| +namespace media { |
| + |
| +namespace { |
| + |
| +// Minimum duration to report. |
| +const int kMinDurationInSeconds = 2; |
| + |
| +// Maximum duration to report. |
| +const int kMaxDurationInSeconds = 3600; |
| + |
| +// Number of slots in the histogram for duration. |
| +const int kNumDurationSlots = 1800; |
|
Ilya Sherman
2015/09/30 04:20:03
nit: Please leave a blank line after this one, for
Ilya Sherman
2015/09/30 04:20:03
Sorry, 1800 buckets is far too many for a histogra
Tima Vaisburd
2015/09/30 18:50:09
Done.
Tima Vaisburd
2015/09/30 18:50:09
Sorry, it was my bad thinking. Changed to 60 inste
|
| +} |
| + |
| +void FrameStatistics::AddFrame() { |
| + ++total; |
| +} |
| + |
| +void FrameStatistics::AddLateFrame(base::TimeDelta delay) { |
| + // Do not collect the late frame if this is the first frame after start. |
| + // This simplifies the MediaSourcePlayer case. |
| + if (total == 1) |
| + return; |
| + |
| + DVLOG(1) << stream_type << " " << __FUNCTION__ << " delay:" << delay |
| + << " total:" << total; |
| + ++late; |
| +} |
| + |
| +MediaStatistics::MediaStatistics() |
| + : audio_frames_(DemuxerStream::AUDIO), |
| + video_frames_(DemuxerStream::VIDEO), |
| + num_starvations_(0) { |
| +} |
| + |
| +MediaStatistics::~MediaStatistics() {} |
| + |
| +void MediaStatistics::Start() { |
| + DVLOG(1) << "MediaStatistics::" << __FUNCTION__; |
|
xhwang
2015/09/30 21:02:57
nit: class name not necessary in the log..
Tima Vaisburd
2015/10/01 20:05:15
Removed everywhere in this class.
|
| + |
| + Clear(); |
| + start_time_ = base::TimeTicks::Now(); |
| +} |
| + |
| +void MediaStatistics::AddStarvation() { |
| + DVLOG(1) << "MediaStatistics::" << __FUNCTION__; |
| + ++num_starvations_; |
| +} |
| + |
| +void MediaStatistics::StopAndReport() { |
| + DVLOG(1) << "MediaStatistics::" << __FUNCTION__; |
| + |
| + if (start_time_.is_null()) |
| + return; // skip if there was no prior Start(). |
| + |
| + base::TimeDelta duration = base::TimeTicks::Now() - start_time_; |
|
qinmin
2015/09/29 23:47:44
The duration is calculated from system time. Shoul
Tima Vaisburd
2015/10/01 20:05:15
Done.
|
| + |
| + // Reset start time. |
| + start_time_ = base::TimeTicks(); |
| + |
| + if (duration < base::TimeDelta::FromSeconds(kMinDurationInSeconds)) |
| + return; // duration is too short. |
| + |
| + if (duration > base::TimeDelta::FromSeconds(kMaxDurationInSeconds)) |
| + return; // duration is too long. |
| + |
| + Report(duration); |
| +} |
| + |
| +void MediaStatistics::Clear() { |
| + audio_frames_.Clear(); |
| + video_frames_.Clear(); |
| + num_starvations_ = 0; |
| +} |
| + |
| +void MediaStatistics::Report(base::TimeDelta duration) { |
| + DVLOG(1) << "MediaStatistics::" << __FUNCTION__ << " duration:" << duration |
| + << " audio frames:" |
| + << audio_frames_.late << "/" << audio_frames_.total |
| + << " video frames:" |
| + << video_frames_.late << "/" << video_frames_.total; |
| + |
| + UMA_HISTOGRAM_CUSTOM_TIMES( |
| + "Media.MSE.Duration", duration, |
| + base::TimeDelta::FromSeconds(kMinDurationInSeconds), |
| + base::TimeDelta::FromSeconds(kMaxDurationInSeconds), kNumDurationSlots); |
| + |
| + // Number of late frames per one million frames. |
| + |
| + if (audio_frames_.total) { |
| + UMA_HISTOGRAM_COUNTS("Media.MSE.LateAudioFrames", |
| + 1000000 * audio_frames_.late / audio_frames_.total); |
| + } |
| + |
| + if (video_frames_.total) { |
| + UMA_HISTOGRAM_COUNTS("Media.MSE.LateVideoFrames", |
| + 1000000 * video_frames_.late / video_frames_.total); |
|
xhwang
2015/09/30 21:02:57
hmm, I wonder why we report frames per milliion fr
Tima Vaisburd
2015/10/01 20:05:15
We expect these values to be less than 1%, so part
|
| + } |
| + |
| + // Number of starvations per one million frames. |
| + |
| + uint32_t total_frames = |
| + audio_frames_.total ? audio_frames_.total : video_frames_.total; |
| + if (total_frames) { |
| + UMA_HISTOGRAM_COUNTS("Media.MSE.Starvations", |
| + 1000000 * num_starvations_ / total_frames); |
| + } |
| +} |
| + |
| +} // namespace media |