OLD | NEW |
1 // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 1 // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
2 // | 2 // |
3 // Use of this source code is governed by a BSD-style license | 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 | 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 | 5 // tree. An additional intellectual property rights grant can be found |
6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
8 // | 8 // |
9 | 9 |
10 #include "webrtc/system_wrappers/include/metrics_default.h" | 10 #include "webrtc/system_wrappers/include/metrics_default.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return map->GetEnumerationHistogram(name, boundary); | 246 return map->GetEnumerationHistogram(name, boundary); |
247 } | 247 } |
248 | 248 |
249 const std::string& GetHistogramName(Histogram* histogram_pointer) { | 249 const std::string& GetHistogramName(Histogram* histogram_pointer) { |
250 RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer); | 250 RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer); |
251 return ptr->name(); | 251 return ptr->name(); |
252 } | 252 } |
253 | 253 |
254 // Fast path. Adds |sample| to cached |histogram_pointer|. | 254 // Fast path. Adds |sample| to cached |histogram_pointer|. |
255 void HistogramAdd(Histogram* histogram_pointer, int sample) { | 255 void HistogramAdd(Histogram* histogram_pointer, int sample) { |
| 256 if (g_rtc_histogram_map == nullptr) { |
| 257 // Histograms are disabled, so the pointer is invalid. Check on this instead |
| 258 // of histogram_pointer being NULL so that we don't accidentally miss |
| 259 // instances where HistogramAdd(histogram_, sample) is called with |
| 260 // histogram_ uninitialized. |
| 261 // |
| 262 // This doesn't happen in Chromium since base::Histogram::FactoryGet and |
| 263 // base::LinearHistogram::FactoryGet always return valid base::HistogramBase |
| 264 // pointers. We could consider returning a null object, but having |
| 265 // RtcHistogram virtual makes function calls to it slower. |
| 266 return; |
| 267 } |
256 RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer); | 268 RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer); |
257 ptr->Add(sample); | 269 ptr->Add(sample); |
258 } | 270 } |
259 | 271 |
260 SampleInfo::SampleInfo(const std::string& name, | 272 SampleInfo::SampleInfo(const std::string& name, |
261 int min, | 273 int min, |
262 int max, | 274 int max, |
263 size_t bucket_count) | 275 size_t bucket_count) |
264 : name(name), min(min), max(max), bucket_count(bucket_count) {} | 276 : name(name), min(min), max(max), bucket_count(bucket_count) {} |
265 | 277 |
266 SampleInfo::~SampleInfo() {} | 278 SampleInfo::~SampleInfo() {} |
267 | 279 |
268 // Implementation of global functions in metrics_default.h. | 280 // Implementation of global functions in metrics_default.h. |
269 void Enable() { | 281 void Enable() { |
| 282 // TODO(pbos): Make sure that no callers have called HistogramFactoryGet*, |
| 283 // HistogramAdd or GetMap() at this point. |
270 RTC_DCHECK(g_rtc_histogram_map == nullptr); | 284 RTC_DCHECK(g_rtc_histogram_map == nullptr); |
271 #if RTC_DCHECK_IS_ON | 285 #if RTC_DCHECK_IS_ON |
272 RTC_DCHECK_EQ(0, rtc::AtomicOps::AcquireLoad(&g_rtc_histogram_called)); | 286 RTC_DCHECK_EQ(0, rtc::AtomicOps::AcquireLoad(&g_rtc_histogram_called)); |
273 #endif | 287 #endif |
274 CreateMap(); | 288 CreateMap(); |
275 } | 289 } |
276 | 290 |
277 void GetAndReset( | 291 void GetAndReset( |
278 std::map<std::string, std::unique_ptr<SampleInfo>>* histograms) { | 292 std::map<std::string, std::unique_ptr<SampleInfo>>* histograms) { |
279 histograms->clear(); | 293 histograms->clear(); |
(...skipping 18 matching lines...) Expand all Loading... |
298 return map ? map->NumSamples(name) : 0; | 312 return map ? map->NumSamples(name) : 0; |
299 } | 313 } |
300 | 314 |
301 int MinSample(const std::string& name) { | 315 int MinSample(const std::string& name) { |
302 RtcHistogramMap* map = GetMap(); | 316 RtcHistogramMap* map = GetMap(); |
303 return map ? map->MinSample(name) : -1; | 317 return map ? map->MinSample(name) : -1; |
304 } | 318 } |
305 | 319 |
306 } // namespace metrics | 320 } // namespace metrics |
307 } // namespace webrtc | 321 } // namespace webrtc |
OLD | NEW |