forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatency_tracker.cc
544 lines (479 loc) · 23.4 KB
/
latency_tracker.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/latency/latency_tracker.h"
#include <algorithm>
#include <cstdint>
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_piece_forward.h"
#include "base/time/time.h"
#include "services/metrics/public/cpp/ukm_entry_builder.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "ui/latency/jank_tracker_for_experiments_buildflags.h"
#include "ui/latency/janky_duration_tracker.h"
// Impose some restrictions for tests etc, but also be lenient since some of the
// data come from untrusted sources.
#define DCHECK_AND_RETURN_ON_FAIL(x) \
DCHECK(x); \
if (!(x)) \
return;
// Event latency that is mostly under 5 seconds. We should only use 100 buckets
// when needed.
#define UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS(name, latency) \
UMA_HISTOGRAM_CUSTOM_COUNTS(name, latency.InMicroseconds(), 1, \
base::Seconds(5).InMicroseconds(), 100);
#define UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS_GROUP( \
suffix, scroll_type, input_modality, latency) \
STATIC_HISTOGRAM_POINTER_GROUP( \
GetHistogramName(suffix, scroll_type, input_modality), \
GetHistogramIndex(scroll_type, input_modality), kMaxHistogramIndex, \
Add(latency.InMicroseconds()), \
base::Histogram::FactoryGet( \
GetHistogramName(suffix, scroll_type, input_modality), 1, \
base::Seconds(5).InMicroseconds(), 100, \
base::HistogramBase::kUmaTargetedHistogramFlag));
// Event latency that is mostly under 100ms. We should only use 100 buckets
// when needed. This drops reports on clients with low-resolution clocks.
#define UMA_HISTOGRAM_INPUT_LATENCY_CUSTOM_MICROSECONDS(name, latency) \
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES( \
name, latency, base::Microseconds(1), base::Milliseconds(100), 100);
// Deprecated, use UMA_HISTOGRAM_INPUT_LATENCY_CUSTOM_MICROSECONDS instead.
// Event latency that is mostly under 1 second. We should only use 100 buckets
// when needed.
#define UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS(name, \
latency) \
UMA_HISTOGRAM_CUSTOM_COUNTS(name, latency.InMicroseconds(), 1, \
base::Seconds(1).InMicroseconds(), 100);
// Event latency that is mostly under 1 second. We should only use 100 buckets
// when needed. This drops reports on clients with low-resolution clocks.
#define UMA_HISTOGRAM_INPUT_LATENCY_CUSTOM_1_SECOND_MAX_MICROSECONDS(name, \
latency) \
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES( \
name, latency, base::Microseconds(1), base::Seconds(1), 100);
// Long touch/wheel scroll latency component that is mostly under 200ms.
#define UMA_HISTOGRAM_SCROLL_LATENCY_LONG_2(name, latency) \
UMA_HISTOGRAM_CUSTOM_COUNTS(name, latency.InMicroseconds(), \
base::Milliseconds(1).InMicroseconds(), \
base::Milliseconds(200).InMicroseconds(), 50);
#define UMA_HISTOGRAM_SCROLL_LATENCY_LONG_2_GROUP(suffix, scroll_type, \
input_modality, latency) \
STATIC_HISTOGRAM_POINTER_GROUP( \
GetHistogramName(suffix, scroll_type, input_modality), \
GetHistogramIndex(scroll_type, input_modality), kMaxHistogramIndex, \
Add(latency.InMicroseconds()), \
base::Histogram::FactoryGet( \
GetHistogramName(suffix, scroll_type, input_modality), \
base::Milliseconds(1).InMicroseconds(), \
base::Milliseconds(200).InMicroseconds(), 50, \
base::HistogramBase::kUmaTargetedHistogramFlag));
// Short touch/wheel scroll latency component that is mostly under 50ms.
#define UMA_HISTOGRAM_SCROLL_LATENCY_SHORT_2_GROUP(suffix, scroll_type, \
input_modality, latency) \
STATIC_HISTOGRAM_POINTER_GROUP( \
GetHistogramName(suffix, scroll_type, input_modality), \
GetHistogramIndex(scroll_type, input_modality), kMaxHistogramIndex, \
Add(latency.InMicroseconds()), \
base::Histogram::FactoryGet( \
GetHistogramName(suffix, scroll_type, input_modality), 1, \
base::Milliseconds(50).InMicroseconds(), 50, \
base::HistogramBase::kUmaTargetedHistogramFlag));
namespace ui {
namespace {
base::TimeDelta ComputeLatency(base::TimeTicks start, base::TimeTicks end) {
DCHECK(!start.is_null());
DCHECK(!end.is_null());
base::TimeDelta latency = end - start;
if (latency.is_negative()) {
return base::Milliseconds(0);
}
return latency;
}
bool IsInertialScroll(const LatencyInfo& latency) {
return latency.source_event_type() == ui::SourceEventType::INERTIAL;
}
enum Jank : int {
kNonJanky = 0,
kJanky,
};
void EmitScrollUpdateTime(base::TimeDelta dur, bool janky) {
int count = dur.InMilliseconds();
if (count <= 0) {
// Histograms aren't allowed to add zero counts, this could happen
// especially in tests when the clock hasn't advanced enough for a
// microsecond to have passed.
return;
}
static auto* histogram = base::BooleanHistogram::FactoryGet(
"Event.Jank.ScrollUpdate.TotalJankyAndNonJankyDuration2",
base::HistogramBase::kUmaTargetedHistogramFlag);
histogram->AddCount(janky ? kJanky : kNonJanky, count);
#if BUILDFLAG(JANK_TRACKER_FOR_EXPERIMENTS)
AdvanceJankyDurationForBenchmarking(janky, count);
#endif
}
} // namespace
// static
base::StringPiece LatencyTracker::ToString(ScrollInputModality modality) {
switch (modality) {
case ScrollInputModality::kWheel:
return "Wheel";
case ScrollInputModality::kTouch:
return "Touch";
case ScrollInputModality::kScrollbar:
return "Scrollbar";
}
}
// static
base::StringPiece LatencyTracker::ToString(ScrollType type) {
switch (type) {
case ScrollType::kBegin:
return "ScrollBegin";
case ScrollType::kUpdate:
return "ScrollUpdate";
case ScrollType::kInertial:
return "ScrollInertial";
}
}
// static
int LatencyTracker::GetHistogramIndex(ScrollType scroll_type,
ScrollInputModality input_modality) {
return static_cast<int>(scroll_type) +
(static_cast<int>(ScrollType::kLastValue) + 1) *
static_cast<int>(input_modality);
}
// static
std::string LatencyTracker::GetHistogramName(
base::StringPiece suffix,
ScrollType scroll_type,
ScrollInputModality input_modality) {
return base::StrCat({"Event.Latency.", ToString(scroll_type), ".",
ToString(input_modality), ".", suffix});
}
// static
LatencyTracker::ScrollInputModality LatencyTracker::ToScrollInputModality(
ui::SourceEventType type) {
switch (type) {
case ui::SourceEventType::WHEEL:
return ScrollInputModality::kWheel;
case ui::SourceEventType::TOUCH:
case ui::SourceEventType::INERTIAL:
return ScrollInputModality::kTouch;
case ui::SourceEventType::SCROLLBAR:
return ScrollInputModality::kScrollbar;
default:
NOTREACHED();
}
return ScrollInputModality::kLastValue;
}
LatencyTracker::LatencyTracker() = default;
LatencyTracker::~LatencyTracker() = default;
void LatencyTracker::OnGpuSwapBuffersCompleted(
std::vector<ui::LatencyInfo> latency_info,
bool top_controls_visible_height_changed) {
// ReportJankyFrame has to process latency infos in increasing trace_id
// order, so it can compare the current frame to previous one. Therefore, the
// vector is sorted here before passing it down the call chain.
std::sort(latency_info.begin(), latency_info.end(),
[](const LatencyInfo& x, const LatencyInfo& y) {
return x.trace_id() < y.trace_id();
});
for (const auto& latency : latency_info) {
base::TimeTicks gpu_swap_end_timestamp;
if (!latency.FindLatency(INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT,
&gpu_swap_end_timestamp)) {
continue;
}
base::TimeTicks gpu_swap_begin_timestamp;
bool found_component = latency.FindLatency(
ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, &gpu_swap_begin_timestamp);
DCHECK_AND_RETURN_ON_FAIL(found_component);
if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
nullptr)) {
continue;
}
ui::SourceEventType source_event_type = latency.source_event_type();
if (source_event_type == ui::SourceEventType::WHEEL ||
source_event_type == ui::SourceEventType::MOUSE ||
source_event_type == ui::SourceEventType::TOUCH ||
source_event_type == ui::SourceEventType::INERTIAL ||
source_event_type == ui::SourceEventType::KEY_PRESS ||
source_event_type == ui::SourceEventType::TOUCHPAD ||
source_event_type == ui::SourceEventType::SCROLLBAR) {
ComputeEndToEndLatencyHistograms(gpu_swap_begin_timestamp,
gpu_swap_end_timestamp, latency,
top_controls_visible_height_changed);
}
}
}
void LatencyTracker::ReportUkmScrollLatency(
const InputMetricEvent& metric_event,
base::TimeTicks start_timestamp,
base::TimeTicks time_to_scroll_update_swap_begin_timestamp,
base::TimeTicks time_to_handled_timestamp,
bool is_main_thread,
const ukm::SourceId ukm_source_id) {
DCHECK(!start_timestamp.is_null());
DCHECK(!time_to_scroll_update_swap_begin_timestamp.is_null());
DCHECK(!time_to_handled_timestamp.is_null());
ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get();
if (ukm_source_id == ukm::kInvalidSourceId || !ukm_recorder)
return;
std::string event_name = "";
switch (metric_event) {
case InputMetricEvent::SCROLL_BEGIN_TOUCH:
event_name = "Event.ScrollBegin.Touch";
break;
case InputMetricEvent::SCROLL_UPDATE_TOUCH:
event_name = "Event.ScrollUpdate.Touch";
break;
case InputMetricEvent::SCROLL_BEGIN_WHEEL:
event_name = "Event.ScrollBegin.Wheel";
break;
case InputMetricEvent::SCROLL_UPDATE_WHEEL:
event_name = "Event.ScrollUpdate.Wheel";
break;
}
ukm::UkmEntryBuilder builder(ukm_source_id, event_name.c_str());
builder.SetMetric(
"TimeToScrollUpdateSwapBegin",
std::max(static_cast<int64_t>(0),
(time_to_scroll_update_swap_begin_timestamp - start_timestamp)
.InMicroseconds()));
builder.SetMetric(
"TimeToHandled",
std::max(static_cast<int64_t>(0),
(time_to_handled_timestamp - start_timestamp).InMicroseconds()));
builder.SetMetric("IsMainThread", is_main_thread);
builder.Record(ukm_recorder);
}
// Checking whether the update event |tested_frames| length (measured in frames)
// is janky compared to another |basis_frames| (either previous or next). Update
// is deemed janky when it's half of a frame longer than a neighbouring update.
//
// A small number is added to 0.5 in order to make sure that the comparison does
// not filter out ratios that are precisely 0.5, which can fall a little above
// or below exact value due to inherent inaccuracy of operations with
// floating-point numbers. Value 1e-9 have been chosen as follows: the ratio has
// less than nanosecond precision in numerator and VSync interval in
// denominator. Assuming refresh rate more than 1 FPS (and therefore VSync
// interval less than a second), this ratio should increase with increments more
// than minimal value in numerator (1ns) divided by maximum value in
// denominator, giving 1e-9.
static bool IsJankyComparison(double tested_frames, double basis_frames) {
return tested_frames > basis_frames + 0.5 + 1e-9;
}
void LatencyTracker::ReportJankyFrame(base::TimeTicks original_timestamp,
base::TimeTicks gpu_swap_end_timestamp,
const ui::LatencyInfo& latency,
bool first_frame) {
DCHECK(!original_timestamp.is_null());
DCHECK(!gpu_swap_end_timestamp.is_null());
base::TimeDelta dur = gpu_swap_end_timestamp - original_timestamp;
if (first_frame) {
if (jank_state_.total_update_events_ > 0) {
// If we have some data from previous scroll, report it to UMA.
UMA_HISTOGRAM_MEDIUM_TIMES("Event.Latency.ScrollUpdate.TotalDuration",
jank_state_.total_update_duration_);
UMA_HISTOGRAM_MEDIUM_TIMES("Event.Latency.ScrollUpdate.JankyDuration",
jank_state_.janky_update_duration_);
UMA_HISTOGRAM_COUNTS_10000("Event.Latency.ScrollUpdate.TotalEvents",
jank_state_.total_update_events_);
UMA_HISTOGRAM_COUNTS_10000("Event.Latency.ScrollUpdate.JankyEvents",
jank_state_.janky_update_events_);
if (!jank_state_.total_update_duration_.is_zero()) {
UMA_HISTOGRAM_PERCENTAGE(
"Event.Latency.ScrollUpdate.JankyDurationPercentage",
static_cast<int>(100 * (jank_state_.janky_update_duration_ /
jank_state_.total_update_duration_)));
}
}
jank_state_ = JankTrackerState{};
}
jank_state_.total_update_events_++;
jank_state_.total_update_duration_ += dur;
// When processing first frame in a scroll, we do not have any other frames to
// compare it to, and thus no way to detect the jank.
if (!first_frame) {
// TODO(185884172): Investigate using proper vsync interval.
// Assuming 60fps, each frame is rendered in (1/60) of a second.
// To see how many of those intervals fit into the real frame timing,
// we divide it on 1/60 which is the same thing as multiplying by 60.
double frames_taken = dur.InSecondsF() * 60;
double prev_frames_taken = jank_state_.prev_duration_.InSecondsF() * 60;
// For each GestureScroll update, we would like to report whether it was
// janky. However, in order to do that, we need to compare it both to the
// previous as well as to the next event. This condition means that no jank
// was reported for the previous frame (as compared to the one before that),
// so we need to compare it to the current one and report whether it's
// janky:
if (!jank_state_.prev_scroll_update_reported_) {
// The information about previous GestureScrollUpdate was not reported:
// check whether it's janky by comparing to the current frame and report.
bool janky = false;
if (IsJankyComparison(prev_frames_taken, frames_taken)) {
janky = true;
jank_state_.janky_update_events_++;
jank_state_.janky_update_duration_ += jank_state_.prev_duration_;
}
UMA_HISTOGRAM_BOOLEAN("Event.Latency.ScrollJank", janky);
EmitScrollUpdateTime(jank_state_.prev_duration_, janky);
}
// The current GestureScrollUpdate is janky compared to the previous one.
if (IsJankyComparison(frames_taken, prev_frames_taken)) {
UMA_HISTOGRAM_BOOLEAN("Event.Latency.ScrollJank", true);
EmitScrollUpdateTime(dur, true);
jank_state_.janky_update_events_++;
jank_state_.janky_update_duration_ += dur;
// Since we have reported the current event as janky, there is no need to
// report anything about it on the next iteration, as we would like to
// report every GestureScrollUpdate only once.
jank_state_.prev_scroll_update_reported_ = true;
} else {
// We do not have enough information to report whether the current event
// is janky, and need to compare it to the next one before reporting
// anything about it.
jank_state_.prev_scroll_update_reported_ = false;
}
}
jank_state_.prev_duration_ = dur;
}
void LatencyTracker::ComputeEndToEndLatencyHistograms(
base::TimeTicks gpu_swap_begin_timestamp,
base::TimeTicks gpu_swap_end_timestamp,
const ui::LatencyInfo& latency,
bool top_controls_visible_height_changed) {
DCHECK_AND_RETURN_ON_FAIL(!latency.coalesced());
base::TimeTicks original_timestamp;
if (latency.FindLatency(
ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT,
&original_timestamp)) {
ReportJankyFrame(original_timestamp, gpu_swap_end_timestamp, latency, true);
ScrollInputModality input_modality =
ToScrollInputModality(latency.source_event_type());
// For inertial scrolling we don't separate the first event from the rest of
// them.
ScrollType scroll_type =
IsInertialScroll(latency) ? ScrollType::kInertial : ScrollType::kBegin;
// This UMA metric tracks the performance of overall scrolling as a high
// level metric.
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS(
"Event.Latency.ScrollBegin.TimeToScrollUpdateSwapBegin2",
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
// This UMA metric tracks the time between the final frame swap for the
// first scroll event in a sequence and the original timestamp of that
// scroll event's underlying touch/wheel event.
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS_GROUP(
"TimeToScrollUpdateSwapBegin4", scroll_type, input_modality,
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
// Report the latency metric separately for the scrolls that caused the
// top-controls to scroll and the ones that didn't.
if (top_controls_visible_height_changed) {
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS_GROUP(
"TimeToScrollUpdateSwapBegin4.TopControlsMoved", scroll_type,
input_modality,
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
} else {
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS_GROUP(
"TimeToScrollUpdateSwapBegin4.NoTopControlsMoved", scroll_type,
input_modality,
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
}
EmitLatencyHistograms(gpu_swap_begin_timestamp, gpu_swap_end_timestamp,
original_timestamp, latency, scroll_type,
input_modality);
} else if (latency.FindLatency(
ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
&original_timestamp)) {
ReportJankyFrame(original_timestamp, gpu_swap_end_timestamp, latency,
false);
ScrollInputModality input_modality =
ToScrollInputModality(latency.source_event_type());
// For inertial scrolling we don't separate the first event from the rest of
// them.
ScrollType scroll_type =
IsInertialScroll(latency) ? ScrollType::kInertial : ScrollType::kUpdate;
// This UMA metric tracks the performance of overall scrolling as a high
// level metric.
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS(
"Event.Latency.ScrollUpdate.TimeToScrollUpdateSwapBegin2",
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
// This UMA metric tracks the time from when the original touch/wheel event
// is created to when the scroll gesture results in final frame swap.
// First scroll events are excluded from this metric.
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS_GROUP(
"TimeToScrollUpdateSwapBegin4", scroll_type, input_modality,
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
// Also report the latency metric separately for the scrolls that caused the
// top-controls to scroll and the ones that didn't.
if (top_controls_visible_height_changed) {
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS_GROUP(
"TimeToScrollUpdateSwapBegin4.TopControlsMoved", scroll_type,
input_modality,
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
} else {
UMA_HISTOGRAM_INPUT_LATENCY_5_SECONDS_MAX_MICROSECONDS_GROUP(
"TimeToScrollUpdateSwapBegin4.NoTopControlsMoved", scroll_type,
input_modality,
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
}
EmitLatencyHistograms(gpu_swap_begin_timestamp, gpu_swap_end_timestamp,
original_timestamp, latency, scroll_type,
input_modality);
} else if (latency.FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
&original_timestamp)) {
if (latency.source_event_type() == SourceEventType::KEY_PRESS) {
UMA_HISTOGRAM_INPUT_LATENCY_HIGH_RESOLUTION_MICROSECONDS(
"Event.Latency.EndToEnd.KeyPress",
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
} else if (latency.source_event_type() == SourceEventType::TOUCHPAD) {
UMA_HISTOGRAM_INPUT_LATENCY_CUSTOM_1_SECOND_MAX_MICROSECONDS(
"Event.Latency.EndToEnd.TouchpadPinch2",
ComputeLatency(original_timestamp, gpu_swap_begin_timestamp));
}
}
}
void LatencyTracker::EmitLatencyHistograms(
base::TimeTicks gpu_swap_begin_timestamp,
base::TimeTicks gpu_swap_end_timestamp,
base::TimeTicks original_timestamp,
const ui::LatencyInfo& latency,
ScrollType scroll_type,
ScrollInputModality input_modality) {
DCHECK(!IsInertialScroll(latency) || scroll_type == ScrollType::kInertial);
// Inertial and scrollbar scrolls are excluded from Ukm metrics.
if (!((input_modality == ScrollInputModality::kTouch &&
!IsInertialScroll(latency)) ||
input_modality == ScrollInputModality::kWheel)) {
return;
}
base::TimeTicks rendering_scheduled_timestamp;
bool rendering_scheduled_on_main = latency.FindLatency(
ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT,
&rendering_scheduled_timestamp);
if (!rendering_scheduled_on_main) {
bool found_component = latency.FindLatency(
ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT,
&rendering_scheduled_timestamp);
DCHECK_AND_RETURN_ON_FAIL(found_component);
}
InputMetricEvent input_metric_event;
if (scroll_type == ScrollType::kBegin) {
input_metric_event = input_modality == ScrollInputModality::kTouch
? InputMetricEvent::SCROLL_BEGIN_TOUCH
: InputMetricEvent::SCROLL_BEGIN_WHEEL;
} else {
DCHECK_EQ(scroll_type, ScrollType::kUpdate);
input_metric_event = input_modality == ScrollInputModality::kTouch
? InputMetricEvent::SCROLL_UPDATE_TOUCH
: InputMetricEvent::SCROLL_UPDATE_WHEEL;
}
ReportUkmScrollLatency(
input_metric_event, original_timestamp, gpu_swap_begin_timestamp,
rendering_scheduled_timestamp, rendering_scheduled_on_main,
latency.ukm_source_id());
}
} // namespace ui