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
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_METRICS_EVENT_METRICS_H_
#define CC_METRICS_EVENT_METRICS_H_
#include <memory>
#include <vector>
#include "base/optional.h"
#include "base/time/time.h"
#include "cc/cc_export.h"
#include "ui/events/types/event_type.h"
#include "ui/events/types/scroll_input_type.h"
namespace cc {
// Data about an event used by CompositorFrameReporter in generating event
// latency metrics.
class CC_EXPORT EventMetrics {
public:
// Whitelisted event types. This list should be in the same order as values of
// EventLatencyEventType enum from enums.xml file.
enum class EventType {
kMousePressed,
kMouseReleased,
kMouseWheel,
// TODO(crbug/1071645): Currently, all ET_KEY_PRESSED events are reported
// under EventLatency.KeyPressed histogram. This includes both key-down and
// key-char events. Consider reporting them separately.
kKeyPressed,
kKeyReleased,
kTouchPressed,
kTouchReleased,
kTouchMoved,
kGestureScrollBegin,
kGestureScrollUpdate,
kGestureScrollEnd,
kGestureDoubleTap,
kGestureLongPress,
kGestureLongTap,
kGestureShowPress,
kGestureTap,
kGestureTapCancel,
kGestureTapDown,
kGestureTapUnconfirmed,
kGestureTwoFingerTap,
kMaxValue = kGestureTwoFingerTap,
};
// Type of scroll events. This list should be in the same order as values of
// EventLatencyScrollInputType enum from enums.xml file.
enum class ScrollType {
kAutoscroll,
kScrollbar,
kTouchscreen,
kWheel,
kMaxValue = kWheel,
};
// Returns a new instance if |type| is a whitelisted event type. Otherwise,
// returns nullptr.
static std::unique_ptr<EventMetrics> Create(
ui::EventType type,
base::TimeTicks time_stamp,
base::Optional<ui::ScrollInputType> scroll_input_type);
EventMetrics(const EventMetrics&);
EventMetrics& operator=(const EventMetrics&);
EventType type() const { return type_; }
// Returns a string representing event type.
const char* GetTypeName() const;
base::TimeTicks time_stamp() const { return time_stamp_; }
const base::Optional<ScrollType>& scroll_type() const { return scroll_type_; }
// Returns a string representing input type for a scroll event. Should only be
// called for scroll events.
const char* GetScrollTypeName() const;
// Used in tests to check expectations on EventMetrics objects.
bool operator==(const EventMetrics& other) const;
private:
EventMetrics(EventType type,
base::TimeTicks time_stamp,
base::Optional<ScrollType> scroll_type);
EventType type_;
base::TimeTicks time_stamp_;
// Only available for scroll events and represents the type of input device
// for the event.
base::Optional<ScrollType> scroll_type_;
};
// Struct storing event metrics from both main and impl threads.
struct CC_EXPORT EventMetricsSet {
EventMetricsSet();
~EventMetricsSet();
EventMetricsSet(std::vector<EventMetrics> main_thread_event_metrics,
std::vector<EventMetrics> impl_thread_event_metrics);
EventMetricsSet(EventMetricsSet&&);
EventMetricsSet& operator=(EventMetricsSet&&);
EventMetricsSet(const EventMetricsSet&) = delete;
EventMetricsSet& operator=(const EventMetricsSet&) = delete;
std::vector<EventMetrics> main_event_metrics;
std::vector<EventMetrics> impl_event_metrics;
};
} // namespace cc
#endif // CC_METRICS_EVENT_METRICS_H_
|