| Index: media/cast/logging/logging_stats.cc
|
| diff --git a/media/cast/logging/logging_stats.cc b/media/cast/logging/logging_stats.cc
|
| index 2cdabcc5df2e1774b3a29ff7f5f2a5de55e3ad7f..e9e6d729b5eb980c03a5ab005c99630ae9f1451a 100644
|
| --- a/media/cast/logging/logging_stats.cc
|
| +++ b/media/cast/logging/logging_stats.cc
|
| @@ -2,20 +2,18 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "base/memory/linked_ptr.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| #include "media/cast/logging/logging_stats.h"
|
|
|
| +#include "base/logging.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +
|
| namespace media {
|
| namespace cast {
|
|
|
| LoggingStats::LoggingStats()
|
| : frame_stats_(),
|
| packet_stats_(),
|
| - generic_stats_(),
|
| - start_time_() {
|
| - memset(counts_, 0, sizeof(counts_));
|
| - memset(start_time_, 0, sizeof(start_time_));
|
| + generic_stats_() {
|
| }
|
|
|
| LoggingStats::~LoggingStats() {}
|
| @@ -24,7 +22,6 @@ void LoggingStats::Reset() {
|
| frame_stats_.clear();
|
| packet_stats_.clear();
|
| generic_stats_.clear();
|
| - memset(counts_, 0, sizeof(counts_));
|
| }
|
|
|
| void LoggingStats::InsertFrameEvent(const base::TimeTicks& time_of_event,
|
| @@ -44,7 +41,7 @@ void LoggingStats::InsertFrameEventWithSize(
|
| // Update size.
|
| FrameStatsMap::iterator it = frame_stats_.find(event);
|
| DCHECK(it != frame_stats_.end());
|
| - it->second->bitrate_kbps += frame_size;
|
| + it->second.sum_size += frame_size;
|
| }
|
|
|
| void LoggingStats::InsertFrameEventWithDelay(
|
| @@ -57,14 +54,11 @@ void LoggingStats::InsertFrameEventWithDelay(
|
| // Update size.
|
| FrameStatsMap::iterator it = frame_stats_.find(event);
|
| DCHECK(it != frame_stats_.end());
|
| - // Using the average delay as a counter, will divide by the counter when
|
| - // triggered.
|
| - it->second->avg_delay_ms += delay.InMilliseconds();
|
| - if (delay.InMilliseconds() > it->second->max_delay_ms)
|
| - it->second->max_delay_ms = delay.InMilliseconds();
|
| - if ((delay.InMilliseconds() < it->second->min_delay_ms) ||
|
| - (counts_[event] == 1) )
|
| - it->second->min_delay_ms = delay.InMilliseconds();
|
| + it->second.sum_delay += delay;
|
| + if (delay > it->second.max_delay || it->second.event_counter == 1)
|
| + it->second.max_delay = delay;
|
| + if (delay < it->second.min_delay || it->second.event_counter == 1)
|
| + it->second.min_delay = delay;
|
| }
|
|
|
| void LoggingStats::InsertBaseFrameEvent(const base::TimeTicks& time_of_event,
|
| @@ -75,12 +69,15 @@ void LoggingStats::InsertBaseFrameEvent(const base::TimeTicks& time_of_event,
|
| FrameStatsMap::iterator it = frame_stats_.find(event);
|
| if (it == frame_stats_.end()) {
|
| // New event.
|
| - start_time_[event] = time_of_event;
|
| - linked_ptr<FrameLogStats> stats(new FrameLogStats());
|
| + FrameLogStats stats;
|
| + stats.first_event_time = time_of_event;
|
| + stats.last_event_time = time_of_event;
|
| + stats.event_counter = 1;
|
| frame_stats_.insert(std::make_pair(event, stats));
|
| + } else {
|
| + it->second.last_event_time = time_of_event;
|
| + ++(it->second.event_counter);
|
| }
|
| -
|
| - ++counts_[event];
|
| }
|
|
|
| void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event,
|
| @@ -94,13 +91,17 @@ void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event,
|
| PacketStatsMap::iterator it = packet_stats_.find(event);
|
| if (it == packet_stats_.end()) {
|
| // New event.
|
| - start_time_[event] = time_of_event;
|
| - packet_stats_.insert(std::make_pair(event, size));
|
| + PacketLogStats stats;
|
| + stats.first_event_time = time_of_event;
|
| + stats.last_event_time = time_of_event;
|
| + stats.sum_size = size;
|
| + stats.event_counter = 1;
|
| + packet_stats_.insert(std::make_pair(event, stats));
|
| } else {
|
| - // Add to existing.
|
| - it->second += size;
|
| + // Add to an existing event.
|
| + it->second.sum_size += size;
|
| + ++(it->second.event_counter);
|
| }
|
| - ++counts_[event];
|
| }
|
|
|
| void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event,
|
| @@ -109,50 +110,39 @@ void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event,
|
| GenericStatsMap::iterator it = generic_stats_.find(event);
|
| if (it == generic_stats_.end()) {
|
| // New event.
|
| - start_time_[event] = time_of_event;
|
| - generic_stats_.insert(std::make_pair(event, value));
|
| + GenericLogStats stats;
|
| + stats.first_event_time = time_of_event;
|
| + stats.last_event_time = time_of_event;
|
| + stats.sum = value;
|
| + stats.sum_squared = value * value;
|
| + stats.min = value;
|
| + stats.max = value;
|
| + stats.event_counter = 1;
|
| + generic_stats_.insert(std::make_pair(event, stats));
|
| } else {
|
| - // Add to existing (will be used to compute average).
|
| - it->second += value;
|
| + // Add to existing event.
|
| + it->second.sum += value;
|
| + it->second.sum_squared += value * value;
|
| + ++(it->second.event_counter);
|
| + it->second.last_event_time = time_of_event;
|
| + if (it->second.min > value) {
|
| + it->second.min = value;
|
| + } else if (it->second.max < value) {
|
| + it->second.max = value;
|
| + }
|
| }
|
| - ++counts_[event];
|
| }
|
|
|
| -const FrameStatsMap* LoggingStats::GetFrameStatsData(
|
| - const base::TimeTicks& now) {
|
| - // Compute framerate and bitrate (when available).
|
| - FrameStatsMap::iterator it;
|
| - for (it = frame_stats_.begin(); it != frame_stats_.end(); ++it) {
|
| - base::TimeDelta time_diff = now - start_time_[it->first];
|
| - it->second->framerate_fps = counts_[it->first] / time_diff.InSecondsF();
|
| - if (it->second->bitrate_kbps > 0) {
|
| - it->second->bitrate_kbps = (8 / 1000) * it->second->bitrate_kbps /
|
| - time_diff.InSecondsF();
|
| - }
|
| - if (it->second->avg_delay_ms > 0)
|
| - it->second->avg_delay_ms /= counts_[it->first];
|
| - }
|
| - return &frame_stats_;
|
| +FrameStatsMap LoggingStats::GetFrameStatsData() const {
|
| + return frame_stats_;
|
| }
|
|
|
| -const PacketStatsMap* LoggingStats::GetPacketStatsData(
|
| - const base::TimeTicks& now) {
|
| - PacketStatsMap::iterator it;
|
| - for (it = packet_stats_.begin(); it != packet_stats_.end(); ++it) {
|
| - if (counts_[it->first] == 0) continue;
|
| - base::TimeDelta time_diff = now - start_time_[it->first];
|
| - it->second = (8 / 1000) * it->second / time_diff.InSecondsF();
|
| - }
|
| - return &packet_stats_;
|
| +PacketStatsMap LoggingStats::GetPacketStatsData() const {
|
| + return packet_stats_;
|
| }
|
|
|
| -const GenericStatsMap* LoggingStats::GetGenericStatsData() {
|
| - // Compute averages.
|
| - GenericStatsMap::iterator it;
|
| - for (it = generic_stats_.begin(); it != generic_stats_.end(); ++it) {
|
| - it->second /= counts_[ it->first];
|
| - }
|
| - return &generic_stats_;
|
| +GenericStatsMap LoggingStats::GetGenericStatsData() const {
|
| + return generic_stats_;
|
| }
|
|
|
| } // namespace cast
|
|
|