Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_BASE_RUNNING_AVERAGE_H_ | 5 #ifndef REMOTING_BASE_RUNNING_MAX_H_ |
| 6 #define REMOTING_BASE_RUNNING_AVERAGE_H_ | 6 #define REMOTING_BASE_RUNNING_MAX_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <deque> | 11 #include <deque> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 | 17 |
| 18 // Calculates the average of the most recent N recorded samples. | 18 // Calculates the maximum of the most recent N recorded samples. |
| 19 // This is typically used to smooth out random variation in point samples | 19 // This is typically used to smooth out random variation in point samples |
| 20 // over bandwidth, frame rate, etc. | 20 // over bandwidth, frame rate, etc. |
| 21 class RunningAverage { | 21 class RunningMax { |
|
Sergey Ulanov
2016/03/17 19:12:37
I don't think we really need both RunningAverage c
Yuwei
2016/03/17 20:24:44
Adding Max() to RunningAverage without renaming th
Sergey Ulanov
2016/03/17 22:00:26
Not sure what's the concern about. The class shoul
Yuwei
2016/03/17 23:02:39
Cool... Will rename it to RunningSample
| |
| 22 public: | 22 public: |
| 23 // Constructs a helper to average over the |window_size| most recent samples. | 23 // Constructs a helper to find max over the |window_size| most recent samples. |
| 24 explicit RunningAverage(int window_size); | 24 explicit RunningMax(int window_size); |
| 25 virtual ~RunningAverage(); | 25 virtual ~RunningMax(); |
| 26 | 26 |
| 27 // Records a point sample. | 27 // Records a point sample. |
| 28 void Record(int64_t value); | 28 void Record(int64_t value); |
| 29 | 29 |
| 30 // Returns the average over up to |window_size| of the most recent samples. | 30 // Returns the max over up to |window_size| of the most recent samples. |
| 31 double Average(); | 31 int64_t Max(); |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 // Stores the desired window size, as size_t to avoid casting when comparing | 34 // Stores the desired window size, as size_t to avoid casting when comparing |
| 35 // with the size of |data_points_|. | 35 // with the size of |data_points_|. |
| 36 const size_t window_size_; | 36 const size_t window_size_; |
| 37 | 37 |
| 38 // Stores the |window_size| most recently recorded samples. | 38 // Stores the |window_size| most recently recorded samples. |
| 39 std::deque<int64_t> data_points_; | 39 std::deque<int64_t> data_points_; |
| 40 | 40 |
| 41 // Holds the sum of the samples in |data_points_|. | |
| 42 int64_t sum_; | |
| 43 | |
| 44 base::ThreadChecker thread_checker_; | 41 base::ThreadChecker thread_checker_; |
| 45 | 42 |
| 46 DISALLOW_COPY_AND_ASSIGN(RunningAverage); | 43 DISALLOW_COPY_AND_ASSIGN(RunningMax); |
| 47 }; | 44 }; |
| 48 | 45 |
| 49 } // namespace remoting | 46 } // namespace remoting |
| 50 | 47 |
| 51 #endif // REMOTING_BASE_RUNNING_AVERAGE_H_ | 48 #endif // REMOTING_BASE_RUNNING_MAX_H_ |
| OLD | NEW |