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

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: Created 4 years, 10 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 <map>
15
16 #include "webrtc/base/scoped_ptr.h"
17
18 namespace webrtc {
19
20 class Clock;
21
22 // StatsCounterObserver is called periodically when a metric is updated.
23 class StatsCounterObserver {
24 public:
25 virtual void OnMetricUpdated(int sample) = 0;
26
27 virtual ~StatsCounterObserver() {}
28 };
29
30 class StatsCounter {
31 public:
32 virtual ~StatsCounter() {}
33
34 virtual bool GetMetric(int* metric) const = 0;
35
36 // Class holding periodically computed metrics.
37 class Histogram {
38 public:
39 Histogram(size_t bucket_count, size_t bucket_max);
40 ~Histogram() {}
41
42 void Add(int sample);
43
44 struct Stats {
45 Stats();
46 int64_t num_samples;
47 int min;
48 int max;
49 int average;
50 int percentile10;
51 int percentile50;
52 int percentile90;
53 };
54
55 // Computes and returns |stats_|.
56 Stats stats();
stefan-webrtc 2016/01/29 15:22:46 ComputeStats() or ComputeAndGetStats()? Should pro
57
58 private:
59 void InitializeBuckets();
60 void AddToBucket(size_t sample);
61 void Compute();
62
63 // Number of samples per bucket mapped by start of bucket.
64 std::map<size_t, size_t> buckets_;
65 const size_t bucket_count_;
66 const size_t bucket_max_;
67 const bool bucket_size1_;
stefan-webrtc 2016/01/29 15:22:46 bucket_size_?
68 int64_t sum_;
69 Stats stats_;
70 };
71
72 // Returns stats from |histogram_|.
73 Histogram::Stats GetStats();
74
75 protected:
76 StatsCounter(Clock* clock,
77 size_t bucket_count,
78 size_t bucket_max,
79 bool include_empty_intervals,
80 StatsCounterObserver* observer);
81
82 // Adds/sets sample. Periodically calls GetMetric and adds it to |histogram_|.
83 void Add(int sample);
84 void Set(int sample);
85
86 int64_t sum_;
87 int64_t num_samples_;
88 int64_t last_sum_;
89
90 private:
91 bool TimeToProcess();
92 void Process();
93
94 Clock* const clock_;
95 const bool include_empty_intervals_;
96 const rtc::scoped_ptr<StatsCounterObserver> observer_;
97 int64_t last_process_time_ms_;
98 Histogram histogram_;
99 };
stefan-webrtc 2016/01/29 15:22:46 You probably want to disable the copy constructor
100
101 // Classes which periodically computes a metric (based on added samples in
102 // the interval) and adds it to a histogram.
103 //
104 // |bucket_count| == |bucket_max|: => linear histogram (bucket size:1)
105 // |bucket_count| < |bucket_max|: => exponential histogram
106 //
107 // Note: takes ownership of |observer|.
108
109 class AvgCounter : public StatsCounter {
110 public:
111 AvgCounter(Clock* clock,
112 size_t bucket_count,
113 size_t bucket_max,
114 StatsCounterObserver* observer);
115 ~AvgCounter() override {}
116
117 void Add(int sample);
118
119 private:
120 bool GetMetric(int* metric) const override;
121 };
122
123 class PercentCounter : public StatsCounter {
124 public:
125 PercentCounter(Clock* clock, StatsCounterObserver* observer);
126 ~PercentCounter() override {}
127
128 void Add(bool sample);
129
130 private:
131 bool GetMetric(int* metric) const override;
132 };
133
134 class PermilleCounter : public StatsCounter {
135 public:
136 PermilleCounter(Clock* clock,
137 size_t bucket_count,
138 StatsCounterObserver* observer);
139 ~PermilleCounter() override {}
140
141 void Add(bool sample);
142
143 private:
144 bool GetMetric(int* metric) const override;
145 };
146
147 class RateCounter : public StatsCounter {
148 public:
149 RateCounter(Clock* clock,
150 size_t bucket_count,
151 size_t bucket_max,
152 bool include_empty_intervals,
153 StatsCounterObserver* observer);
154 ~RateCounter() override {}
155
156 void Add(int sample);
157
158 private:
159 bool GetMetric(int* metric) const override;
160 };
161
162 class RateAccCounter : public StatsCounter {
163 public:
164 RateAccCounter(Clock* clock,
165 size_t bucket_count,
166 size_t bucket_max,
167 bool include_empty_intervals,
168 StatsCounterObserver* observer);
169 ~RateAccCounter() override {}
170
171 void Set(int sample);
172
173 private:
174 bool GetMetric(int* metric) const override;
175 };
176
177 } // namespace webrtc
178
179 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698