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

Side by Side Diff: webrtc/video/stats_counter.h

Issue 1640053003: Add class which periodically computes statistics. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 7 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_VIDEO_STATS_COUNTER_H_
12 #define WEBRTC_VIDEO_STATS_COUNTER_H_
13
14 #include <memory>
15
16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/typedefs.h"
18
19 namespace webrtc {
20
21 class Clock;
22
23 // |StatsCounterObserver| is called periodically when a metric is updated.
24 class StatsCounterObserver {
25 public:
26 virtual void OnMetricUpdated(int sample) = 0;
27
28 virtual ~StatsCounterObserver() {}
29 };
30
31 class StatsCounter {
32 public:
33 virtual ~StatsCounter() {}
34
35 virtual bool GetMetric(int* metric) const = 0;
36
37 // Class holding periodically computed metrics.
38 class AggStats {
mflodman 2016/05/06 07:33:29 What does 'Agg' stand for? Can you write the whole
åsapersson 2016/05/09 14:36:50 Have moved the nested classes and renamed classes.
39 public:
40 AggStats();
41 ~AggStats() {}
42
43 struct Stats {
44 Stats();
45 int64_t num_samples;
mflodman 2016/05/06 07:33:29 You can set default values here instead of using a
åsapersson 2016/05/09 14:36:50 Done.
46 int min;
47 int max;
48 int average;
49 // TODO(asapersson): Consider adding median/percentiles.
50 };
51
52 void Add(int sample);
53 // Computes and returns |stats_|.
stefan-webrtc 2016/05/06 11:10:17 Empty line above.
åsapersson 2016/05/09 14:36:50 Done.
54 Stats ComputeStats();
55
56 private:
57 void Compute();
58 int64_t sum_;
59 Stats stats_;
60 };
61
62 // Returns stats from |agg_stats_|.
63 AggStats::Stats GetStats();
64
65 protected:
66 StatsCounter(Clock* clock,
67 bool include_empty_intervals,
68 StatsCounterObserver* observer);
69
70 void Add(int sample);
mflodman 2016/05/06 07:33:29 It would be good to add a comment for these two me
åsapersson 2016/05/09 14:36:50 Added more comments and examples.
71 void Set(int sample);
72
73 int64_t sum_;
74 int64_t num_samples_;
75 int64_t last_sum_;
76
77 private:
78 bool TimeToProcess();
79 void Process();
80
81 Clock* const clock_;
82 const bool include_empty_intervals_;
83 const std::unique_ptr<StatsCounterObserver> observer_;
84 int64_t last_process_time_ms_;
85 AggStats agg_stats_;
86 };
87
88 // Classes which periodically computes a metric.
89 //
90 // During a period, |kProcessIntervalMs|, different metrics can be computed:
91 // - |AvgCounter|: average of samples
92 // - |PercentCounter|: percentage of samples
93 // - |PermilleCounter|: permille of samples
94 // - |RateCounter|: units per second (sums added |sample|)
95 // - |AccRateCounter|: units per second (uses differences of set |sample|, to be
96 // used for counters)
97 //
98 // Each periodic metric can be either:
99 // - reported to an |observer| each period
100 // - aggregated during the call (e.g. min, max, average)
101 //
102 // Note: takes ownership of |observer|.
103
104 class AvgCounter : public StatsCounter {
105 public:
106 AvgCounter(Clock* clock, StatsCounterObserver* observer);
107 ~AvgCounter() override {}
108
109 void Add(int sample);
110
111 private:
112 bool GetMetric(int* metric) const override;
113
114 RTC_DISALLOW_COPY_AND_ASSIGN(AvgCounter);
115 };
116
117 class PercentCounter : public StatsCounter {
118 public:
119 PercentCounter(Clock* clock, StatsCounterObserver* observer);
120 ~PercentCounter() override {}
121
122 void Add(bool sample);
123
124 private:
125 bool GetMetric(int* metric) const override;
126
127 RTC_DISALLOW_COPY_AND_ASSIGN(PercentCounter);
128 };
129
130 class PermilleCounter : public StatsCounter {
131 public:
132 PermilleCounter(Clock* clock, StatsCounterObserver* observer);
133 ~PermilleCounter() override {}
134
135 void Add(bool sample);
136
137 private:
138 bool GetMetric(int* metric) const override;
139
140 RTC_DISALLOW_COPY_AND_ASSIGN(PermilleCounter);
141 };
142
143 class RateCounter : public StatsCounter {
144 public:
145 RateCounter(Clock* clock, StatsCounterObserver* observer);
146 ~RateCounter() override {}
147
148 void Add(int sample);
149
150 private:
151 bool GetMetric(int* metric) const override;
152
153 RTC_DISALLOW_COPY_AND_ASSIGN(RateCounter);
154 };
155
156 class RateAccCounter : public StatsCounter {
mflodman 2016/05/06 07:33:29 It would be good with a class description for thes
åsapersson 2016/05/09 14:36:50 Done.
157 public:
158 RateAccCounter(Clock* clock, StatsCounterObserver* observer);
159 ~RateAccCounter() override {}
160
161 void Set(int sample);
162
163 private:
164 bool GetMetric(int* metric) const override;
165
166 RTC_DISALLOW_COPY_AND_ASSIGN(RateAccCounter);
167 };
168
169 } // namespace webrtc
170
171 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698