[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / metrics / compositor_timing_history.h
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.
4
5 #ifndef CC_METRICS_COMPOSITOR_TIMING_HISTORY_H_
6 #define CC_METRICS_COMPOSITOR_TIMING_HISTORY_H_
7
8 #include <memory>
9 #include <vector>
10
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"
19
20 namespace perfetto {
21 namespace protos {
22 namespace pbzero {
23 class CompositorTimingHistory;
24 }
25 }  // namespace protos
26 }  // namespace perfetto
27
28 namespace cc {
29 class RenderingStatsInstrumentation;
30
31 class CC_EXPORT CompositorTimingHistory {
32  public:
33   enum UMACategory {
34     RENDERER_UMA,
35     BROWSER_UMA,
36     NULL_UMA,
37   };
38   class UMAReporter;
39
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();
46
47   CompositorTimingHistory& operator=(const CompositorTimingHistory&) = delete;
48
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()
53       const;
54   virtual base::TimeDelta BeginMainFrameStartToReadyToCommitDurationEstimate()
55       const;
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;
61
62   base::TimeDelta BeginMainFrameStartToReadyToCommitCriticalEstimate() const;
63   base::TimeDelta BeginMainFrameStartToReadyToCommitNotCriticalEstimate() const;
64   base::TimeDelta BeginMainFrameQueueToActivateCriticalEstimate() const;
65
66   // State that affects when events should be expected/recorded/reported.
67   void SetRecordingEnabled(bool enabled);
68
69   // Events to be timed.
70   void WillBeginImplFrame(const viz::BeginFrameArgs& args,
71                           base::TimeTicks now);
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();
78   void WillCommit();
79   void DidCommit();
80   void WillPrepareTiles();
81   void DidPrepareTiles();
82   void ReadyToActivate();
83   void WillActivate();
84   void DidActivate();
85   void WillDraw();
86   void DidDraw(bool used_new_active_tree,
87                bool has_custom_property_animations);
88   void WillInvalidateOnImplSide();
89
90   // Record the scheduler's deadline mode and send to UMA.
91   using DeadlineMode = SchedulerStateMachine::BeginImplFrameDeadlineMode;
92   void RecordDeadlineMode(DeadlineMode deadline_mode);
93
94   base::TimeTicks begin_main_frame_sent_time() const {
95     return begin_main_frame_sent_time_;
96   }
97
98   void ClearHistory();
99
100   size_t CommitDurationSampleCountForTesting() const;
101
102  protected:
103   void DidBeginMainFrame(base::TimeTicks begin_main_frame_end_time);
104
105   void SetCompositorDrawingContinuously(bool active);
106
107   static std::unique_ptr<UMAReporter> CreateUMAReporter(UMACategory category);
108   virtual base::TimeTicks Now() const;
109
110   bool using_synchronous_renderer_compositor_;
111   bool enabled_;
112
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_;
117
118   // If you add any history here, please remember to reset it in
119   // ClearHistory.
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_;
130
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
134   // sum instead.
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_;
142
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
147   // pending tree.
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_;
152
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_;
165
166   bool pending_tree_is_impl_side_;
167
168   std::unique_ptr<UMAReporter> uma_reporter_;
169
170   // Owned by LayerTreeHost and is destroyed when LayerTreeHost is destroyed.
171   raw_ptr<RenderingStatsInstrumentation> rendering_stats_instrumentation_;
172
173   // Used only for reporting animation targeted UMA.
174   bool previous_frame_had_custom_property_animations_ = false;
175 };
176
177 }  // namespace cc
178
179 #endif  // CC_METRICS_COMPOSITOR_TIMING_HISTORY_H_