asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 1 | // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style license |
| 4 | // that can be found in the LICENSE file in the root of the source |
| 5 | // tree. An additional intellectual property rights grant can be found |
| 6 | // in the file PATENTS. All contributing project authors may |
| 7 | // be found in the AUTHORS file in the root of the source tree. |
| 8 | // |
| 9 | |
Mirko Bonadei | c1c2a88 | 2018-09-06 13:34:51 +0200 | [diff] [blame] | 10 | #include "system_wrappers/include/metrics.h" |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 11 | |
asapersson | 1731c9c | 2016-11-30 00:29:09 -0800 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 14 | #include "absl/strings/string_view.h" |
| 15 | #include "rtc_base/string_utils.h" |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 16 | #include "rtc_base/synchronization/mutex.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/thread_annotations.h" |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 18 | |
| 19 | // Default implementation of histogram methods for WebRTC clients that do not |
| 20 | // want to provide their own implementation. |
| 21 | |
| 22 | namespace webrtc { |
| 23 | namespace metrics { |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 24 | class Histogram; |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 25 | |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 26 | namespace { |
| 27 | // Limit for the maximum number of sample values that can be stored. |
| 28 | // TODO(asapersson): Consider using bucket count (and set up |
| 29 | // linearly/exponentially spaced buckets) if samples are logged more frequently. |
asapersson | 7d56997 | 2016-05-24 06:03:38 -0700 | [diff] [blame] | 30 | const int kMaxSampleMapSize = 300; |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 31 | |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 32 | class RtcHistogram { |
| 33 | public: |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 34 | RtcHistogram(absl::string_view name, int min, int max, int bucket_count) |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 35 | : min_(min), max_(max), info_(name, min, max, bucket_count) { |
| 36 | RTC_DCHECK_GT(bucket_count, 0); |
| 37 | } |
| 38 | |
Byoungchan Lee | c065e73 | 2022-01-18 09:35:48 +0900 | [diff] [blame] | 39 | RtcHistogram(const RtcHistogram&) = delete; |
| 40 | RtcHistogram& operator=(const RtcHistogram&) = delete; |
| 41 | |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 42 | void Add(int sample) { |
asapersson | 1731c9c | 2016-11-30 00:29:09 -0800 | [diff] [blame] | 43 | sample = std::min(sample, max_); |
| 44 | sample = std::max(sample, min_ - 1); // Underflow bucket. |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 45 | |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 46 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 47 | if (info_.samples.size() == kMaxSampleMapSize && |
| 48 | info_.samples.find(sample) == info_.samples.end()) { |
| 49 | return; |
| 50 | } |
| 51 | ++info_.samples[sample]; |
| 52 | } |
| 53 | |
| 54 | // Returns a copy (or nullptr if there are no samples) and clears samples. |
| 55 | std::unique_ptr<SampleInfo> GetAndReset() { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 56 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 57 | if (info_.samples.empty()) |
| 58 | return nullptr; |
| 59 | |
| 60 | SampleInfo* copy = |
| 61 | new SampleInfo(info_.name, info_.min, info_.max, info_.bucket_count); |
asapersson | 1731c9c | 2016-11-30 00:29:09 -0800 | [diff] [blame] | 62 | |
| 63 | std::swap(info_.samples, copy->samples); |
| 64 | |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 65 | return std::unique_ptr<SampleInfo>(copy); |
| 66 | } |
| 67 | |
| 68 | const std::string& name() const { return info_.name; } |
| 69 | |
| 70 | // Functions only for testing. |
| 71 | void Reset() { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 72 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 73 | info_.samples.clear(); |
| 74 | } |
| 75 | |
| 76 | int NumEvents(int sample) const { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 77 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 78 | const auto it = info_.samples.find(sample); |
| 79 | return (it == info_.samples.end()) ? 0 : it->second; |
| 80 | } |
| 81 | |
| 82 | int NumSamples() const { |
| 83 | int num_samples = 0; |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 84 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 85 | for (const auto& sample : info_.samples) { |
| 86 | num_samples += sample.second; |
| 87 | } |
| 88 | return num_samples; |
| 89 | } |
| 90 | |
| 91 | int MinSample() const { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 92 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 93 | return (info_.samples.empty()) ? -1 : info_.samples.begin()->first; |
| 94 | } |
| 95 | |
Steve Anton | c1e6e86 | 2019-03-04 14:43:44 -0800 | [diff] [blame] | 96 | std::map<int, int> Samples() const { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 97 | MutexLock lock(&mutex_); |
Steve Anton | c1e6e86 | 2019-03-04 14:43:44 -0800 | [diff] [blame] | 98 | return info_.samples; |
| 99 | } |
| 100 | |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 101 | private: |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 102 | mutable Mutex mutex_; |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 103 | const int min_; |
| 104 | const int max_; |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 105 | SampleInfo info_ RTC_GUARDED_BY(mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | class RtcHistogramMap { |
| 109 | public: |
| 110 | RtcHistogramMap() {} |
| 111 | ~RtcHistogramMap() {} |
| 112 | |
Byoungchan Lee | c065e73 | 2022-01-18 09:35:48 +0900 | [diff] [blame] | 113 | RtcHistogramMap(const RtcHistogramMap&) = delete; |
| 114 | RtcHistogramMap& operator=(const RtcHistogramMap&) = delete; |
| 115 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 116 | Histogram* GetCountsHistogram(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 117 | int min, |
| 118 | int max, |
| 119 | int bucket_count) { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 120 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 121 | const auto& it = map_.find(name); |
| 122 | if (it != map_.end()) |
| 123 | return reinterpret_cast<Histogram*>(it->second.get()); |
| 124 | |
| 125 | RtcHistogram* hist = new RtcHistogram(name, min, max, bucket_count); |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 126 | map_.emplace(name, hist); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 127 | return reinterpret_cast<Histogram*>(hist); |
| 128 | } |
| 129 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 130 | Histogram* GetEnumerationHistogram(absl::string_view name, int boundary) { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 131 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 132 | const auto& it = map_.find(name); |
| 133 | if (it != map_.end()) |
| 134 | return reinterpret_cast<Histogram*>(it->second.get()); |
| 135 | |
| 136 | RtcHistogram* hist = new RtcHistogram(name, 1, boundary, boundary + 1); |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 137 | map_.emplace(name, hist); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 138 | return reinterpret_cast<Histogram*>(hist); |
| 139 | } |
| 140 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 141 | void GetAndReset(std::map<std::string, |
| 142 | std::unique_ptr<SampleInfo>, |
| 143 | rtc::AbslStringViewCmp>* histograms) { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 144 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 145 | for (const auto& kv : map_) { |
| 146 | std::unique_ptr<SampleInfo> info = kv.second->GetAndReset(); |
| 147 | if (info) |
| 148 | histograms->insert(std::make_pair(kv.first, std::move(info))); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Functions only for testing. |
| 153 | void Reset() { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 154 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 155 | for (const auto& kv : map_) |
| 156 | kv.second->Reset(); |
| 157 | } |
| 158 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 159 | int NumEvents(absl::string_view name, int sample) const { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 160 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 161 | const auto& it = map_.find(name); |
| 162 | return (it == map_.end()) ? 0 : it->second->NumEvents(sample); |
| 163 | } |
| 164 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 165 | int NumSamples(absl::string_view name) const { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 166 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 167 | const auto& it = map_.find(name); |
| 168 | return (it == map_.end()) ? 0 : it->second->NumSamples(); |
| 169 | } |
| 170 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 171 | int MinSample(absl::string_view name) const { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 172 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 173 | const auto& it = map_.find(name); |
| 174 | return (it == map_.end()) ? -1 : it->second->MinSample(); |
| 175 | } |
| 176 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 177 | std::map<int, int> Samples(absl::string_view name) const { |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 178 | MutexLock lock(&mutex_); |
Steve Anton | c1e6e86 | 2019-03-04 14:43:44 -0800 | [diff] [blame] | 179 | const auto& it = map_.find(name); |
| 180 | return (it == map_.end()) ? std::map<int, int>() : it->second->Samples(); |
| 181 | } |
| 182 | |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 183 | private: |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 184 | mutable Mutex mutex_; |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 185 | std::map<std::string, std::unique_ptr<RtcHistogram>, rtc::AbslStringViewCmp> |
| 186 | map_ RTC_GUARDED_BY(mutex_); |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | // RtcHistogramMap is allocated upon call to Enable(). |
| 190 | // The histogram getter functions, which return pointer values to the histograms |
| 191 | // in the map, are cached in WebRTC. Therefore, this memory is not freed by the |
| 192 | // application (the memory will be reclaimed by the OS). |
| 193 | static RtcHistogramMap* volatile g_rtc_histogram_map = nullptr; |
| 194 | |
| 195 | void CreateMap() { |
| 196 | RtcHistogramMap* map = rtc::AtomicOps::AcquireLoadPtr(&g_rtc_histogram_map); |
| 197 | if (map == nullptr) { |
| 198 | RtcHistogramMap* new_map = new RtcHistogramMap(); |
| 199 | RtcHistogramMap* old_map = rtc::AtomicOps::CompareAndSwapPtr( |
| 200 | &g_rtc_histogram_map, static_cast<RtcHistogramMap*>(nullptr), new_map); |
| 201 | if (old_map != nullptr) |
| 202 | delete new_map; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // Set the first time we start using histograms. Used to make sure Enable() is |
| 207 | // not called thereafter. |
| 208 | #if RTC_DCHECK_IS_ON |
| 209 | static volatile int g_rtc_histogram_called = 0; |
| 210 | #endif |
| 211 | |
| 212 | // Gets the map (or nullptr). |
| 213 | RtcHistogramMap* GetMap() { |
| 214 | #if RTC_DCHECK_IS_ON |
| 215 | rtc::AtomicOps::ReleaseStore(&g_rtc_histogram_called, 1); |
| 216 | #endif |
| 217 | return g_rtc_histogram_map; |
| 218 | } |
| 219 | } // namespace |
| 220 | |
Mirko Bonadei | c1c2a88 | 2018-09-06 13:34:51 +0200 | [diff] [blame] | 221 | #ifndef WEBRTC_EXCLUDE_METRICS_DEFAULT |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 222 | // Implementation of histogram methods in |
| 223 | // webrtc/system_wrappers/interface/metrics.h. |
| 224 | |
| 225 | // Histogram with exponentially spaced buckets. |
| 226 | // Creates (or finds) histogram. |
| 227 | // The returned histogram pointer is cached (and used for adding samples in |
| 228 | // subsequent calls). |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 229 | Histogram* HistogramFactoryGetCounts(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 230 | int min, |
| 231 | int max, |
| 232 | int bucket_count) { |
henrik.lundin | f29e05d | 2016-12-01 09:58:45 -0800 | [diff] [blame] | 233 | // TODO(asapersson): Alternative implementation will be needed if this |
| 234 | // histogram type should be truly exponential. |
| 235 | return HistogramFactoryGetCountsLinear(name, min, max, bucket_count); |
| 236 | } |
| 237 | |
| 238 | // Histogram with linearly spaced buckets. |
| 239 | // Creates (or finds) histogram. |
| 240 | // The returned histogram pointer is cached (and used for adding samples in |
| 241 | // subsequent calls). |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 242 | Histogram* HistogramFactoryGetCountsLinear(absl::string_view name, |
henrik.lundin | f29e05d | 2016-12-01 09:58:45 -0800 | [diff] [blame] | 243 | int min, |
| 244 | int max, |
| 245 | int bucket_count) { |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 246 | RtcHistogramMap* map = GetMap(); |
| 247 | if (!map) |
| 248 | return nullptr; |
| 249 | |
| 250 | return map->GetCountsHistogram(name, min, max, bucket_count); |
| 251 | } |
| 252 | |
| 253 | // Histogram with linearly spaced buckets. |
| 254 | // Creates (or finds) histogram. |
| 255 | // The returned histogram pointer is cached (and used for adding samples in |
| 256 | // subsequent calls). |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 257 | Histogram* HistogramFactoryGetEnumeration(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 258 | int boundary) { |
| 259 | RtcHistogramMap* map = GetMap(); |
| 260 | if (!map) |
| 261 | return nullptr; |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 262 | |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 263 | return map->GetEnumerationHistogram(name, boundary); |
| 264 | } |
| 265 | |
Qingsi Wang | d6eb71e | 2018-06-26 12:30:04 -0700 | [diff] [blame] | 266 | // Our default implementation reuses the non-sparse histogram. |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 267 | Histogram* SparseHistogramFactoryGetEnumeration(absl::string_view name, |
Qingsi Wang | d6eb71e | 2018-06-26 12:30:04 -0700 | [diff] [blame] | 268 | int boundary) { |
| 269 | return HistogramFactoryGetEnumeration(name, boundary); |
| 270 | } |
| 271 | |
Artem Titov | f067192 | 2021-07-27 12:40:17 +0200 | [diff] [blame] | 272 | // Fast path. Adds `sample` to cached `histogram_pointer`. |
sakal | 2a5f371 | 2016-09-09 00:11:48 -0700 | [diff] [blame] | 273 | void HistogramAdd(Histogram* histogram_pointer, int sample) { |
sakal | 2a5f371 | 2016-09-09 00:11:48 -0700 | [diff] [blame] | 274 | RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer); |
| 275 | ptr->Add(sample); |
| 276 | } |
| 277 | |
Mirko Bonadei | c1c2a88 | 2018-09-06 13:34:51 +0200 | [diff] [blame] | 278 | #endif // WEBRTC_EXCLUDE_METRICS_DEFAULT |
| 279 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 280 | SampleInfo::SampleInfo(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 281 | int min, |
| 282 | int max, |
| 283 | size_t bucket_count) |
| 284 | : name(name), min(min), max(max), bucket_count(bucket_count) {} |
| 285 | |
| 286 | SampleInfo::~SampleInfo() {} |
| 287 | |
Mirko Bonadei | 17f4878 | 2018-09-28 08:51:10 +0200 | [diff] [blame] | 288 | // Implementation of global functions in metrics.h. |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 289 | void Enable() { |
| 290 | RTC_DCHECK(g_rtc_histogram_map == nullptr); |
| 291 | #if RTC_DCHECK_IS_ON |
| 292 | RTC_DCHECK_EQ(0, rtc::AtomicOps::AcquireLoad(&g_rtc_histogram_called)); |
| 293 | #endif |
| 294 | CreateMap(); |
| 295 | } |
| 296 | |
| 297 | void GetAndReset( |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 298 | std::map<std::string, std::unique_ptr<SampleInfo>, rtc::AbslStringViewCmp>* |
| 299 | histograms) { |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 300 | histograms->clear(); |
| 301 | RtcHistogramMap* map = GetMap(); |
| 302 | if (map) |
| 303 | map->GetAndReset(histograms); |
| 304 | } |
| 305 | |
| 306 | void Reset() { |
| 307 | RtcHistogramMap* map = GetMap(); |
| 308 | if (map) |
| 309 | map->Reset(); |
| 310 | } |
| 311 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 312 | int NumEvents(absl::string_view name, int sample) { |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 313 | RtcHistogramMap* map = GetMap(); |
| 314 | return map ? map->NumEvents(name, sample) : 0; |
| 315 | } |
| 316 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 317 | int NumSamples(absl::string_view name) { |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 318 | RtcHistogramMap* map = GetMap(); |
| 319 | return map ? map->NumSamples(name) : 0; |
| 320 | } |
| 321 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 322 | int MinSample(absl::string_view name) { |
asapersson | 01d70a3 | 2016-05-20 06:29:46 -0700 | [diff] [blame] | 323 | RtcHistogramMap* map = GetMap(); |
| 324 | return map ? map->MinSample(name) : -1; |
| 325 | } |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 326 | |
Ali Tofigh | 969c135 | 2022-05-13 10:26:58 +0200 | [diff] [blame] | 327 | std::map<int, int> Samples(absl::string_view name) { |
Steve Anton | c1e6e86 | 2019-03-04 14:43:44 -0800 | [diff] [blame] | 328 | RtcHistogramMap* map = GetMap(); |
| 329 | return map ? map->Samples(name) : std::map<int, int>(); |
| 330 | } |
| 331 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 +0000 | [diff] [blame] | 332 | } // namespace metrics |
| 333 | } // namespace webrtc |