| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cmath> |
| 6 |
| 5 #include "media/cast/logging/stats_event_subscriber.h" | 7 #include "media/cast/logging/stats_event_subscriber.h" |
| 6 | 8 |
| 7 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 | 13 |
| 12 #define STAT_ENUM_TO_STRING(enum) \ | 14 #define STAT_ENUM_TO_STRING(enum) \ |
| 13 case enum: \ | 15 case enum: \ |
| 14 return #enum | 16 return #enum |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 void StatsEventSubscriber::SimpleHistogram::Reset() { | 60 void StatsEventSubscriber::SimpleHistogram::Reset() { |
| 59 buckets_.assign(buckets_.size(), 0); | 61 buckets_.assign(buckets_.size(), 0); |
| 60 } | 62 } |
| 61 | 63 |
| 62 scoped_ptr<base::ListValue> | 64 scoped_ptr<base::ListValue> |
| 63 StatsEventSubscriber::SimpleHistogram::GetHistogram() const { | 65 StatsEventSubscriber::SimpleHistogram::GetHistogram() const { |
| 64 scoped_ptr<base::ListValue> histo(new base::ListValue); | 66 scoped_ptr<base::ListValue> histo(new base::ListValue); |
| 65 | 67 |
| 66 scoped_ptr<base::DictionaryValue> bucket(new base::DictionaryValue); | 68 scoped_ptr<base::DictionaryValue> bucket(new base::DictionaryValue); |
| 67 | 69 |
| 68 bucket->SetString("bucket", base::StringPrintf("< %" PRId64, min_)); | 70 if (buckets_.front()) { |
| 69 bucket->SetInteger("count", buckets_.front()); | 71 bucket->SetInteger(base::StringPrintf("<%" PRId64, min_), |
| 70 histo->Append(bucket.release()); | 72 buckets_.front()); |
| 71 | |
| 72 for (size_t i = 1; i < buckets_.size() - 1; i++) { | |
| 73 bucket.reset(new base::DictionaryValue); | |
| 74 | |
| 75 int64 lower = min_ + (i - 1) * width_; | |
| 76 int64 upper = lower + width_ - 1; | |
| 77 bucket->SetString( | |
| 78 "bucket", base::StringPrintf("%" PRId64 " - %" PRId64, lower, upper)); | |
| 79 bucket->SetInteger("count", buckets_[i]); | |
| 80 histo->Append(bucket.release()); | 73 histo->Append(bucket.release()); |
| 81 } | 74 } |
| 82 | 75 |
| 83 bucket.reset(new base::DictionaryValue); | 76 for (size_t i = 1; i < buckets_.size() - 1; i++) { |
| 77 if (!buckets_[i]) |
| 78 continue; |
| 79 bucket.reset(new base::DictionaryValue); |
| 80 int64 lower = min_ + (i - 1) * width_; |
| 81 int64 upper = lower + width_ - 1; |
| 82 bucket->SetInteger( |
| 83 base::StringPrintf("%" PRId64 "-%" PRId64, lower, upper), |
| 84 buckets_[i]); |
| 85 histo->Append(bucket.release()); |
| 86 } |
| 84 | 87 |
| 85 bucket->SetString("bucket", base::StringPrintf(">= %" PRId64, max_)); | 88 if (buckets_.back()) { |
| 86 bucket->SetInteger("count", buckets_.back()); | 89 bucket.reset(new base::DictionaryValue); |
| 87 histo->Append(bucket.release()); | 90 bucket->SetInteger(base::StringPrintf(">=%" PRId64, max_), |
| 88 | 91 buckets_.back()); |
| 92 histo->Append(bucket.release()); |
| 93 } |
| 89 return histo.Pass(); | 94 return histo.Pass(); |
| 90 } | 95 } |
| 91 | 96 |
| 92 StatsEventSubscriber::StatsEventSubscriber( | 97 StatsEventSubscriber::StatsEventSubscriber( |
| 93 EventMediaType event_media_type, | 98 EventMediaType event_media_type, |
| 94 base::TickClock* clock, | 99 base::TickClock* clock, |
| 95 ReceiverTimeOffsetEstimator* offset_estimator) | 100 ReceiverTimeOffsetEstimator* offset_estimator) |
| 96 : event_media_type_(event_media_type), | 101 : event_media_type_(event_media_type), |
| 97 clock_(clock), | 102 clock_(clock), |
| 98 offset_estimator_(offset_estimator), | 103 offset_estimator_(offset_estimator), |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 215 } |
| 211 | 216 |
| 212 scoped_ptr<base::DictionaryValue> StatsEventSubscriber::GetStats() const { | 217 scoped_ptr<base::DictionaryValue> StatsEventSubscriber::GetStats() const { |
| 213 StatsMap stats_map; | 218 StatsMap stats_map; |
| 214 GetStatsInternal(&stats_map); | 219 GetStatsInternal(&stats_map); |
| 215 scoped_ptr<base::DictionaryValue> ret(new base::DictionaryValue); | 220 scoped_ptr<base::DictionaryValue> ret(new base::DictionaryValue); |
| 216 | 221 |
| 217 scoped_ptr<base::DictionaryValue> stats(new base::DictionaryValue); | 222 scoped_ptr<base::DictionaryValue> stats(new base::DictionaryValue); |
| 218 for (StatsMap::const_iterator it = stats_map.begin(); it != stats_map.end(); | 223 for (StatsMap::const_iterator it = stats_map.begin(); it != stats_map.end(); |
| 219 ++it) { | 224 ++it) { |
| 220 stats->SetDouble(CastStatToString(it->first), it->second); | 225 // Round to 3 digits after the decimal point. |
| 226 stats->SetDouble(CastStatToString(it->first), |
| 227 round(it->second * 1000.0) / 1000.0); |
| 221 } | 228 } |
| 222 for (HistogramMap::const_iterator it = histograms_.begin(); | 229 for (HistogramMap::const_iterator it = histograms_.begin(); |
| 223 it != histograms_.end(); | 230 it != histograms_.end(); |
| 224 ++it) { | 231 ++it) { |
| 225 stats->Set(CastStatToString(it->first), | 232 stats->Set(CastStatToString(it->first), |
| 226 it->second->GetHistogram().release()); | 233 it->second->GetHistogram().release()); |
| 227 } | 234 } |
| 228 | 235 |
| 229 ret->Set(event_media_type_ == AUDIO_EVENT ? "audio" : "video", | 236 ret->Set(event_media_type_ == AUDIO_EVENT ? "audio" : "video", |
| 230 stats.release()); | 237 stats.release()); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 : event_counter(0), sum_size(0) {} | 656 : event_counter(0), sum_size(0) {} |
| 650 StatsEventSubscriber::PacketLogStats::~PacketLogStats() {} | 657 StatsEventSubscriber::PacketLogStats::~PacketLogStats() {} |
| 651 | 658 |
| 652 StatsEventSubscriber::FrameInfo::FrameInfo() : encoded(false) { | 659 StatsEventSubscriber::FrameInfo::FrameInfo() : encoded(false) { |
| 653 } | 660 } |
| 654 StatsEventSubscriber::FrameInfo::~FrameInfo() { | 661 StatsEventSubscriber::FrameInfo::~FrameInfo() { |
| 655 } | 662 } |
| 656 | 663 |
| 657 } // namespace cast | 664 } // namespace cast |
| 658 } // namespace media | 665 } // namespace media |
| OLD | NEW |