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