thread_metrics.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.
  4. #ifndef COMPONENTS_SCHEDULING_METRICS_THREAD_METRICS_H_
  5. #define COMPONENTS_SCHEDULING_METRICS_THREAD_METRICS_H_
  6. #include "base/component_export.h"
  7. #include "base/task/sequence_manager/task_queue.h"
  8. #include "base/time/time.h"
  9. #include "components/scheduling_metrics/task_duration_metric_reporter.h"
  10. #include "components/scheduling_metrics/thread_type.h"
  11. #include "components/scheduling_metrics/total_duration_metric_reporter.h"
  12. namespace scheduling_metrics {
  13. // Helper class to take care of task metrics shared between different threads
  14. // in Chrome, including but not limited to browser UI and IO threads, renderer
  15. // main thread and blink worker threads.
  16. //
  17. class COMPONENT_EXPORT(SCHEDULING_METRICS) ThreadMetrics {
  18. public:
  19. ThreadMetrics(ThreadType thread_type, bool has_cpu_timing_for_each_task);
  20. ThreadMetrics(const ThreadMetrics&) = delete;
  21. ThreadMetrics& operator=(const ThreadMetrics&) = delete;
  22. ~ThreadMetrics();
  23. bool ShouldDiscardTask(
  24. const base::sequence_manager::Task& task,
  25. const base::sequence_manager::TaskQueue::TaskTiming& task_timing);
  26. // Record task metrics which are shared between threads.
  27. void RecordTaskMetrics(
  28. const base::sequence_manager::Task& task,
  29. const base::sequence_manager::TaskQueue::TaskTiming& task_timing);
  30. protected:
  31. const ThreadType thread_type_;
  32. const bool has_cpu_timing_for_each_task_;
  33. private:
  34. base::ThreadTicks last_known_time_;
  35. TaskDurationMetricReporter<ThreadType> thread_task_duration_reporter_;
  36. TaskDurationMetricReporter<ThreadType> thread_task_cpu_duration_reporter_;
  37. TaskDurationMetricReporter<ThreadType> tracked_cpu_duration_reporter_;
  38. TaskDurationMetricReporter<ThreadType> non_tracked_cpu_duration_reporter_;
  39. };
  40. } // namespace scheduling_metrics
  41. #endif // COMPONENTS_SCHEDULING_METRICS_THREAD_METRICS_H_