metrics.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/metrics/histogram.h"
  5. #include "base/metrics/sparse_histogram.h"
  6. #include "third_party/abseil-cpp/absl/strings/string_view.h"
  7. namespace webrtc {
  8. // Define webrtc::metrics functions to provide webrtc with implementations.
  9. namespace metrics {
  10. // This class doesn't actually exist, so don't go looking for it :)
  11. // This type is just fwd declared here in order to use it as an opaque type
  12. // between the Histogram functions in this file.
  13. class Histogram;
  14. Histogram* HistogramFactoryGetCounts(absl::string_view name,
  15. int min,
  16. int max,
  17. int bucket_count) {
  18. return reinterpret_cast<Histogram*>(base::Histogram::FactoryGet(
  19. std::string(name), min, max, bucket_count,
  20. base::HistogramBase::kUmaTargetedHistogramFlag));
  21. }
  22. Histogram* HistogramFactoryGetCountsLinear(absl::string_view name,
  23. int min,
  24. int max,
  25. int bucket_count) {
  26. return reinterpret_cast<Histogram*>(base::LinearHistogram::FactoryGet(
  27. std::string(name), min, max, bucket_count,
  28. base::HistogramBase::kUmaTargetedHistogramFlag));
  29. }
  30. Histogram* HistogramFactoryGetEnumeration(absl::string_view name,
  31. int boundary) {
  32. return reinterpret_cast<Histogram*>(base::LinearHistogram::FactoryGet(
  33. std::string(name), 1, boundary, boundary + 1,
  34. base::HistogramBase::kUmaTargetedHistogramFlag));
  35. }
  36. Histogram* SparseHistogramFactoryGetEnumeration(absl::string_view name,
  37. int boundary) {
  38. return reinterpret_cast<Histogram*>(base::SparseHistogram::FactoryGet(
  39. std::string(name), base::HistogramBase::kUmaTargetedHistogramFlag));
  40. }
  41. const char* GetHistogramName(Histogram* histogram_pointer) {
  42. base::HistogramBase* ptr =
  43. reinterpret_cast<base::HistogramBase*>(histogram_pointer);
  44. return ptr->histogram_name();
  45. }
  46. void HistogramAdd(Histogram* histogram_pointer, int sample) {
  47. base::HistogramBase* ptr =
  48. reinterpret_cast<base::HistogramBase*>(histogram_pointer);
  49. ptr->Add(sample);
  50. }
  51. } // namespace metrics
  52. } // namespace webrtc