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

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

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