OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 #include "webrtc/base/histogram.h" |
| 11 |
| 12 #include "webrtc/base/checks.h" |
| 13 #include "webrtc/system_wrappers/include/metrics.h" |
| 14 |
| 15 namespace rtc { |
| 16 |
| 17 HistogramBase::HistogramBase(const char* name, |
| 18 Type type, |
| 19 int min, |
| 20 int max, |
| 21 int bucket_count) |
| 22 : histogram_(type == Type::kCounts |
| 23 ? webrtc::metrics::HistogramFactoryGetCounts(name, |
| 24 min, |
| 25 max, |
| 26 bucket_count) |
| 27 : webrtc::metrics::HistogramFactoryGetCountsLinear( |
| 28 name, |
| 29 min, |
| 30 max, |
| 31 bucket_count)) { |
| 32 RTC_DCHECK(type == Type::kCounts || type == Type::kCountsLinear); |
| 33 } |
| 34 |
| 35 HistogramBase::HistogramBase(const char* name, Type type, int boundary) |
| 36 : histogram_( |
| 37 webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) { |
| 38 // Enumerations should only specify boundary, other types should use the other |
| 39 // constructor. |
| 40 RTC_DCHECK(type == Type::kEnumeration); |
| 41 } |
| 42 |
| 43 void HistogramBase::AddSample(int sample) const { |
| 44 webrtc::metrics::HistogramAdd(histogram_, sample); |
| 45 } |
| 46 |
| 47 // Histograms for counts with exponentionally spaced buckets. |
| 48 Histogram::Histogram(const char* name, int max) : Histogram(name, 1, max) {} |
| 49 Histogram::Histogram(const char* name, int min, int max) |
| 50 : Histogram(name, min, max, 50) {} |
| 51 Histogram::Histogram(const char* name, int min, int max, int bucket_count) |
| 52 : HistogramBase(name, Type::kCounts, min, max, bucket_count) {} |
| 53 |
| 54 |
| 55 // Histograms with linear spaced buckets. |
| 56 HistogramLinear::HistogramLinear(const char* name, int max) |
| 57 : HistogramLinear(name, 1, max) {} |
| 58 HistogramLinear::HistogramLinear(const char* name, int min, int max) |
| 59 : HistogramLinear(name, min, max, 50) {} |
| 60 HistogramLinear::HistogramLinear(const char* name, |
| 61 int min, |
| 62 int max, |
| 63 int bucket_count) |
| 64 : HistogramBase(name, Type::kCountsLinear, min, max, bucket_count) {} |
| 65 |
| 66 // Histograms for enumerations, values in [0, boundary) are valid. |
| 67 HistogramEnumeration::HistogramEnumeration(const char* name, int boundary) |
| 68 : HistogramBase(name, Type::kEnumeration, boundary), |
| 69 boundary_(boundary) {} |
| 70 void HistogramEnumeration::AddSample(int sample) { |
| 71 RTC_DCHECK_GE(sample, 0); |
| 72 RTC_DCHECK_LE(sample, boundary_); |
| 73 HistogramBase::AddSample(sample); |
| 74 } |
| 75 |
| 76 // Histograms for booleans. |
| 77 HistogramBoolean::HistogramBoolean(const char* name) |
| 78 : HistogramEnumeration(name, 2) {} |
| 79 void HistogramBoolean::AddSample(bool sample) { |
| 80 HistogramEnumeration::AddSample(sample ? 1 : 0); |
| 81 } |
| 82 |
| 83 // Histograms for percentages. |
| 84 HistogramPercentage::HistogramPercentage(const char* name) |
| 85 : HistogramEnumeration(name, 101) {} |
| 86 |
| 87 } // namespace rtc |
OLD | NEW |