| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_BASE_RUNNING_SAMPLES_H_ | |
| 6 #define REMOTING_BASE_RUNNING_SAMPLES_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <deque> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 | |
| 16 namespace remoting { | |
| 17 | |
| 18 // Calculates the maximum or average of the most recent N recorded samples. | |
| 19 // This is typically used to smooth out random variation in point samples | |
| 20 // over bandwidth, frame rate, etc. | |
| 21 class RunningSamples { | |
| 22 public: | |
| 23 // Constructs a running sample helper that stores |window_size| most | |
| 24 // recent samples. | |
| 25 explicit RunningSamples(int window_size); | |
| 26 virtual ~RunningSamples(); | |
| 27 | |
| 28 // Records a point sample. | |
| 29 void Record(int64_t value); | |
| 30 | |
| 31 // Returns the average over up to |window_size| of the most recent samples. | |
| 32 // 0 if no sample available | |
| 33 double Average() const; | |
| 34 | |
| 35 // Returns the max over up to |window_size| of the most recent samples. | |
| 36 // 0 if no sample available | |
| 37 int64_t Max() const; | |
| 38 | |
| 39 private: | |
| 40 // Stores the desired window size, as size_t to avoid casting when comparing | |
| 41 // with the size of |data_points_|. | |
| 42 const size_t window_size_; | |
| 43 | |
| 44 // Stores the |window_size| most recently recorded samples. | |
| 45 std::deque<int64_t> data_points_; | |
| 46 | |
| 47 // Holds the sum of the samples in |data_points_|. | |
| 48 int64_t sum_ = 0; | |
| 49 | |
| 50 base::ThreadChecker thread_checker_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(RunningSamples); | |
| 53 }; | |
| 54 | |
| 55 } // namespace remoting | |
| 56 | |
| 57 #endif // REMOTING_BASE_RUNNING_SAMPLES_H_ | |
| OLD | NEW |