Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: webrtc/modules/audio_coding/neteq/statistics_calculator.cc

Issue 1289753008: DRAFT: Make new base class PeriodicUmaLogger (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@neteq-metrics3
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_coding/neteq/statistics_calculator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h" 11 #include "webrtc/modules/audio_coding/neteq/statistics_calculator.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <string.h> // memset 14 #include <string.h> // memset
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" 17 #include "webrtc/modules/audio_coding/neteq/decision_logic.h"
18 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" 18 #include "webrtc/modules/audio_coding/neteq/delay_manager.h"
19 #include "webrtc/system_wrappers/interface/metrics.h" 19 #include "webrtc/system_wrappers/interface/metrics.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 StatisticsCalculator::PeriodicUmaLogger::PeriodicUmaLogger(
24 const std::string& uma_name,
25 int report_interval_ms,
26 int max_value)
27 : uma_name_(uma_name),
28 report_interval_ms_(report_interval_ms),
29 max_value_(max_value),
30 timer_(0) {
31 }
32
33 StatisticsCalculator::PeriodicUmaLogger::~PeriodicUmaLogger() = default;
34
35 void StatisticsCalculator::PeriodicUmaLogger::AdvanceClock(int step_ms) {
36 timer_ += step_ms;
37 if (timer_ < report_interval_ms_) {
38 return;
39 }
40 LogToUma(Metric());
41 Reset();
42 timer_ -= report_interval_ms_;
43 DCHECK_GE(timer_, 0);
44 }
45
46 void StatisticsCalculator::PeriodicUmaLogger::LogToUma(int value) const {
47 RTC_HISTOGRAM_COUNTS(uma_name_, value, 1, max_value_, 50);
48 }
49
50 StatisticsCalculator::DelayedPacketOutagesPerMinuteCounter::
51 DelayedPacketOutagesPerMinuteCounter()
52 : PeriodicUmaLogger("WebRTC.Audio.DelayedPacketOutageEventsPerMinute",
53 60000, // 60 seconds report interval.
54 100) {
55 }
56
23 void StatisticsCalculator::DelayedPacketOutagesPerMinuteCounter:: 57 void StatisticsCalculator::DelayedPacketOutagesPerMinuteCounter::
24 RegisterEvent() { 58 RegisterEvent() {
25 ++counter_; 59 ++counter_;
26 } 60 }
27 61
28 void StatisticsCalculator::DelayedPacketOutagesPerMinuteCounter::AdvanceClock( 62 int StatisticsCalculator::DelayedPacketOutagesPerMinuteCounter::Metric() const {
29 int step_ms) { 63 return counter_;
30 timer_ += step_ms;
31 if (timer_ < kReportIntervalMs) {
32 return;
33 }
34 LogToUma();
35 counter_ = 0;
36 timer_ -= kReportIntervalMs;
37 DCHECK_GE(timer_, 0);
38 } 64 }
39 65
40 void StatisticsCalculator::DelayedPacketOutagesPerMinuteCounter::LogToUma() 66 void StatisticsCalculator::DelayedPacketOutagesPerMinuteCounter::Reset() {
41 const { 67 counter_ = 0;
42 RTC_HISTOGRAM_COUNTS_100("WebRTC.Audio.DelayedPacketOutageEventsPerMinute", 68 }
43 counter_); 69
70 StatisticsCalculator::AverageExcessBufferDelayMs::AverageExcessBufferDelayMs()
71 : PeriodicUmaLogger("WebRTC.Audio.AverageExcessBufferDelayMs",
72 60000, // 60 seconds report interval.
73 1000) {
44 } 74 }
45 75
46 void StatisticsCalculator::AverageExcessBufferDelayMs:: 76 void StatisticsCalculator::AverageExcessBufferDelayMs::
47 RegisterPacketWaitingTime(int time_ms) { 77 RegisterPacketWaitingTime(int time_ms) {
48 sum_ += time_ms; 78 sum_ += time_ms;
49 ++num_packets_; 79 ++num_packets_;
50 } 80 }
51 81
52 void StatisticsCalculator::AverageExcessBufferDelayMs::AdvanceClock( 82 int StatisticsCalculator::AverageExcessBufferDelayMs::Metric() const {
53 int step_ms) { 83 return static_cast<int>(sum_ / num_packets_);
54 timer_ += step_ms; 84 }
55 if (timer_ < kReportIntervalMs) { 85
56 return; 86 void StatisticsCalculator::AverageExcessBufferDelayMs::Reset() {
57 }
58 LogToUma();
59 sum_ = 0.0; 87 sum_ = 0.0;
60 num_packets_ = 0; 88 num_packets_ = 0;
61 timer_ -= kReportIntervalMs;
62 DCHECK_GE(timer_, 0);
63 }
64
65 void StatisticsCalculator::AverageExcessBufferDelayMs::LogToUma() {
66 if (num_packets_ > 0) {
67 RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.AverageExcessBufferDelayMs",
68 static_cast<int>(sum_ / num_packets_));
69 }
70 } 89 }
71 90
72 StatisticsCalculator::StatisticsCalculator() 91 StatisticsCalculator::StatisticsCalculator()
73 : preemptive_samples_(0), 92 : preemptive_samples_(0),
74 accelerate_samples_(0), 93 accelerate_samples_(0),
75 added_zero_samples_(0), 94 added_zero_samples_(0),
76 expanded_speech_samples_(0), 95 expanded_speech_samples_(0),
77 expanded_noise_samples_(0), 96 expanded_noise_samples_(0),
78 discarded_packets_(0), 97 discarded_packets_(0),
79 lost_timestamps_(0), 98 lost_timestamps_(0),
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // Ratio must be smaller than 1 in Q14. 257 // Ratio must be smaller than 1 in Q14.
239 assert((numerator << 14) / denominator < (1 << 14)); 258 assert((numerator << 14) / denominator < (1 << 14));
240 return static_cast<uint16_t>((numerator << 14) / denominator); 259 return static_cast<uint16_t>((numerator << 14) / denominator);
241 } else { 260 } else {
242 // Will not produce a ratio larger than 1, since this is probably an error. 261 // Will not produce a ratio larger than 1, since this is probably an error.
243 return 1 << 14; 262 return 1 << 14;
244 } 263 }
245 } 264 }
246 265
247 } // namespace webrtc 266 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/statistics_calculator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698