| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_LATENCY_LATENCY_INFO_H_ | 5 #ifndef UI_LATENCY_LATENCY_INFO_H_ |
| 6 #define UI_LATENCY_LATENCY_INFO_H_ | 6 #define UI_LATENCY_LATENCY_INFO_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 WHEEL, | 110 WHEEL, |
| 111 TOUCH, | 111 TOUCH, |
| 112 KEY_PRESS, | 112 KEY_PRESS, |
| 113 OTHER, | 113 OTHER, |
| 114 SOURCE_EVENT_TYPE_LAST = OTHER, | 114 SOURCE_EVENT_TYPE_LAST = OTHER, |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class LatencyInfo { | 117 class LatencyInfo { |
| 118 public: | 118 public: |
| 119 struct LatencyComponent { | 119 struct LatencyComponent { |
| 120 // Nondecreasing number that can be used to determine what events happened | |
| 121 // in the component at the time this struct was sent on to the next | |
| 122 // component. | |
| 123 int64_t sequence_number; | |
| 124 // Average time of events that happened in this component. | 120 // Average time of events that happened in this component. |
| 125 base::TimeTicks event_time; | 121 base::TimeTicks event_time; |
| 126 // Count of events that happened in this component | 122 // Count of events that happened in this component |
| 127 uint32_t event_count; | 123 uint32_t event_count; |
| 128 // Time of the oldest event that happened in this component. | 124 // Time of the oldest event that happened in this component. |
| 129 base::TimeTicks first_event_time; | 125 base::TimeTicks first_event_time; |
| 130 // Time of the most recent event that happened in this component. | 126 // Time of the most recent event that happened in this component. |
| 131 base::TimeTicks last_event_time; | 127 base::TimeTicks last_event_time; |
| 132 }; | 128 }; |
| 133 | 129 |
| 134 enum : size_t { kMaxInputCoordinates = 2 }; | |
| 135 | |
| 136 // Map a Latency Component (with a component-specific int64_t id) to a | 130 // Map a Latency Component (with a component-specific int64_t id) to a |
| 137 // component info. | 131 // component info. |
| 138 using LatencyMap = base::flat_map<std::pair<LatencyComponentType, int64_t>, | 132 using LatencyMap = base::flat_map<std::pair<LatencyComponentType, int64_t>, |
| 139 LatencyComponent>; | 133 LatencyComponent>; |
| 140 | 134 |
| 141 LatencyInfo(); | 135 LatencyInfo(); |
| 142 LatencyInfo(const LatencyInfo& other); | 136 LatencyInfo(const LatencyInfo& other); |
| 143 LatencyInfo(SourceEventType type); | 137 LatencyInfo(SourceEventType type); |
| 144 ~LatencyInfo(); | 138 ~LatencyInfo(); |
| 145 | 139 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 157 const char* referring_msg); | 151 const char* referring_msg); |
| 158 | 152 |
| 159 // Copy LatencyComponents with type |type| from |other| into |this|. | 153 // Copy LatencyComponents with type |type| from |other| into |this|. |
| 160 void CopyLatencyFrom(const LatencyInfo& other, LatencyComponentType type); | 154 void CopyLatencyFrom(const LatencyInfo& other, LatencyComponentType type); |
| 161 | 155 |
| 162 // Add LatencyComponents that are in |other| but not in |this|. | 156 // Add LatencyComponents that are in |other| but not in |this|. |
| 163 void AddNewLatencyFrom(const LatencyInfo& other); | 157 void AddNewLatencyFrom(const LatencyInfo& other); |
| 164 | 158 |
| 165 // Modifies the current sequence number for a component, and adds a new | 159 // Modifies the current sequence number for a component, and adds a new |
| 166 // sequence number with the current timestamp. | 160 // sequence number with the current timestamp. |
| 167 void AddLatencyNumber(LatencyComponentType component, | 161 void AddLatencyNumber(LatencyComponentType component, int64_t id); |
| 168 int64_t id, | |
| 169 int64_t component_sequence_number); | |
| 170 | 162 |
| 171 // Similar to |AddLatencyNumber|, and also appends |trace_name_str| to | 163 // Similar to |AddLatencyNumber|, and also appends |trace_name_str| to |
| 172 // the trace event's name. | 164 // the trace event's name. |
| 173 // This function should only be called when adding a BEGIN component. | 165 // This function should only be called when adding a BEGIN component. |
| 174 void AddLatencyNumberWithTraceName(LatencyComponentType component, | 166 void AddLatencyNumberWithTraceName(LatencyComponentType component, |
| 175 int64_t id, | 167 int64_t id, |
| 176 int64_t component_sequence_number, | |
| 177 const char* trace_name_str); | 168 const char* trace_name_str); |
| 178 | 169 |
| 179 // Modifies the current sequence number and adds a certain number of events | 170 // Modifies the current sequence number and adds a certain number of events |
| 180 // for a specific component. | 171 // for a specific component. |
| 181 void AddLatencyNumberWithTimestamp(LatencyComponentType component, | 172 void AddLatencyNumberWithTimestamp(LatencyComponentType component, |
| 182 int64_t id, | 173 int64_t id, |
| 183 int64_t component_sequence_number, | |
| 184 base::TimeTicks time, | 174 base::TimeTicks time, |
| 185 uint32_t event_count); | 175 uint32_t event_count); |
| 186 | 176 |
| 187 // Returns true if the a component with |type| and |id| is found in | 177 // Returns true if the a component with |type| and |id| is found in |
| 188 // the latency_components and the component is stored to |output| if | 178 // the latency_components and the component is stored to |output| if |
| 189 // |output| is not NULL. Returns false if no such component is found. | 179 // |output| is not NULL. Returns false if no such component is found. |
| 190 bool FindLatency(LatencyComponentType type, | 180 bool FindLatency(LatencyComponentType type, |
| 191 int64_t id, | 181 int64_t id, |
| 192 LatencyComponent* output) const; | 182 LatencyComponent* output) const; |
| 193 | 183 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 220 bool began() const { return began_; } | 210 bool began() const { return began_; } |
| 221 bool terminated() const { return terminated_; } | 211 bool terminated() const { return terminated_; } |
| 222 void set_coalesced() { coalesced_ = true; } | 212 void set_coalesced() { coalesced_ = true; } |
| 223 bool coalesced() const { return coalesced_; } | 213 bool coalesced() const { return coalesced_; } |
| 224 int64_t trace_id() const { return trace_id_; } | 214 int64_t trace_id() const { return trace_id_; } |
| 225 void set_trace_id(int64_t trace_id) { trace_id_ = trace_id; } | 215 void set_trace_id(int64_t trace_id) { trace_id_ = trace_id; } |
| 226 | 216 |
| 227 private: | 217 private: |
| 228 void AddLatencyNumberWithTimestampImpl(LatencyComponentType component, | 218 void AddLatencyNumberWithTimestampImpl(LatencyComponentType component, |
| 229 int64_t id, | 219 int64_t id, |
| 230 int64_t component_sequence_number, | |
| 231 base::TimeTicks time, | 220 base::TimeTicks time, |
| 232 uint32_t event_count, | 221 uint32_t event_count, |
| 233 const char* trace_name_str); | 222 const char* trace_name_str); |
| 234 | 223 |
| 235 // Converts latencyinfo into format that can be dumped into trace buffer. | 224 // Converts latencyinfo into format that can be dumped into trace buffer. |
| 236 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 225 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 237 AsTraceableData(); | 226 AsTraceableData(); |
| 238 | 227 |
| 239 // Shown as part of the name of the trace event for this LatencyInfo. | 228 // Shown as part of the name of the trace event for this LatencyInfo. |
| 240 // String is empty if no tracing is enabled. | 229 // String is empty if no tracing is enabled. |
| 241 std::string trace_name_; | 230 std::string trace_name_; |
| 242 | 231 |
| 243 LatencyMap latency_components_; | 232 LatencyMap latency_components_; |
| 244 | 233 |
| 245 // The unique id for matching the ASYNC_BEGIN/END trace event. | 234 // The unique id for matching the ASYNC_BEGIN/END trace event. -1 until a |
| 235 // begin component has been encountered. |
| 246 int64_t trace_id_; | 236 int64_t trace_id_; |
| 247 // Whether this event has been coalesced into another event. | 237 // Whether this event has been coalesced into another event. |
| 248 bool coalesced_; | 238 bool coalesced_; |
| 249 // Whether a begin component has been added. | 239 // Whether a begin component has been added. |
| 250 bool began_; | 240 bool began_; |
| 251 // Whether a terminal component has been added. | 241 // Whether a terminal component has been added. |
| 252 bool terminated_; | 242 bool terminated_; |
| 253 // Stores the type of the first source event. | 243 // Stores the type of the first source event. |
| 254 SourceEventType source_event_type_; | 244 SourceEventType source_event_type_; |
| 255 // The expected queueing time on the main thread when this event was | 245 // The expected queueing time on the main thread when this event was |
| 256 // dispatched. | 246 // dispatched. |
| 257 base::TimeDelta expected_queueing_time_on_dispatch_; | 247 base::TimeDelta expected_queueing_time_on_dispatch_; |
| 258 | 248 |
| 259 #if !defined(OS_IOS) | 249 #if !defined(OS_IOS) |
| 260 friend struct IPC::ParamTraits<ui::LatencyInfo>; | 250 friend struct IPC::ParamTraits<ui::LatencyInfo>; |
| 261 friend struct mojo::StructTraits<ui::mojom::LatencyInfoDataView, | 251 friend struct mojo::StructTraits<ui::mojom::LatencyInfoDataView, |
| 262 ui::LatencyInfo>; | 252 ui::LatencyInfo>; |
| 263 #endif | 253 #endif |
| 264 }; | 254 }; |
| 265 | 255 |
| 266 // This is declared here for use in gtest-based unit tests, but is defined in | 256 // This is declared here for use in gtest-based unit tests, but is defined in |
| 267 // //ui/latency:test_support target. | 257 // //ui/latency:test_support target. |
| 268 // Without this the default PrintTo template in gtest tries to pass LatencyInfo | 258 // Without this the default PrintTo template in gtest tries to pass LatencyInfo |
| 269 // by value, which leads to an alignment compile error on Windows. | 259 // by value, which leads to an alignment compile error on Windows. |
| 270 void PrintTo(const LatencyInfo& latency, ::std::ostream* os); | 260 void PrintTo(const LatencyInfo& latency, ::std::ostream* os); |
| 271 | 261 |
| 272 } // namespace ui | 262 } // namespace ui |
| 273 | 263 |
| 274 #endif // UI_LATENCY_LATENCY_INFO_H_ | 264 #endif // UI_LATENCY_LATENCY_INFO_H_ |
| OLD | NEW |