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