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