asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 | [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 11:34:51 | [diff] [blame] | 10 | #include "system_wrappers/include/metrics.h" |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 11 | |
asapersson | 1731c9c | 2016-11-30 08:29:09 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 14 | #include "absl/strings/string_view.h" |
| 15 | #include "rtc_base/string_utils.h" |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 16 | #include "rtc_base/synchronization/mutex.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "rtc_base/thread_annotations.h" |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 | [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 13:29:46 | [diff] [blame] | 24 | class Histogram; |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 | [diff] [blame] | 25 | |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 13:03:38 | [diff] [blame] | 30 | const int kMaxSampleMapSize = 300; |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 | [diff] [blame] | 31 | |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 32 | class RtcHistogram { |
| 33 | public: |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 34 | RtcHistogram(absl::string_view name, int min, int max, int bucket_count) |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 00:35:48 | [diff] [blame] | 39 | RtcHistogram(const RtcHistogram&) = delete; |
| 40 | RtcHistogram& operator=(const RtcHistogram&) = delete; |
| 41 | |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 42 | void Add(int sample) { |
asapersson | 1731c9c | 2016-11-30 08:29:09 | [diff] [blame] | 43 | sample = std::min(sample, max_); |
| 44 | sample = std::max(sample, min_ - 1); // Underflow bucket. |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 45 | |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 46 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 21:04:37 | [diff] [blame] | 56 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 08:29:09 | [diff] [blame] | 62 | |
| 63 | std::swap(info_.samples, copy->samples); |
| 64 | |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 21:04:37 | [diff] [blame] | 72 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 73 | info_.samples.clear(); |
| 74 | } |
| 75 | |
| 76 | int NumEvents(int sample) const { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 77 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 21:04:37 | [diff] [blame] | 84 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 21:04:37 | [diff] [blame] | 92 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 93 | return (info_.samples.empty()) ? -1 : info_.samples.begin()->first; |
| 94 | } |
| 95 | |
Steve Anton | c1e6e86 | 2019-03-04 22:43:44 | [diff] [blame] | 96 | std::map<int, int> Samples() const { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 97 | MutexLock lock(&mutex_); |
Steve Anton | c1e6e86 | 2019-03-04 22:43:44 | [diff] [blame] | 98 | return info_.samples; |
| 99 | } |
| 100 | |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 101 | private: |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 102 | mutable Mutex mutex_; |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 103 | const int min_; |
| 104 | const int max_; |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 105 | SampleInfo info_ RTC_GUARDED_BY(mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | class RtcHistogramMap { |
| 109 | public: |
| 110 | RtcHistogramMap() {} |
| 111 | ~RtcHistogramMap() {} |
| 112 | |
Byoungchan Lee | c065e73 | 2022-01-18 00:35:48 | [diff] [blame] | 113 | RtcHistogramMap(const RtcHistogramMap&) = delete; |
| 114 | RtcHistogramMap& operator=(const RtcHistogramMap&) = delete; |
| 115 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 116 | Histogram* GetCountsHistogram(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 117 | int min, |
| 118 | int max, |
| 119 | int bucket_count) { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 120 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 126 | map_.emplace(name, hist); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 127 | return reinterpret_cast<Histogram*>(hist); |
| 128 | } |
| 129 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 130 | Histogram* GetEnumerationHistogram(absl::string_view name, int boundary) { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 131 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 137 | map_.emplace(name, hist); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 138 | return reinterpret_cast<Histogram*>(hist); |
| 139 | } |
| 140 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 141 | void GetAndReset(std::map<std::string, |
| 142 | std::unique_ptr<SampleInfo>, |
| 143 | rtc::AbslStringViewCmp>* histograms) { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 144 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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 21:04:37 | [diff] [blame] | 154 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 155 | for (const auto& kv : map_) |
| 156 | kv.second->Reset(); |
| 157 | } |
| 158 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 159 | int NumEvents(absl::string_view name, int sample) const { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 160 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 161 | const auto& it = map_.find(name); |
| 162 | return (it == map_.end()) ? 0 : it->second->NumEvents(sample); |
| 163 | } |
| 164 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 165 | int NumSamples(absl::string_view name) const { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 166 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 167 | const auto& it = map_.find(name); |
| 168 | return (it == map_.end()) ? 0 : it->second->NumSamples(); |
| 169 | } |
| 170 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 171 | int MinSample(absl::string_view name) const { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 172 | MutexLock lock(&mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 173 | const auto& it = map_.find(name); |
| 174 | return (it == map_.end()) ? -1 : it->second->MinSample(); |
| 175 | } |
| 176 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 177 | std::map<int, int> Samples(absl::string_view name) const { |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 178 | MutexLock lock(&mutex_); |
Steve Anton | c1e6e86 | 2019-03-04 22:43:44 | [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 13:29:46 | [diff] [blame] | 183 | private: |
Markus Handell | 85585f4 | 2020-07-08 21:04:37 | [diff] [blame] | 184 | mutable Mutex mutex_; |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 185 | std::map<std::string, std::unique_ptr<RtcHistogram>, rtc::AbslStringViewCmp> |
| 186 | map_ RTC_GUARDED_BY(mutex_); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [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). |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 193 | static std::atomic<RtcHistogramMap*> g_rtc_histogram_map(nullptr); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 194 | |
| 195 | void CreateMap() { |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 196 | RtcHistogramMap* map = g_rtc_histogram_map.load(std::memory_order_acquire); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 197 | if (map == nullptr) { |
| 198 | RtcHistogramMap* new_map = new RtcHistogramMap(); |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 199 | if (!g_rtc_histogram_map.compare_exchange_strong(map, new_map)) |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 200 | delete new_map; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // Set the first time we start using histograms. Used to make sure Enable() is |
| 205 | // not called thereafter. |
| 206 | #if RTC_DCHECK_IS_ON |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 207 | static std::atomic<int> g_rtc_histogram_called(0); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 208 | #endif |
| 209 | |
| 210 | // Gets the map (or nullptr). |
| 211 | RtcHistogramMap* GetMap() { |
| 212 | #if RTC_DCHECK_IS_ON |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 213 | g_rtc_histogram_called.store(1, std::memory_order_release); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 214 | #endif |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 215 | return g_rtc_histogram_map.load(); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 216 | } |
| 217 | } // namespace |
| 218 | |
Mirko Bonadei | c1c2a88 | 2018-09-06 11:34:51 | [diff] [blame] | 219 | #ifndef WEBRTC_EXCLUDE_METRICS_DEFAULT |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 220 | // Implementation of histogram methods in |
| 221 | // webrtc/system_wrappers/interface/metrics.h. |
| 222 | |
| 223 | // Histogram with exponentially spaced buckets. |
| 224 | // Creates (or finds) histogram. |
| 225 | // The returned histogram pointer is cached (and used for adding samples in |
| 226 | // subsequent calls). |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 227 | Histogram* HistogramFactoryGetCounts(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 228 | int min, |
| 229 | int max, |
| 230 | int bucket_count) { |
henrik.lundin | f29e05d | 2016-12-01 17:58:45 | [diff] [blame] | 231 | // TODO(asapersson): Alternative implementation will be needed if this |
| 232 | // histogram type should be truly exponential. |
| 233 | return HistogramFactoryGetCountsLinear(name, min, max, bucket_count); |
| 234 | } |
| 235 | |
| 236 | // Histogram with linearly spaced buckets. |
| 237 | // Creates (or finds) histogram. |
| 238 | // The returned histogram pointer is cached (and used for adding samples in |
| 239 | // subsequent calls). |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 240 | Histogram* HistogramFactoryGetCountsLinear(absl::string_view name, |
henrik.lundin | f29e05d | 2016-12-01 17:58:45 | [diff] [blame] | 241 | int min, |
| 242 | int max, |
| 243 | int bucket_count) { |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 244 | RtcHistogramMap* map = GetMap(); |
| 245 | if (!map) |
| 246 | return nullptr; |
| 247 | |
| 248 | return map->GetCountsHistogram(name, min, max, bucket_count); |
| 249 | } |
| 250 | |
| 251 | // Histogram with linearly spaced buckets. |
| 252 | // Creates (or finds) histogram. |
| 253 | // The returned histogram pointer is cached (and used for adding samples in |
| 254 | // subsequent calls). |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 255 | Histogram* HistogramFactoryGetEnumeration(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 256 | int boundary) { |
| 257 | RtcHistogramMap* map = GetMap(); |
| 258 | if (!map) |
| 259 | return nullptr; |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 | [diff] [blame] | 260 | |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 261 | return map->GetEnumerationHistogram(name, boundary); |
| 262 | } |
| 263 | |
Qingsi Wang | d6eb71e | 2018-06-26 19:30:04 | [diff] [blame] | 264 | // Our default implementation reuses the non-sparse histogram. |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 265 | Histogram* SparseHistogramFactoryGetEnumeration(absl::string_view name, |
Qingsi Wang | d6eb71e | 2018-06-26 19:30:04 | [diff] [blame] | 266 | int boundary) { |
| 267 | return HistogramFactoryGetEnumeration(name, boundary); |
| 268 | } |
| 269 | |
Artem Titov | f067192 | 2021-07-27 10:40:17 | [diff] [blame] | 270 | // Fast path. Adds `sample` to cached `histogram_pointer`. |
sakal | 2a5f371 | 2016-09-09 07:11:48 | [diff] [blame] | 271 | void HistogramAdd(Histogram* histogram_pointer, int sample) { |
sakal | 2a5f371 | 2016-09-09 07:11:48 | [diff] [blame] | 272 | RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer); |
| 273 | ptr->Add(sample); |
| 274 | } |
| 275 | |
Mirko Bonadei | c1c2a88 | 2018-09-06 11:34:51 | [diff] [blame] | 276 | #endif // WEBRTC_EXCLUDE_METRICS_DEFAULT |
| 277 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 278 | SampleInfo::SampleInfo(absl::string_view name, |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 279 | int min, |
| 280 | int max, |
| 281 | size_t bucket_count) |
| 282 | : name(name), min(min), max(max), bucket_count(bucket_count) {} |
| 283 | |
| 284 | SampleInfo::~SampleInfo() {} |
| 285 | |
Mirko Bonadei | 17f4878 | 2018-09-28 06:51:10 | [diff] [blame] | 286 | // Implementation of global functions in metrics.h. |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 287 | void Enable() { |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 288 | RTC_DCHECK(g_rtc_histogram_map.load() == nullptr); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 289 | #if RTC_DCHECK_IS_ON |
Niels Möller | 7a66900 | 2022-06-27 07:47:02 | [diff] [blame] | 290 | RTC_DCHECK_EQ(0, g_rtc_histogram_called.load(std::memory_order_acquire)); |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 291 | #endif |
| 292 | CreateMap(); |
| 293 | } |
| 294 | |
| 295 | void GetAndReset( |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 296 | std::map<std::string, std::unique_ptr<SampleInfo>, rtc::AbslStringViewCmp>* |
| 297 | histograms) { |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 298 | histograms->clear(); |
| 299 | RtcHistogramMap* map = GetMap(); |
| 300 | if (map) |
| 301 | map->GetAndReset(histograms); |
| 302 | } |
| 303 | |
| 304 | void Reset() { |
| 305 | RtcHistogramMap* map = GetMap(); |
| 306 | if (map) |
| 307 | map->Reset(); |
| 308 | } |
| 309 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 310 | int NumEvents(absl::string_view name, int sample) { |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 311 | RtcHistogramMap* map = GetMap(); |
| 312 | return map ? map->NumEvents(name, sample) : 0; |
| 313 | } |
| 314 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 315 | int NumSamples(absl::string_view name) { |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 316 | RtcHistogramMap* map = GetMap(); |
| 317 | return map ? map->NumSamples(name) : 0; |
| 318 | } |
| 319 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 320 | int MinSample(absl::string_view name) { |
asapersson | 01d70a3 | 2016-05-20 13:29:46 | [diff] [blame] | 321 | RtcHistogramMap* map = GetMap(); |
| 322 | return map ? map->MinSample(name) : -1; |
| 323 | } |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 | [diff] [blame] | 324 | |
Ali Tofigh | 969c1356 | 2022-05-13 08:26:58 | [diff] [blame] | 325 | std::map<int, int> Samples(absl::string_view name) { |
Steve Anton | c1e6e86 | 2019-03-04 22:43:44 | [diff] [blame] | 326 | RtcHistogramMap* map = GetMap(); |
| 327 | return map ? map->Samples(name) : std::map<int, int>(); |
| 328 | } |
| 329 | |
asapersson@webrtc.org | 580d367 | 2014-10-23 12:57:56 | [diff] [blame] | 330 | } // namespace metrics |
| 331 | } // namespace webrtc |