OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Gets aggregated stats (i.e. aggregate of periodically computed metrics). | 92 // Gets aggregated stats (i.e. aggregate of periodically computed metrics). |
93 AggregatedStats GetStats(); | 93 AggregatedStats GetStats(); |
94 | 94 |
95 // Reports metrics for elapsed intervals to AggregatedCounter and GetStats. | 95 // Reports metrics for elapsed intervals to AggregatedCounter and GetStats. |
96 AggregatedStats ProcessAndGetStats(); | 96 AggregatedStats ProcessAndGetStats(); |
97 | 97 |
98 // Reports metrics for elapsed intervals to AggregatedCounter and pauses stats | 98 // Reports metrics for elapsed intervals to AggregatedCounter and pauses stats |
99 // (i.e. empty intervals will be discarded until next sample is added). | 99 // (i.e. empty intervals will be discarded until next sample is added). |
100 void ProcessAndPause(); | 100 void ProcessAndPause(); |
101 | 101 |
| 102 // As above with a minimum pause time. Added samples within this interval will |
| 103 // not resume the stats (i.e. stop the pause). |
| 104 void ProcessAndPauseForDuration(int64_t min_pause_time_ms); |
| 105 |
| 106 // Reports metrics for elapsed intervals to AggregatedCounter and stops pause. |
| 107 void ProcessAndStopPause(); |
| 108 |
102 // Checks if a sample has been added (i.e. Add or Set called). | 109 // Checks if a sample has been added (i.e. Add or Set called). |
103 bool HasSample() const; | 110 bool HasSample() const; |
104 | 111 |
105 protected: | 112 protected: |
106 StatsCounter(Clock* clock, | 113 StatsCounter(Clock* clock, |
107 int64_t process_intervals_ms, | 114 int64_t process_intervals_ms, |
108 bool include_empty_intervals, | 115 bool include_empty_intervals, |
109 StatsCounterObserver* observer); | 116 StatsCounterObserver* observer); |
110 | 117 |
111 void Add(int sample); | 118 void Add(int sample); |
112 void Set(int sample, uint32_t stream_id); | 119 void Set(int64_t sample, uint32_t stream_id); |
| 120 void SetLast(int64_t sample, uint32_t stream_id); |
113 | 121 |
114 const bool include_empty_intervals_; | 122 const bool include_empty_intervals_; |
115 const int64_t process_intervals_ms_; | 123 const int64_t process_intervals_ms_; |
116 const std::unique_ptr<AggregatedCounter> aggregated_counter_; | 124 const std::unique_ptr<AggregatedCounter> aggregated_counter_; |
117 const std::unique_ptr<Samples> samples_; | 125 const std::unique_ptr<Samples> samples_; |
118 | 126 |
119 private: | 127 private: |
120 bool TimeToProcess(int* num_elapsed_intervals); | 128 bool TimeToProcess(int* num_elapsed_intervals); |
121 void TryProcess(); | 129 void TryProcess(); |
122 void ReportMetricToAggregatedCounter(int value, int num_values_to_add) const; | 130 void ReportMetricToAggregatedCounter(int value, int num_values_to_add) const; |
123 bool IncludeEmptyIntervals() const; | 131 bool IncludeEmptyIntervals() const; |
| 132 void Resume(); |
| 133 void ResumeIfMinTimePassed(); |
124 | 134 |
125 Clock* const clock_; | 135 Clock* const clock_; |
126 const std::unique_ptr<StatsCounterObserver> observer_; | 136 const std::unique_ptr<StatsCounterObserver> observer_; |
127 int64_t last_process_time_ms_; | 137 int64_t last_process_time_ms_; |
128 bool paused_; | 138 bool paused_; |
| 139 int64_t pause_time_ms_; |
| 140 int64_t min_pause_time_ms_; |
129 }; | 141 }; |
130 | 142 |
131 // AvgCounter: average of samples | 143 // AvgCounter: average of samples |
132 // | 144 // |
133 // | * * * | * * | ... | 145 // | * * * | * * | ... |
134 // | Add(5) Add(1) Add(6) | Add(5) Add(5) | | 146 // | Add(5) Add(1) Add(6) | Add(5) Add(5) | |
135 // GetMetric | (5 + 1 + 6) / 3 | (5 + 5) / 2 | | 147 // GetMetric | (5 + 1 + 6) / 3 | (5 + 5) / 2 | |
136 // | 148 // |
137 // |include_empty_intervals|: If set, intervals without samples will be included | 149 // |include_empty_intervals|: If set, intervals without samples will be included |
138 // in the stats. The value for an interval is | 150 // in the stats. The value for an interval is |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 int GetValueForEmptyInterval() const override; // Returns zero. | 255 int GetValueForEmptyInterval() const override; // Returns zero. |
244 | 256 |
245 RTC_DISALLOW_COPY_AND_ASSIGN(RateCounter); | 257 RTC_DISALLOW_COPY_AND_ASSIGN(RateCounter); |
246 }; | 258 }; |
247 | 259 |
248 // RateAccCounter: units per second (used for counters) | 260 // RateAccCounter: units per second (used for counters) |
249 // | 261 // |
250 // | * * * | * * | ... | 262 // | * * * | * * | ... |
251 // | Set(5) Set(6) Set(8) | Set(11) Set(13) | | 263 // | Set(5) Set(6) Set(8) | Set(11) Set(13) | |
252 // |<------ 2 sec ------->| | | 264 // |<------ 2 sec ------->| | |
253 // GetMetric | 8 / 2 | (13 - 8) / 2 | | 265 // GetMetric | (8 - 0) / 2 | (13 - 8) / 2 | |
254 // | 266 // |
255 // |include_empty_intervals|: If set, intervals without samples will be included | 267 // |include_empty_intervals|: If set, intervals without samples will be included |
256 // in the stats. The value for an interval is | 268 // in the stats. The value for an interval is |
257 // determined by GetValueForEmptyInterval(). | 269 // determined by GetValueForEmptyInterval(). |
258 // | 270 // |
259 class RateAccCounter : public StatsCounter { | 271 class RateAccCounter : public StatsCounter { |
260 public: | 272 public: |
261 RateAccCounter(Clock* clock, | 273 RateAccCounter(Clock* clock, |
262 StatsCounterObserver* observer, | 274 StatsCounterObserver* observer, |
263 bool include_empty_intervals); | 275 bool include_empty_intervals); |
264 ~RateAccCounter() override {} | 276 ~RateAccCounter() override {} |
265 | 277 |
266 void Set(int sample, uint32_t stream_id); | 278 void Set(int64_t sample, uint32_t stream_id); |
| 279 |
| 280 // Sets the value for previous interval. |
| 281 // To be used if a value other than zero is initially required. |
| 282 void SetLast(int64_t sample, uint32_t stream_id); |
267 | 283 |
268 private: | 284 private: |
269 bool GetMetric(int* metric) const override; | 285 bool GetMetric(int* metric) const override; |
270 int GetValueForEmptyInterval() const override; // Returns zero. | 286 int GetValueForEmptyInterval() const override; // Returns zero. |
271 | 287 |
272 RTC_DISALLOW_COPY_AND_ASSIGN(RateAccCounter); | 288 RTC_DISALLOW_COPY_AND_ASSIGN(RateAccCounter); |
273 }; | 289 }; |
274 | 290 |
275 } // namespace webrtc | 291 } // namespace webrtc |
276 | 292 |
277 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_ | 293 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_ |
OLD | NEW |