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

Side by Side Diff: remoting/base/running_samples.h

Issue 1811833002: Show max latency on client's status bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: JS compiler fix and lld fix Created 4 years, 9 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
« no previous file with comments | « remoting/base/running_average_unittest.cc ('k') | remoting/base/running_samples.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_SAMPLES_H_
6 #define REMOTING_BASE_RUNNING_AVERAGE_H_ 6 #define REMOTING_BASE_RUNNING_SAMPLES_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 or average 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 RunningSamples {
22 public: 22 public:
23 // Constructs a helper to average over the |window_size| most recent samples. 23 // Constructs a running sample helper that stores |window_size| most
24 explicit RunningAverage(int window_size); 24 // recent samples.
25 virtual ~RunningAverage(); 25 explicit RunningSamples(int window_size);
26 virtual ~RunningSamples();
26 27
27 // Records a point sample. 28 // Records a point sample.
28 void Record(int64_t value); 29 void Record(int64_t value);
29 30
30 // Returns the average over up to |window_size| of the most recent samples. 31 // Returns the average over up to |window_size| of the most recent samples.
31 double Average(); 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;
32 38
33 private: 39 private:
34 // Stores the desired window size, as size_t to avoid casting when comparing 40 // Stores the desired window size, as size_t to avoid casting when comparing
35 // with the size of |data_points_|. 41 // with the size of |data_points_|.
36 const size_t window_size_; 42 const size_t window_size_;
37 43
38 // Stores the |window_size| most recently recorded samples. 44 // Stores the |window_size| most recently recorded samples.
39 std::deque<int64_t> data_points_; 45 std::deque<int64_t> data_points_;
40 46
41 // Holds the sum of the samples in |data_points_|. 47 // Holds the sum of the samples in |data_points_|.
42 int64_t sum_; 48 int64_t sum_ = 0;
43 49
44 base::ThreadChecker thread_checker_; 50 base::ThreadChecker thread_checker_;
45 51
46 DISALLOW_COPY_AND_ASSIGN(RunningAverage); 52 DISALLOW_COPY_AND_ASSIGN(RunningSamples);
47 }; 53 };
48 54
49 } // namespace remoting 55 } // namespace remoting
50 56
51 #endif // REMOTING_BASE_RUNNING_AVERAGE_H_ 57 #endif // REMOTING_BASE_RUNNING_SAMPLES_H_
OLDNEW
« no previous file with comments | « remoting/base/running_average_unittest.cc ('k') | remoting/base/running_samples.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698