Chromium Code Reviews| Index: third_party/WebKit/Source/platform/scheduler/base/thread_load_tracker.h |
| diff --git a/third_party/WebKit/Source/platform/scheduler/base/thread_load_tracker.h b/third_party/WebKit/Source/platform/scheduler/base/thread_load_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c7e9ffced0fb8f96d9f11399155cc4991d308b4a |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/scheduler/base/thread_load_tracker.h |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_TRACKER_H_ |
| +#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_TRACKER_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/time/time.h" |
| +#include "public/platform/WebCommon.h" |
| + |
| +namespace blink { |
| +namespace scheduler { |
| + |
| +// This class tracks thread load level, i.e. percentage of wall time spent |
| +// running tasks. |
| +// In order to avoid bias it reports load level at regular intervals. |
| +class BLINK_PLATFORM_EXPORT ThreadLoadTracker { |
| + public: |
| + // Callback is called with (current_time, load_level) parameters. |
| + using Callback = base::Callback<void(base::TimeTicks, double)>; |
| + |
| + ThreadLoadTracker(base::TimeTicks now, const Callback& callback); |
| + ~ThreadLoadTracker(); |
| + |
| + void Pause(base::TimeTicks now); |
| + void Resume(base::TimeTicks now); |
| + |
| + void RecordTaskTime(base::TimeTicks start_time, base::TimeTicks end_time); |
| + |
| + void RecordIdle(base::TimeTicks now); |
| + |
| + // TODO(altimin): Count wakeups. |
| + |
| + private: |
| + enum class ThreadState { ACTIVE, PAUSED }; |
| + |
| + enum class TaskState { TASK_RUNNING, IDLE }; |
| + |
| + // This functions advances |time_| to |now|, calling |callback_| |
|
haraken
2016/08/23 02:35:45
function
|
| + // in the process (multiple times if needed). |
| + void Advance(base::TimeTicks now, TaskState task_state); |
| + |
| + double Load(); |
| + |
| + // |time_| is the last timestamp LoadTracker knows about. |
| + base::TimeTicks time_; |
| + base::TimeTicks next_reporting_time_; |
| + |
| + ThreadState thread_state_; |
| + base::TimeTicks last_state_change_time_; |
| + |
| + base::TimeDelta total_time_; |
| + base::TimeDelta total_runtime_; |
| + |
| + // Start reporting values after |waiting_period_|. |
| + base::TimeDelta waiting_period_; |
| + base::TimeDelta reporting_interval_; |
| + |
| + Callback callback_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ThreadLoadTracker); |
| +}; |
| + |
| +} // namespace scheduler |
| +} // namespace blink |
| + |
| +#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_LOAD_TRACKER_H_ |