1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_METRICS_COMPOSITOR_TIMING_HISTORY_H_
6 #define CC_METRICS_COMPOSITOR_TIMING_HISTORY_H_
11 #include "base/memory/raw_ptr.h"
12 #include "base/time/time.h"
13 #include "cc/base/rolling_time_delta_history.h"
14 #include "cc/cc_export.h"
15 #include "cc/metrics/event_metrics.h"
16 #include "cc/scheduler/scheduler.h"
17 #include "cc/tiles/tile_priority.h"
18 #include "components/viz/common/frame_sinks/begin_frame_args.h"
23 class CompositorTimingHistory;
26 } // namespace perfetto
29 class RenderingStatsInstrumentation;
31 class CC_EXPORT CompositorTimingHistory {
40 CompositorTimingHistory(
41 bool using_synchronous_renderer_compositor,
42 UMACategory uma_category,
43 RenderingStatsInstrumentation* rendering_stats_instrumentation);
44 CompositorTimingHistory(const CompositorTimingHistory&) = delete;
45 virtual ~CompositorTimingHistory();
47 CompositorTimingHistory& operator=(const CompositorTimingHistory&) = delete;
49 // The main thread responsiveness depends heavily on whether or not the
50 // on_critical_path flag is set, so we record response times separately.
51 virtual base::TimeDelta BeginMainFrameQueueDurationCriticalEstimate() const;
52 virtual base::TimeDelta BeginMainFrameQueueDurationNotCriticalEstimate()
54 virtual base::TimeDelta BeginMainFrameStartToReadyToCommitDurationEstimate()
56 virtual base::TimeDelta CommitDurationEstimate() const;
57 virtual base::TimeDelta CommitToReadyToActivateDurationEstimate() const;
58 virtual base::TimeDelta PrepareTilesDurationEstimate() const;
59 virtual base::TimeDelta ActivateDurationEstimate() const;
60 virtual base::TimeDelta DrawDurationEstimate() const;
62 base::TimeDelta BeginMainFrameStartToReadyToCommitCriticalEstimate() const;
63 base::TimeDelta BeginMainFrameStartToReadyToCommitNotCriticalEstimate() const;
64 base::TimeDelta BeginMainFrameQueueToActivateCriticalEstimate() const;
66 // State that affects when events should be expected/recorded/reported.
67 void SetRecordingEnabled(bool enabled);
69 // Events to be timed.
70 void WillBeginImplFrame(const viz::BeginFrameArgs& args,
72 void WillFinishImplFrame(bool needs_redraw);
73 void BeginImplFrameNotExpectedSoon();
74 void WillBeginMainFrame(const viz::BeginFrameArgs& args);
75 void BeginMainFrameStarted(base::TimeTicks begin_main_frame_start_time_);
76 void BeginMainFrameAborted();
77 void NotifyReadyToCommit();
80 void WillPrepareTiles();
81 void DidPrepareTiles();
82 void ReadyToActivate();
86 void DidDraw(bool used_new_active_tree,
87 bool has_custom_property_animations);
88 void WillInvalidateOnImplSide();
90 // Record the scheduler's deadline mode and send to UMA.
91 using DeadlineMode = SchedulerStateMachine::BeginImplFrameDeadlineMode;
92 void RecordDeadlineMode(DeadlineMode deadline_mode);
94 base::TimeTicks begin_main_frame_sent_time() const {
95 return begin_main_frame_sent_time_;
100 size_t CommitDurationSampleCountForTesting() const;
103 void DidBeginMainFrame(base::TimeTicks begin_main_frame_end_time);
105 void SetCompositorDrawingContinuously(bool active);
107 static std::unique_ptr<UMAReporter> CreateUMAReporter(UMACategory category);
108 virtual base::TimeTicks Now() const;
110 bool using_synchronous_renderer_compositor_;
113 // Used to calculate frame rates of Main and Impl threads.
114 bool compositor_drawing_continuously_;
115 base::TimeTicks new_active_tree_draw_end_time_prev_;
116 base::TimeTicks draw_end_time_prev_;
118 // If you add any history here, please remember to reset it in
120 RollingTimeDeltaHistory begin_main_frame_queue_duration_history_;
121 RollingTimeDeltaHistory begin_main_frame_queue_duration_critical_history_;
122 RollingTimeDeltaHistory begin_main_frame_queue_duration_not_critical_history_;
123 RollingTimeDeltaHistory
124 begin_main_frame_start_to_ready_to_commit_duration_history_;
125 RollingTimeDeltaHistory commit_duration_history_;
126 RollingTimeDeltaHistory commit_to_ready_to_activate_duration_history_;
127 RollingTimeDeltaHistory prepare_tiles_duration_history_;
128 RollingTimeDeltaHistory activate_duration_history_;
129 RollingTimeDeltaHistory draw_duration_history_;
131 // Used for duration estimates when enabled. Without this feature, compositor
132 // timing history collects timing history of each stage and use sum of
133 // percentile for duration estimates. With this feature, we use percentile of
135 bool duration_estimates_enabled_;
136 RollingTimeDeltaHistory bmf_start_to_ready_to_commit_critical_history_;
137 double bmf_start_to_ready_to_commit_critical_percentile_;
138 RollingTimeDeltaHistory bmf_start_to_ready_to_commit_not_critical_history_;
139 double bmf_start_to_ready_to_commit_not_critical_percentile_;
140 RollingTimeDeltaHistory bmf_queue_to_activate_critical_history_;
141 double bmf_queue_to_activate_critical_percentile_;
143 // The time between when BMF was posted to the main thread task queue, and the
144 // timestamp taken on the main thread when the BMF started running.
145 base::TimeDelta begin_main_frame_queue_duration_;
146 // The value of begin_main_frame_queue_duration_ that was measured for the
148 base::TimeDelta pending_tree_bmf_queue_duration_;
149 // The time between when BMF was posted to the main thread task queue, and
150 // when the result of the BMF finished activation.
151 base::TimeDelta bmf_start_to_ready_to_activate_duration_;
153 bool begin_main_frame_on_critical_path_ = false;
154 bool pending_commit_on_critical_path_ = false;
155 bool pending_tree_on_critical_path_ = false;
156 base::TimeTicks begin_main_frame_sent_time_;
157 base::TimeTicks begin_main_frame_start_time_;
158 base::TimeTicks ready_to_commit_time_;
159 base::TimeTicks commit_start_time_;
160 base::TimeTicks pending_tree_creation_time_;
161 base::TimeTicks pending_tree_ready_to_activate_time_;
162 base::TimeTicks prepare_tiles_start_time_;
163 base::TimeTicks activate_start_time_;
164 base::TimeTicks draw_start_time_;
166 bool pending_tree_is_impl_side_;
168 std::unique_ptr<UMAReporter> uma_reporter_;
170 // Owned by LayerTreeHost and is destroyed when LayerTreeHost is destroyed.
171 raw_ptr<RenderingStatsInstrumentation> rendering_stats_instrumentation_;
173 // Used only for reporting animation targeted UMA.
174 bool previous_frame_had_custom_property_animations_ = false;
179 #endif // CC_METRICS_COMPOSITOR_TIMING_HISTORY_H_