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..75b473161fdbfa7e6b5c48cdd91ae36fd3aa5497 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/scheduler/base/thread_load_tracker.h |
@@ -0,0 +1,70 @@ |
+// 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 renderer load level, e.g. percentage of wall time spent |
Sami
2016/08/22 16:35:40
s/renderer/thread/
Also since this class doesn't
altimin
2016/08/22 17:02:23
Replacement done.
Actually, given that we process
|
+// 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 |
+ }; |
+ |
+ void Advance(base::TimeTicks now, TaskState task_state); |
+ |
+ double Load(); |
+ |
+ base::TimeTicks current_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_ |