| OLD | NEW |
| 1 // Copyright 2016 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_TRAC
KER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_TRAC
KER_H_ |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_TRAC
KER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_TRAC
KER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "public/platform/WebCommon.h" | 11 #include "public/platform/WebCommon.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 namespace scheduler { | 14 namespace scheduler { |
| 15 | 15 |
| 16 // This class tracks thread load level, i.e. percentage of wall time spent | 16 // This class tracks thread load level, i.e. percentage of wall time spent |
| 17 // running tasks. | 17 // running tasks. |
| 18 // In order to avoid bias it reports load level at regular intervals. | 18 // In order to avoid bias it reports load level at regular intervals. |
| 19 // Every |reporting_interval_| time units, it reports the average thread load |
| 20 // level computed using a sliding window of width |reporting_interval_|. |
| 19 class BLINK_PLATFORM_EXPORT ThreadLoadTracker { | 21 class BLINK_PLATFORM_EXPORT ThreadLoadTracker { |
| 20 public: | 22 public: |
| 21 // Callback is called with (current_time, load_level) parameters. | 23 // Callback is called with (current_time, load_level) parameters. |
| 22 using Callback = base::Callback<void(base::TimeTicks, double)>; | 24 using Callback = base::Callback<void(base::TimeTicks, double)>; |
| 23 | 25 |
| 24 ThreadLoadTracker(base::TimeTicks now, const Callback& callback); | 26 ThreadLoadTracker(base::TimeTicks now, |
| 27 const Callback& callback, |
| 28 base::TimeDelta reporting_interval, |
| 29 base::TimeDelta waiting_period); |
| 25 ~ThreadLoadTracker(); | 30 ~ThreadLoadTracker(); |
| 26 | 31 |
| 27 void Pause(base::TimeTicks now); | 32 void Pause(base::TimeTicks now); |
| 28 void Resume(base::TimeTicks now); | 33 void Resume(base::TimeTicks now); |
| 29 | 34 |
| 30 void RecordTaskTime(base::TimeTicks start_time, base::TimeTicks end_time); | 35 void RecordTaskTime(base::TimeTicks start_time, base::TimeTicks end_time); |
| 31 | 36 |
| 32 void RecordIdle(base::TimeTicks now); | 37 void RecordIdle(base::TimeTicks now); |
| 33 | 38 |
| 34 // TODO(altimin): Count wakeups. | 39 // TODO(altimin): Count wakeups. |
| 35 | 40 |
| 36 private: | 41 private: |
| 37 enum class ThreadState { ACTIVE, PAUSED }; | 42 enum class ThreadState { ACTIVE, PAUSED }; |
| 38 | 43 |
| 39 enum class TaskState { TASK_RUNNING, IDLE }; | 44 enum class TaskState { TASK_RUNNING, IDLE }; |
| 40 | 45 |
| 41 // This function advances |time_| to |now|, calling |callback_| | 46 // This function advances |time_| to |now|, calling |callback_| |
| 42 // in the process (multiple times if needed). | 47 // in the process (multiple times if needed). |
| 43 void Advance(base::TimeTicks now, TaskState task_state); | 48 void Advance(base::TimeTicks now, TaskState task_state); |
| 44 | 49 |
| 45 double Load(); | 50 double Load(); |
| 46 | 51 |
| 47 // |time_| is the last timestamp LoadTracker knows about. | 52 // |time_| is the last timestamp LoadTracker knows about. |
| 48 base::TimeTicks time_; | 53 base::TimeTicks time_; |
| 49 base::TimeTicks next_reporting_time_; | 54 base::TimeTicks next_reporting_time_; |
| 55 // Total period for which this LoadTracker was active. Needed to discard |
| 56 // first |waiting_period_| time. |
| 57 base::TimeDelta total_active_time_; |
| 50 | 58 |
| 51 ThreadState thread_state_; | 59 ThreadState thread_state_; |
| 52 base::TimeTicks last_state_change_time_; | 60 base::TimeTicks last_state_change_time_; |
| 53 | 61 |
| 54 base::TimeDelta total_time_; | |
| 55 base::TimeDelta total_runtime_; | |
| 56 | |
| 57 // Start reporting values after |waiting_period_|. | 62 // Start reporting values after |waiting_period_|. |
| 58 base::TimeDelta waiting_period_; | 63 base::TimeDelta waiting_period_; |
| 59 base::TimeDelta reporting_interval_; | 64 base::TimeDelta reporting_interval_; |
| 60 | 65 |
| 66 // Recorded run time in window |
| 67 // [next_reporting_time - reporting_interval, next_reporting_time]. |
| 68 base::TimeDelta run_time_inside_window_; |
| 69 |
| 61 Callback callback_; | 70 Callback callback_; |
| 62 | 71 |
| 63 DISALLOW_COPY_AND_ASSIGN(ThreadLoadTracker); | 72 DISALLOW_COPY_AND_ASSIGN(ThreadLoadTracker); |
| 64 }; | 73 }; |
| 65 | 74 |
| 66 } // namespace scheduler | 75 } // namespace scheduler |
| 67 } // namespace blink | 76 } // namespace blink |
| 68 | 77 |
| 69 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_T
RACKER_H_ | 78 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_T
RACKER_H_ |
| OLD | NEW |