Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: ui/events/latency_info.h

Issue 2783973002: Moving LatencyInfo into a separate component. (Closed)
Patch Set: Rebase again Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/ipc/latency_info_param_traits_unittest.cc ('k') | ui/events/latency_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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
5 #ifndef UI_EVENTS_LATENCY_INFO_H_
6 #define UI_EVENTS_LATENCY_INFO_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <utility>
13 #include <vector>
14
15 #include "base/containers/small_map.h"
16 #include "base/time/time.h"
17 #include "ui/events/events_base_export.h"
18 #include "ui/gfx/geometry/point_f.h"
19
20 #if !defined(OS_IOS)
21 #include "ipc/ipc_param_traits.h" // nogncheck
22 #include "mojo/public/cpp/bindings/struct_traits.h" // nogncheck
23 #endif
24
25 namespace base {
26 namespace trace_event {
27 class ConvertableToTraceFormat;
28 }
29 }
30
31 namespace ui {
32
33 #if !defined(OS_IOS)
34 namespace mojom {
35 class LatencyInfoDataView;
36 }
37 #endif
38
39 // When adding new components, or new metrics based on LatencyInfo,
40 // please update latency_info.dot.
41 enum LatencyComponentType {
42 // ---------------------------BEGIN COMPONENT-------------------------------
43 // BEGIN COMPONENT is when we show the latency begin in chrome://tracing.
44 // Timestamp when the input event is sent from RenderWidgetHost to renderer.
45 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
46 // In threaded scrolling, main thread scroll listener update is async to
47 // scroll processing in impl thread. This is the timestamp when we consider
48 // the main thread scroll listener update is begun.
49 LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT,
50 // ---------------------------NORMAL COMPONENT-------------------------------
51 // The original timestamp of the touch event which converts to scroll update.
52 INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
53 // The original timestamp of the touch event which converts to the *first*
54 // scroll update in a scroll gesture sequence.
55 INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
56 // Original timestamp for input event (e.g. timestamp from kernel).
57 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
58 // Timestamp when the UI event is created.
59 INPUT_EVENT_LATENCY_UI_COMPONENT,
60 // Timestamp when the event is dispatched on the main thread of the renderer.
61 INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT,
62 // This is special component indicating there is rendering scheduled for
63 // the event associated with this LatencyInfo on main thread.
64 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT,
65 // This is special component indicating there is rendering scheduled for
66 // the event associated with this LatencyInfo on impl thread.
67 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT,
68 // Timestamp when a scroll update is forwarded to the main thread.
69 INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT,
70 // Timestamp when the event's ack is received by the RWH.
71 INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT,
72 // Frame number when a window snapshot was requested. The snapshot
73 // is taken when the rendering results actually reach the screen.
74 WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
75 // Timestamp when a tab is requested to be shown.
76 TAB_SHOW_COMPONENT,
77 // Timestamp when the frame is swapped in renderer.
78 INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT,
79 // Timestamp of when the browser process receives a buffer swap notification
80 // from the renderer.
81 INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT,
82 // Timestamp of when the gpu service began swap buffers, unlike
83 // INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT which measures after.
84 INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT,
85 // Timestamp of when the gesture scroll update is generated from a mouse wheel
86 // event.
87 INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL,
88 // ---------------------------TERMINAL COMPONENT-----------------------------
89 // Timestamp when the event is acked from renderer when it does not
90 // cause any rendering to be scheduled.
91 INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT,
92 // Timestamp when the frame is swapped (i.e. when the rendering caused by
93 // input event actually takes effect).
94 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
95 // This component indicates that the input causes a commit to be scheduled
96 // but the commit failed.
97 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT,
98 // This component indicates that the input causes a commit to be scheduled
99 // but the commit was aborted since it carried no new information.
100 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT,
101 // This component indicates that the input causes a swap to be scheduled
102 // but the swap failed.
103 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT,
104 LATENCY_COMPONENT_TYPE_LAST =
105 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT,
106 };
107
108 enum SourceEventType {
109 UNKNOWN,
110 WHEEL,
111 TOUCH,
112 OTHER,
113 SOURCE_EVENT_TYPE_LAST = OTHER,
114 };
115
116 class EVENTS_BASE_EXPORT LatencyInfo {
117 public:
118 struct LatencyComponent {
119 // Nondecreasing number that can be used to determine what events happened
120 // in the component at the time this struct was sent on to the next
121 // component.
122 int64_t sequence_number;
123 // Average time of events that happened in this component.
124 base::TimeTicks event_time;
125 // Count of events that happened in this component
126 uint32_t event_count;
127 // Time of the oldest event that happened in this component.
128 base::TimeTicks first_event_time;
129 // Time of the most recent event that happened in this component.
130 base::TimeTicks last_event_time;
131 };
132
133 // Empirically determined constant based on a typical scroll sequence.
134 enum { kTypicalMaxComponentsPerLatencyInfo = 10 };
135
136 enum : size_t { kMaxInputCoordinates = 2 };
137
138 // Map a Latency Component (with a component-specific int64_t id) to a
139 // component info.
140 typedef base::SmallMap<
141 std::map<std::pair<LatencyComponentType, int64_t>, LatencyComponent>,
142 kTypicalMaxComponentsPerLatencyInfo> LatencyMap;
143
144 LatencyInfo();
145 LatencyInfo(const LatencyInfo& other);
146 LatencyInfo(SourceEventType type);
147 ~LatencyInfo();
148
149 // For test only.
150 LatencyInfo(int64_t trace_id, bool terminated);
151
152 // Returns true if the vector |latency_info| is valid. Returns false
153 // if it is not valid and log the |referring_msg|.
154 // This function is mainly used to check the latency_info vector that
155 // is passed between processes using IPC message has reasonable size
156 // so that we are confident the IPC message is not corrupted/compromised.
157 // This check will go away once the IPC system has better built-in scheme
158 // for corruption/compromise detection.
159 static bool Verify(const std::vector<LatencyInfo>& latency_info,
160 const char* referring_msg);
161
162 // Copy LatencyComponents with type |type| from |other| into |this|.
163 void CopyLatencyFrom(const LatencyInfo& other, LatencyComponentType type);
164
165 // Add LatencyComponents that are in |other| but not in |this|.
166 void AddNewLatencyFrom(const LatencyInfo& other);
167
168 // Modifies the current sequence number for a component, and adds a new
169 // sequence number with the current timestamp.
170 void AddLatencyNumber(LatencyComponentType component,
171 int64_t id,
172 int64_t component_sequence_number);
173
174 // Similar to |AddLatencyNumber|, and also appends |trace_name_str| to
175 // the trace event's name.
176 // This function should only be called when adding a BEGIN component.
177 void AddLatencyNumberWithTraceName(LatencyComponentType component,
178 int64_t id,
179 int64_t component_sequence_number,
180 const char* trace_name_str);
181
182 // Modifies the current sequence number and adds a certain number of events
183 // for a specific component.
184 void AddLatencyNumberWithTimestamp(LatencyComponentType component,
185 int64_t id,
186 int64_t component_sequence_number,
187 base::TimeTicks time,
188 uint32_t event_count);
189
190 // Returns true if the a component with |type| and |id| is found in
191 // the latency_components and the component is stored to |output| if
192 // |output| is not NULL. Returns false if no such component is found.
193 bool FindLatency(LatencyComponentType type,
194 int64_t id,
195 LatencyComponent* output) const;
196
197 void RemoveLatency(LatencyComponentType type);
198
199 // Returns true if there is still room for keeping the |input_coordinate|,
200 // false otherwise.
201 bool AddInputCoordinate(const gfx::PointF& input_coordinate);
202
203 uint32_t input_coordinates_size() const { return input_coordinates_size_; }
204 const gfx::PointF* input_coordinates() const { return input_coordinates_; }
205
206 const LatencyMap& latency_components() const { return latency_components_; }
207
208 const SourceEventType& source_event_type() const {
209 return source_event_type_;
210 }
211 void set_source_event_type(SourceEventType type) {
212 source_event_type_ = type;
213 }
214
215 bool terminated() const { return terminated_; }
216 void set_coalesced() { coalesced_ = true; }
217 bool coalesced() const { return coalesced_; }
218 int64_t trace_id() const { return trace_id_; }
219
220 private:
221 void AddLatencyNumberWithTimestampImpl(LatencyComponentType component,
222 int64_t id,
223 int64_t component_sequence_number,
224 base::TimeTicks time,
225 uint32_t event_count,
226 const char* trace_name_str);
227
228 // Converts latencyinfo into format that can be dumped into trace buffer.
229 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
230 AsTraceableData();
231 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
232 CoordinatesAsTraceableData();
233
234 // Shown as part of the name of the trace event for this LatencyInfo.
235 // String is empty if no tracing is enabled.
236 std::string trace_name_;
237
238 LatencyMap latency_components_;
239
240 // These coordinates represent window coordinates of the original input event.
241 uint32_t input_coordinates_size_;
242 gfx::PointF input_coordinates_[kMaxInputCoordinates];
243
244 // The unique id for matching the ASYNC_BEGIN/END trace event.
245 int64_t trace_id_;
246 // Whether this event has been coalesced into another event.
247 bool coalesced_;
248 // Whether a terminal component has been added.
249 bool terminated_;
250 // Stores the type of the first source event.
251 SourceEventType source_event_type_;
252
253 #if !defined(OS_IOS)
254 friend struct IPC::ParamTraits<ui::LatencyInfo>;
255 friend struct mojo::StructTraits<ui::mojom::LatencyInfoDataView,
256 ui::LatencyInfo>;
257 #endif
258 };
259
260 } // namespace ui
261
262 #endif // UI_EVENTS_LATENCY_INFO_H_
OLDNEW
« no previous file with comments | « ui/events/ipc/latency_info_param_traits_unittest.cc ('k') | ui/events/latency_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698