blob: cc5c20a886ac3d2b556516bc80e4bb9024d1c3d5 [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
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Henrik Lundin3ef3bfc2018-04-10 15:10:26 +020015#include <memory>
16#include <string>
17
Ali Tofigh714e3cb2022-07-20 12:53:07 +020018#include "absl/strings/string_view.h"
Danil Chapovalovb6021232018-06-19 13:26:36 +020019#include "absl/types/optional.h"
Ivo Creusen3ce44a32019-10-31 14:38:11 +010020#include "api/neteq/tick_timer.h"
Henrik Lundin3ef3bfc2018-04-10 15:10:26 +020021
22namespace webrtc {
23
24// This class is used to periodically log values to a UMA histogram. The caller
25// is expected to update this class with an incremental sample counter which
26// counts expand samples. At the end of each logging period, the class will
27// calculate the fraction of samples that were expand samples during that period
28// and report that in percent. The logging period must be strictly positive.
29// Does not take ownership of tick_timer and the pointer must refer to a valid
30// object that outlives the one constructed.
31class ExpandUmaLogger {
32 public:
Ali Tofigh714e3cb2022-07-20 12:53:07 +020033 ExpandUmaLogger(absl::string_view uma_name,
Henrik Lundin3ef3bfc2018-04-10 15:10:26 +020034 int logging_period_s,
35 const TickTimer* tick_timer);
36
37 ~ExpandUmaLogger();
38
Byoungchan Lee604fd2f2022-01-21 09:49:39 +090039 ExpandUmaLogger(const ExpandUmaLogger&) = delete;
40 ExpandUmaLogger& operator=(const ExpandUmaLogger&) = delete;
41
Henrik Lundin3ef3bfc2018-04-10 15:10:26 +020042 // In this call, value should be an incremental sample counter. The sample
43 // rate must be strictly positive.
44 void UpdateSampleCounter(uint64_t value, int sample_rate_hz);
45
46 private:
47 const std::string uma_name_;
48 const int logging_period_s_;
49 const TickTimer& tick_timer_;
50 std::unique_ptr<TickTimer::Countdown> timer_;
Danil Chapovalovb6021232018-06-19 13:26:36 +020051 absl::optional<uint64_t> last_logged_value_;
Henrik Lundin3ef3bfc2018-04-10 15:10:26 +020052 uint64_t last_value_ = 0;
53 int sample_rate_hz_ = 0;
Henrik Lundin3ef3bfc2018-04-10 15:10:26 +020054};
55
56} // namespace webrtc
57#endif // MODULES_AUDIO_CODING_NETEQ_EXPAND_UMA_LOGGER_H_