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

Side by Side Diff: ui/latency/latency_tracker.cc

Issue 2814483002: Splitting up RenderWidgetHostLatencyTracker and some renames. (Closed)
Patch Set: Rebase 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
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "ui/latency/latency_tracker.h"
6
7 #include "base/metrics/histogram_functions.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "ui/latency/latency_histogram_macros.h"
10
11 namespace ui {
12 namespace {
13
14 std::string LatencySourceEventTypeToInputModalityString(
15 ui::SourceEventType type) {
16 switch (type) {
17 case ui::SourceEventType::WHEEL:
18 return "Wheel";
19 case ui::SourceEventType::TOUCH:
20 return "Touch";
21 default:
22 return "";
23 }
24 }
25
26 void ComputeScrollLatencyHistograms(
27 const LatencyInfo::LatencyComponent& gpu_swap_begin_component,
28 const LatencyInfo::LatencyComponent& gpu_swap_end_component,
29 const LatencyInfo& latency) {
30 DCHECK(!latency.coalesced());
31 if (latency.coalesced())
32 return;
33
34 DCHECK(!gpu_swap_begin_component.event_time.is_null());
35 DCHECK(!gpu_swap_end_component.event_time.is_null());
36 LatencyInfo::LatencyComponent original_component;
37 if (latency.FindLatency(
38 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
39 &original_component)) {
40 // This UMA metric tracks the time between the final frame swap for the
41 // first scroll event in a sequence and the original timestamp of that
42 // scroll event's underlying touch event.
43 for (size_t i = 0; i < original_component.event_count; i++) {
44 UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS(
45 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", original_component,
46 gpu_swap_begin_component);
47 }
48 } else if (!latency.FindLatency(
49 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
50 &original_component)) {
51 return;
52 }
53
54 // This UMA metric tracks the time from when the original touch event is
55 // created to when the scroll gesture results in final frame swap.
56 for (size_t i = 0; i < original_component.event_count; i++) {
57 UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS(
58 "Event.Latency.TouchToScrollUpdateSwapBegin", original_component,
59 gpu_swap_begin_component);
60 }
61 }
62
63 } // namespace
64
65 void LatencyTracker::ReportRapporScrollLatency(
66 const std::string& name,
67 const LatencyInfo::LatencyComponent& start_component,
68 const LatencyInfo::LatencyComponent& end_component) {}
69
70 void LatencyTracker::ComputeTouchAndWheelScrollLatencyHistograms(
71 const ui::LatencyInfo::LatencyComponent& gpu_swap_begin_component,
72 const ui::LatencyInfo::LatencyComponent& gpu_swap_end_component,
73 const ui::LatencyInfo& latency) {
74 DCHECK(!latency.coalesced());
75 if (latency.coalesced())
76 return;
77
78 LatencyInfo::LatencyComponent original_component;
79 std::string scroll_name = "ScrollUpdate";
80
81 const std::string input_modality =
82 LatencySourceEventTypeToInputModalityString(latency.source_event_type());
83
84 if (latency.FindLatency(
85 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
86 &original_component)) {
87 scroll_name = "ScrollBegin";
88 // This UMA metric tracks the time between the final frame swap for the
89 // first scroll event in a sequence and the original timestamp of that
90 // scroll event's underlying touch/wheel event.
91 UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS(
92 "Event.Latency.ScrollBegin." + input_modality +
93 ".TimeToScrollUpdateSwapBegin2",
94 original_component, gpu_swap_begin_component);
95
96 ReportRapporScrollLatency("Event.Latency.ScrollBegin." + input_modality +
97 ".TimeToScrollUpdateSwapBegin2",
98 original_component, gpu_swap_begin_component);
99
100 // TODO(lanwei): Will remove them when M56 is stable, see
101 // https://crbug.com/669618.
102 UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS(
103 "Event.Latency.ScrollUpdate." + input_modality +
104 ".TimeToFirstScrollUpdateSwapBegin2",
105 original_component, gpu_swap_begin_component);
106 } else if (latency.FindLatency(
107 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
108 &original_component)) {
109 // This UMA metric tracks the time from when the original touch event is
110 // created to when the scroll gesture results in final frame swap.
111 // First scroll events are excluded from this metric.
112 if (input_modality == "Touch") {
113 UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS(
114 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2",
115 original_component, gpu_swap_begin_component);
116
117 ReportRapporScrollLatency(
118 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2",
119 original_component, gpu_swap_begin_component);
120 }
121 } else {
122 // No original component found.
123 return;
124 }
125
126 LatencyInfo::LatencyComponent rendering_scheduled_component;
127 bool rendering_scheduled_on_main = latency.FindLatency(
128 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT, 0,
129 &rendering_scheduled_component);
130 if (!rendering_scheduled_on_main) {
131 if (!latency.FindLatency(
132 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0,
133 &rendering_scheduled_component))
134 return;
135 }
136
137 const std::string thread_name = rendering_scheduled_on_main ? "Main" : "Impl";
138
139 UMA_HISTOGRAM_SCROLL_LATENCY_LONG_2(
140 "Event.Latency." + scroll_name + "." + input_modality +
141 ".TimeToHandled2_" + thread_name,
142 original_component, rendering_scheduled_component);
143
144 LatencyInfo::LatencyComponent renderer_swap_component;
145 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 0,
146 &renderer_swap_component))
147 return;
148
149 UMA_HISTOGRAM_SCROLL_LATENCY_LONG_2(
150 "Event.Latency." + scroll_name + "." + input_modality +
151 ".HandledToRendererSwap2_" + thread_name,
152 rendering_scheduled_component, renderer_swap_component);
153
154 LatencyInfo::LatencyComponent browser_received_swap_component;
155 if (!latency.FindLatency(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, 0,
156 &browser_received_swap_component))
157 return;
158
159 UMA_HISTOGRAM_SCROLL_LATENCY_SHORT_2(
160 "Event.Latency." + scroll_name + "." + input_modality +
161 ".RendererSwapToBrowserNotified2",
162 renderer_swap_component, browser_received_swap_component);
163
164 UMA_HISTOGRAM_SCROLL_LATENCY_LONG_2(
165 "Event.Latency." + scroll_name + "." + input_modality +
166 ".BrowserNotifiedToBeforeGpuSwap2",
167 browser_received_swap_component, gpu_swap_begin_component);
168
169 UMA_HISTOGRAM_SCROLL_LATENCY_SHORT_2(
170 "Event.Latency." + scroll_name + "." + input_modality + ".GpuSwap2",
171 gpu_swap_begin_component, gpu_swap_end_component);
172 }
173
174 // TODO(mfomitchev): Move the method up. It's here temporarily for ease of
175 // review.
176 void LatencyTracker::OnGpuSwapBuffersCompleted(const LatencyInfo& latency) {
177 LatencyInfo::LatencyComponent gpu_swap_end_component;
178 if (!latency.FindLatency(
179 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0,
180 &gpu_swap_end_component)) {
181 return;
182 }
183
184 LatencyInfo::LatencyComponent gpu_swap_begin_component;
185 if (!latency.FindLatency(ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0,
186 &gpu_swap_begin_component)) {
187 return;
188 }
189
190 LatencyInfo::LatencyComponent tab_switch_component;
191 if (latency.FindLatency(ui::TAB_SHOW_COMPONENT, &tab_switch_component)) {
192 base::TimeDelta delta =
193 gpu_swap_end_component.event_time - tab_switch_component.event_time;
194 for (size_t i = 0; i < tab_switch_component.event_count; i++) {
195 UMA_HISTOGRAM_TIMES("MPArch.RWH_TabSwitchPaintDuration", delta);
196 }
197 }
198
199 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
200 nullptr)) {
201 return;
202 }
203
204 ui::SourceEventType source_event_type = latency.source_event_type();
205 if (source_event_type == ui::SourceEventType::WHEEL ||
206 source_event_type == ui::SourceEventType::TOUCH) {
207 ComputeTouchAndWheelScrollLatencyHistograms(
208 gpu_swap_begin_component, gpu_swap_end_component, latency);
209 }
210
211 // Compute the old scroll update latency metrics. They are exclusively
212 // calculated for touch scrolls, and will be deprecated on M56.
213 // (https://crbug.com/649754)
214 LatencyInfo::LatencyComponent mouse_wheel_scroll_update_component;
215 if (!latency.FindLatency(
216 ui::INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL, 0,
217 &mouse_wheel_scroll_update_component)) {
218 ComputeScrollLatencyHistograms(gpu_swap_begin_component,
219 gpu_swap_end_component, latency);
220 }
221 }
222
223 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698