1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SCHEDULING_METRICS_THREAD_METRICS_H_
6 #define COMPONENTS_SCHEDULING_METRICS_THREAD_METRICS_H_
8 #include "base/component_export.h"
9 #include "base/optional.h"
10 #include "base/task/sequence_manager/task_queue.h"
11 #include "base/time/time.h"
12 #include "components/scheduling_metrics/task_duration_metric_reporter.h"
13 #include "components/scheduling_metrics/thread_type.h"
14 #include "components/scheduling_metrics/total_duration_metric_reporter.h"
16 namespace scheduling_metrics {
18 // Helper class to take care of task metrics shared between different threads
19 // in Chrome, including but not limited to browser UI and IO threads, renderer
20 // main thread and blink worker threads.
22 class COMPONENT_EXPORT(SCHEDULING_METRICS) ThreadMetrics {
24 ThreadMetrics(ThreadType thread_type, bool has_cpu_timing_for_each_task);
27 bool ShouldDiscardTask(
28 base::sequence_manager::TaskQueue* queue,
29 const base::sequence_manager::Task& task,
30 const base::sequence_manager::TaskQueue::TaskTiming& task_timing);
32 // Record task metrics which are shared between threads.
33 void RecordTaskMetrics(
34 base::sequence_manager::TaskQueue* queue,
35 const base::sequence_manager::Task& task,
36 const base::sequence_manager::TaskQueue::TaskTiming& task_timing);
39 const ThreadType thread_type_;
40 const bool has_cpu_timing_for_each_task_;
43 base::ThreadTicks last_known_time_;
45 TaskDurationMetricReporter<ThreadType> thread_task_duration_reporter_;
46 TaskDurationMetricReporter<ThreadType> thread_task_cpu_duration_reporter_;
47 TaskDurationMetricReporter<ThreadType> tracked_cpu_duration_reporter_;
48 TaskDurationMetricReporter<ThreadType> non_tracked_cpu_duration_reporter_;
50 DISALLOW_COPY_AND_ASSIGN(ThreadMetrics);
53 } // namespace scheduling_metrics
55 #endif // COMPONENTS_SCHEDULING_METRICS_THREAD_METRICS_H_