| 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 |
| 11 #ifndef WEBRTC_VIDEO_STATS_COUNTER_H_ | 11 #ifndef WEBRTC_VIDEO_STATS_COUNTER_H_ |
| 12 #define WEBRTC_VIDEO_STATS_COUNTER_H_ | 12 #define WEBRTC_VIDEO_STATS_COUNTER_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
| 17 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 class AggregatedCounter; | 21 class AggregatedCounter; |
| 22 class Clock; | 22 class Clock; |
| 23 class Samples; |
| 23 | 24 |
| 24 // |StatsCounterObserver| is called periodically when a metric is updated. | 25 // |StatsCounterObserver| is called periodically when a metric is updated. |
| 25 class StatsCounterObserver { | 26 class StatsCounterObserver { |
| 26 public: | 27 public: |
| 27 virtual void OnMetricUpdated(int sample) = 0; | 28 virtual void OnMetricUpdated(int sample) = 0; |
| 28 | 29 |
| 29 virtual ~StatsCounterObserver() {} | 30 virtual ~StatsCounterObserver() {} |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 struct AggregatedStats { | 33 struct AggregatedStats { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Checks if a sample has been added (i.e. Add or Set called). | 98 // Checks if a sample has been added (i.e. Add or Set called). |
| 98 bool HasSample() const; | 99 bool HasSample() const; |
| 99 | 100 |
| 100 protected: | 101 protected: |
| 101 StatsCounter(Clock* clock, | 102 StatsCounter(Clock* clock, |
| 102 int64_t process_intervals_ms, | 103 int64_t process_intervals_ms, |
| 103 bool include_empty_intervals, | 104 bool include_empty_intervals, |
| 104 StatsCounterObserver* observer); | 105 StatsCounterObserver* observer); |
| 105 | 106 |
| 106 void Add(int sample); | 107 void Add(int sample); |
| 107 void Set(int sample); | 108 void Set(int sample, uint32_t stream_id); |
| 108 | 109 |
| 109 int max_; | 110 const bool include_empty_intervals_; |
| 110 int64_t sum_; | 111 const int64_t process_intervals_ms_; |
| 111 int64_t num_samples_; | |
| 112 int64_t last_sum_; | |
| 113 | |
| 114 const std::unique_ptr<AggregatedCounter> aggregated_counter_; | 112 const std::unique_ptr<AggregatedCounter> aggregated_counter_; |
| 115 const int64_t process_intervals_ms_; | 113 const std::unique_ptr<Samples> samples_; |
| 116 | 114 |
| 117 private: | 115 private: |
| 118 bool TimeToProcess(int* num_elapsed_intervals); | 116 bool TimeToProcess(int* num_elapsed_intervals); |
| 119 void TryProcess(); | 117 void TryProcess(); |
| 120 void ReportMetricToAggregatedCounter(int value, int num_values_to_add) const; | 118 void ReportMetricToAggregatedCounter(int value, int num_values_to_add) const; |
| 121 bool IncludeEmptyIntervals() const; | 119 bool IncludeEmptyIntervals() const; |
| 122 | 120 |
| 123 Clock* const clock_; | 121 Clock* const clock_; |
| 124 const bool include_empty_intervals_; | |
| 125 const std::unique_ptr<StatsCounterObserver> observer_; | 122 const std::unique_ptr<StatsCounterObserver> observer_; |
| 126 int64_t last_process_time_ms_; | 123 int64_t last_process_time_ms_; |
| 127 bool paused_; | 124 bool paused_; |
| 128 }; | 125 }; |
| 129 | 126 |
| 130 // AvgCounter: average of samples | 127 // AvgCounter: average of samples |
| 131 // | 128 // |
| 132 // | * * * | * * | ... | 129 // | * * * | * * | ... |
| 133 // | Add(5) Add(1) Add(6) | Add(5) Add(5) | | 130 // | Add(5) Add(1) Add(6) | Add(5) Add(5) | |
| 134 // GetMetric | (5 + 1 + 6) / 3 | (5 + 5) / 2 | | 131 // GetMetric | (5 + 1 + 6) / 3 | (5 + 5) / 2 | |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // in the stats. The value for an interval is | 252 // in the stats. The value for an interval is |
| 256 // determined by GetValueForEmptyInterval(). | 253 // determined by GetValueForEmptyInterval(). |
| 257 // | 254 // |
| 258 class RateAccCounter : public StatsCounter { | 255 class RateAccCounter : public StatsCounter { |
| 259 public: | 256 public: |
| 260 RateAccCounter(Clock* clock, | 257 RateAccCounter(Clock* clock, |
| 261 StatsCounterObserver* observer, | 258 StatsCounterObserver* observer, |
| 262 bool include_empty_intervals); | 259 bool include_empty_intervals); |
| 263 ~RateAccCounter() override {} | 260 ~RateAccCounter() override {} |
| 264 | 261 |
| 265 void Set(int sample); | 262 void Set(int sample, uint32_t stream_id); |
| 266 | 263 |
| 267 private: | 264 private: |
| 268 bool GetMetric(int* metric) const override; | 265 bool GetMetric(int* metric) const override; |
| 269 int GetValueForEmptyInterval() const override; // Returns zero. | 266 int GetValueForEmptyInterval() const override; // Returns zero. |
| 270 | 267 |
| 271 RTC_DISALLOW_COPY_AND_ASSIGN(RateAccCounter); | 268 RTC_DISALLOW_COPY_AND_ASSIGN(RateAccCounter); |
| 272 }; | 269 }; |
| 273 | 270 |
| 274 } // namespace webrtc | 271 } // namespace webrtc |
| 275 | 272 |
| 276 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_ | 273 #endif // WEBRTC_VIDEO_STATS_COUNTER_H_ |
| OLD | NEW |