expand_uma_logger.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (c) 2018 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. #ifndef MODULES_AUDIO_CODING_NETEQ_EXPAND_UMA_LOGGER_H_
  10. #define MODULES_AUDIO_CODING_NETEQ_EXPAND_UMA_LOGGER_H_
  11. #include <stdint.h>
  12. #include <memory>
  13. #include <string>
  14. #include "absl/types/optional.h"
  15. #include "api/neteq/tick_timer.h"
  16. #include "rtc_base/constructor_magic.h"
  17. namespace webrtc {
  18. // This class is used to periodically log values to a UMA histogram. The caller
  19. // is expected to update this class with an incremental sample counter which
  20. // counts expand samples. At the end of each logging period, the class will
  21. // calculate the fraction of samples that were expand samples during that period
  22. // and report that in percent. The logging period must be strictly positive.
  23. // Does not take ownership of tick_timer and the pointer must refer to a valid
  24. // object that outlives the one constructed.
  25. class ExpandUmaLogger {
  26. public:
  27. ExpandUmaLogger(std::string uma_name,
  28. int logging_period_s,
  29. const TickTimer* tick_timer);
  30. ~ExpandUmaLogger();
  31. // In this call, value should be an incremental sample counter. The sample
  32. // rate must be strictly positive.
  33. void UpdateSampleCounter(uint64_t value, int sample_rate_hz);
  34. private:
  35. const std::string uma_name_;
  36. const int logging_period_s_;
  37. const TickTimer& tick_timer_;
  38. std::unique_ptr<TickTimer::Countdown> timer_;
  39. absl::optional<uint64_t> last_logged_value_;
  40. uint64_t last_value_ = 0;
  41. int sample_rate_hz_ = 0;
  42. RTC_DISALLOW_COPY_AND_ASSIGN(ExpandUmaLogger);
  43. };
  44. } // namespace webrtc
  45. #endif // MODULES_AUDIO_CODING_NETEQ_EXPAND_UMA_LOGGER_H_