Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / events / latency_info.h
blobffc9bdbde5e87193925f078ce28bbc7ebad46a43
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.
5 #ifndef UI_EVENTS_LATENCY_INFO_H_
6 #define UI_EVENTS_LATENCY_INFO_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/containers/small_map.h"
14 #include "base/time/time.h"
15 #include "ui/events/events_base_export.h"
17 namespace ui {
19 enum LatencyComponentType {
20 // ---------------------------BEGIN COMPONENT-------------------------------
21 // BEGIN COMPONENT is when we show the latency begin in chrome://tracing.
22 // Timestamp when the input event is sent from RenderWidgetHost to renderer.
23 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
24 // Timestamp when the input event is received in plugin.
25 INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT,
26 // In threaded scrolling, main thread scroll listener update is async to
27 // scroll processing in impl thread. This is the timestamp when we consider
28 // the main thread scroll listener update is begun.
29 LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT,
30 // ---------------------------NORMAL COMPONENT-------------------------------
31 // The original timestamp of the touch event which converts to scroll update.
32 INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
33 // The original timestamp of the touch event which converts to the *first*
34 // scroll update in a scroll gesture sequence.
35 INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
36 // Original timestamp for input event (e.g. timestamp from kernel).
37 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
38 // Timestamp when the UI event is created.
39 INPUT_EVENT_LATENCY_UI_COMPONENT,
40 // This is special component indicating there is rendering scheduled for
41 // the event associated with this LatencyInfo on main thread.
42 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT,
43 // This is special component indicating there is rendering scheduled for
44 // the event associated with this LatencyInfo on impl thread.
45 INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT,
46 // Timestamp when a scroll update is forwarded to the main thread.
47 INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT,
48 // Timestamp when the event's ack is received by the RWH.
49 INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT,
50 // Frame number when a window snapshot was requested. The snapshot
51 // is taken when the rendering results actually reach the screen.
52 WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
53 // Timestamp when a tab is requested to be shown.
54 TAB_SHOW_COMPONENT,
55 // Timestamp when the frame is swapped in renderer.
56 INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT,
57 // Timestamp of when the browser process receives a buffer swap notification
58 // from the renderer.
59 INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT,
60 // Timestamp of when the gpu service began swap buffers, unlike
61 // INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT which measures after.
62 INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT,
63 // ---------------------------TERMINAL COMPONENT-----------------------------
64 // TERMINAL COMPONENT is when we show the latency end in chrome://tracing.
65 // Timestamp when the mouse event is acked from renderer and it does not
66 // cause any rendering scheduled.
67 INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT,
68 // Timestamp when the touch event is acked from renderer and it does not
69 // cause any rendering schedueld and does not generate any gesture event.
70 INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT,
71 // Timestamp when the gesture event is acked from renderer, and it does not
72 // cause any rendering schedueld.
73 INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT,
74 // Timestamp when the frame is swapped (i.e. when the rendering caused by
75 // input event actually takes effect).
76 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
77 // This component indicates that the input causes a commit to be scheduled
78 // but the commit failed.
79 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT,
80 // This component indicates that the input causes a commit to be scheduled
81 // but the commit was aborted since it carried no new information.
82 INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT,
83 // This component indicates that the input causes a swap to be scheduled
84 // but the swap failed.
85 INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT,
86 // Timestamp when the input event is considered not cause any rendering
87 // damage in plugin and thus terminated.
88 INPUT_EVENT_LATENCY_TERMINATED_PLUGIN_COMPONENT,
89 LATENCY_COMPONENT_TYPE_LAST = INPUT_EVENT_LATENCY_TERMINATED_PLUGIN_COMPONENT
92 struct EVENTS_BASE_EXPORT LatencyInfo {
93 struct LatencyComponent {
94 // Nondecreasing number that can be used to determine what events happened
95 // in the component at the time this struct was sent on to the next
96 // component.
97 int64 sequence_number;
98 // Average time of events that happened in this component.
99 base::TimeTicks event_time;
100 // Count of events that happened in this component
101 uint32 event_count;
104 struct EVENTS_BASE_EXPORT InputCoordinate {
105 InputCoordinate();
106 InputCoordinate(float x, float y);
108 float x;
109 float y;
112 // Empirically determined constant based on a typical scroll sequence.
113 enum { kTypicalMaxComponentsPerLatencyInfo = 10 };
115 enum { kMaxInputCoordinates = 2 };
117 // Map a Latency Component (with a component-specific int64 id) to a
118 // component info.
119 typedef base::SmallMap<
120 std::map<std::pair<LatencyComponentType, int64>, LatencyComponent>,
121 kTypicalMaxComponentsPerLatencyInfo> LatencyMap;
123 LatencyInfo();
125 ~LatencyInfo();
127 // Returns true if the vector |latency_info| is valid. Returns false
128 // if it is not valid and log the |referring_msg|.
129 // This function is mainly used to check the latency_info vector that
130 // is passed between processes using IPC message has reasonable size
131 // so that we are confident the IPC message is not corrupted/compromised.
132 // This check will go away once the IPC system has better built-in scheme
133 // for corruption/compromise detection.
134 static bool Verify(const std::vector<LatencyInfo>& latency_info,
135 const char* referring_msg);
137 // Copy LatencyComponents with type |type| from |other| into |this|.
138 void CopyLatencyFrom(const LatencyInfo& other, LatencyComponentType type);
140 // Add LatencyComponents that are in |other| but not in |this|.
141 void AddNewLatencyFrom(const LatencyInfo& other);
143 // Modifies the current sequence number for a component, and adds a new
144 // sequence number with the current timestamp.
145 void AddLatencyNumber(LatencyComponentType component,
146 int64 id,
147 int64 component_sequence_number);
149 // Similar to |AddLatencyNumber|, and also appends |trace_name_str| to
150 // the trace event's name.
151 // This function should only be called when adding a BEGIN component.
152 void AddLatencyNumberWithTraceName(LatencyComponentType component,
153 int64 id,
154 int64 component_sequence_number,
155 const char* trace_name_str);
157 // Modifies the current sequence number and adds a certain number of events
158 // for a specific component.
159 void AddLatencyNumberWithTimestamp(LatencyComponentType component,
160 int64 id,
161 int64 component_sequence_number,
162 base::TimeTicks time,
163 uint32 event_count);
165 void AddLatencyNumberWithTimestampImpl(LatencyComponentType component,
166 int64 id,
167 int64 component_sequence_number,
168 base::TimeTicks time,
169 uint32 event_count,
170 const char* trace_name_str);
172 // Returns true if the a component with |type| and |id| is found in
173 // the latency_components and the component is stored to |output| if
174 // |output| is not NULL. Returns false if no such component is found.
175 bool FindLatency(LatencyComponentType type,
176 int64 id,
177 LatencyComponent* output) const;
179 void RemoveLatency(LatencyComponentType type);
181 void Clear();
183 // Shown as part of the name of the trace event for this LatencyInfo.
184 // String is empty if no tracing is enabled.
185 std::string trace_name;
187 LatencyMap latency_components;
189 // These coordinates represent window coordinates of the original input event.
190 uint32 input_coordinates_size;
191 InputCoordinate input_coordinates[kMaxInputCoordinates];
193 // The unique id for matching the ASYNC_BEGIN/END trace event.
194 int64 trace_id;
195 // Whether a terminal component has been added.
196 bool terminated;
199 } // namespace ui
201 #endif // UI_EVENTS_LATENCY_INFO_H_