OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CHROME_BROWSER_ANDROID_VR_SHELL_FPS_METER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_FPS_METER_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_FPS_METER_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_FPS_METER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 | 12 |
13 namespace vr_shell { | 13 namespace vr_shell { |
14 | 14 |
15 class SampleQueue { | |
16 public: | |
17 explicit SampleQueue(size_t window_size); | |
18 ~SampleQueue(); | |
19 | |
20 int64_t GetSum() const { return sum_; } | |
21 | |
22 void AddSample(int64_t value); | |
23 | |
24 size_t GetCount() const { return samples_.size(); } | |
25 | |
26 // Get sliding window size for tests. | |
27 size_t GetWindowSize() const { return window_size_; } | |
28 | |
29 private: | |
30 int64_t sum_ = 0; | |
31 size_t current_index_ = 0; | |
32 size_t window_size_; | |
33 std::vector<int64_t> samples_; | |
34 }; | |
35 | |
15 // Computes fps based on submitted frame times. | 36 // Computes fps based on submitted frame times. |
16 class FPSMeter { | 37 class FPSMeter { |
17 public: | 38 public: |
18 FPSMeter(); | 39 FPSMeter(); |
40 explicit FPSMeter(size_t window_size); | |
cjgrant
2017/05/24 13:37:30
Just a sanity check - are there no existing tools
klausw
2017/05/24 16:32:23
Can you check with vollick@? He implemented this F
| |
19 ~FPSMeter(); | 41 ~FPSMeter(); |
20 | 42 |
21 void AddFrame(const base::TimeTicks& time_stamp); | 43 void AddFrame(const base::TimeTicks& time_stamp); |
22 | 44 |
23 bool CanComputeFPS() const; | 45 bool CanComputeFPS() const; |
24 | 46 |
25 double GetFPS() const; | 47 double GetFPS() const; |
26 | 48 |
27 // Get sliding window size for tests. | 49 // Get sliding window size for tests. |
28 size_t GetNumFrameTimes(); | 50 size_t GetNumFrameTimes(); |
29 | 51 |
30 private: | 52 private: |
31 size_t current_index_; | 53 SampleQueue frame_times_; |
32 int64_t total_time_us_; | |
33 base::TimeTicks last_time_stamp_; | 54 base::TimeTicks last_time_stamp_; |
34 std::vector<base::TimeDelta> frame_times_; | |
35 DISALLOW_COPY_AND_ASSIGN(FPSMeter); | 55 DISALLOW_COPY_AND_ASSIGN(FPSMeter); |
36 }; | 56 }; |
37 | 57 |
58 class SlidingAverage { | |
59 public: | |
60 explicit SlidingAverage(size_t window_size); | |
61 ~SlidingAverage(); | |
62 | |
63 void AddSample(int64_t value); | |
64 int64_t GetAverageOrDefault(int64_t default_value); | |
65 int64_t GetAverage() { return GetAverageOrDefault(0); } | |
66 | |
67 private: | |
68 SampleQueue values_; | |
69 }; | |
70 | |
38 } // namespace vr_shell | 71 } // namespace vr_shell |
39 | 72 |
40 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_FPS_METER_H_ | 73 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_FPS_METER_H_ |
OLD | NEW |