OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #include "media/capture/content/smooth_event_sampler.h" | 5 #include "media/capture/content/smooth_event_sampler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 // called often enough (a bug). On the other hand, if RecordSample() is being | 34 // called often enough (a bug). On the other hand, if RecordSample() is being |
35 // called too often (e.g., as a reaction to IsOverdueForSamplingAt()), the | 35 // called too often (e.g., as a reaction to IsOverdueForSamplingAt()), the |
36 // bucket will underflow. | 36 // bucket will underflow. |
37 if (!current_event_.is_null()) { | 37 if (!current_event_.is_null()) { |
38 if (current_event_ < event_time) { | 38 if (current_event_ < event_time) { |
39 token_bucket_ += event_time - current_event_; | 39 token_bucket_ += event_time - current_event_; |
40 if (token_bucket_ > token_bucket_capacity_) | 40 if (token_bucket_ > token_bucket_capacity_) |
41 token_bucket_ = token_bucket_capacity_; | 41 token_bucket_ = token_bucket_capacity_; |
42 } | 42 } |
43 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", | 43 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", |
44 std::max<int64>(0, token_bucket_.InMicroseconds())); | 44 std::max<int64_t>(0, token_bucket_.InMicroseconds())); |
45 } | 45 } |
46 current_event_ = event_time; | 46 current_event_ = event_time; |
47 } | 47 } |
48 | 48 |
49 bool SmoothEventSampler::ShouldSample() const { | 49 bool SmoothEventSampler::ShouldSample() const { |
50 return token_bucket_ >= min_capture_period_; | 50 return token_bucket_ >= min_capture_period_; |
51 } | 51 } |
52 | 52 |
53 void SmoothEventSampler::RecordSample() { | 53 void SmoothEventSampler::RecordSample() { |
54 token_bucket_ -= min_capture_period_; | 54 token_bucket_ -= min_capture_period_; |
55 if (token_bucket_ < base::TimeDelta()) | 55 if (token_bucket_ < base::TimeDelta()) |
56 token_bucket_ = base::TimeDelta(); | 56 token_bucket_ = base::TimeDelta(); |
57 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", | 57 TRACE_COUNTER1("gpu.capture", "MirroringTokenBucketUsec", |
58 std::max<int64>(0, token_bucket_.InMicroseconds())); | 58 std::max<int64_t>(0, token_bucket_.InMicroseconds())); |
59 | 59 |
60 if (HasUnrecordedEvent()) { | 60 if (HasUnrecordedEvent()) { |
61 last_sample_ = current_event_; | 61 last_sample_ = current_event_; |
62 overdue_sample_count_ = 0; | 62 overdue_sample_count_ = 0; |
63 } else { | 63 } else { |
64 ++overdue_sample_count_; | 64 ++overdue_sample_count_; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 bool SmoothEventSampler::IsOverdueForSamplingAt( | 68 bool SmoothEventSampler::IsOverdueForSamplingAt( |
(...skipping 11 matching lines...) Expand all Loading... |
80 base::TimeDelta dirty_interval = event_time - last_sample_; | 80 base::TimeDelta dirty_interval = event_time - last_sample_; |
81 return dirty_interval >= | 81 return dirty_interval >= |
82 base::TimeDelta::FromMilliseconds(OVERDUE_DIRTY_THRESHOLD_MILLIS); | 82 base::TimeDelta::FromMilliseconds(OVERDUE_DIRTY_THRESHOLD_MILLIS); |
83 } | 83 } |
84 | 84 |
85 bool SmoothEventSampler::HasUnrecordedEvent() const { | 85 bool SmoothEventSampler::HasUnrecordedEvent() const { |
86 return !current_event_.is_null() && current_event_ != last_sample_; | 86 return !current_event_.is_null() && current_event_ != last_sample_; |
87 } | 87 } |
88 | 88 |
89 } // namespace media | 89 } // namespace media |
OLD | NEW |