OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/events/event.h" | 5 #include "ui/events/event.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #if defined(USE_X11) | 9 #if defined(USE_X11) |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 34 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
35 #elif defined(USE_OZONE) | 35 #elif defined(USE_OZONE) |
36 #include "ui/events/ozone/layout/keyboard_layout_engine.h" // nogncheck | 36 #include "ui/events/ozone/layout/keyboard_layout_engine.h" // nogncheck |
37 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" // nogncheck | 37 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" // nogncheck |
38 #endif | 38 #endif |
39 | 39 |
40 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
41 #include "ui/events/keycodes/platform_key_map_win.h" | 41 #include "ui/events/keycodes/platform_key_map_win.h" |
42 #endif | 42 #endif |
43 | 43 |
| 44 // Support a collection of histograms, perhaps one for each entry in an |
| 45 // enumeration. This macro manages a block of pointers, adding to a specific |
| 46 // one by its index. |
| 47 // |
| 48 // A typical instantiation looks something like this: |
| 49 // STATIC_HISTOGRAM_POINTER_GROUP( |
| 50 // GetHistogramNameForIndex(histogram_index), |
| 51 // histogram_index, MAXIMUM_HISTOGRAM_INDEX, Add(some_delta), |
| 52 // base::Histogram::FactoryGet( |
| 53 // GetHistogramNameForType(histogram_index), |
| 54 // MINIMUM_SAMPLE, MAXIMUM_SAMPLE, BUCKET_COUNT, |
| 55 // base::HistogramBase::kUmaTargetedHistogramFlag)); |
| 56 // |
| 57 // Though it seems inefficient to generate the name twice, the first |
| 58 // instance will be used only for DCHECK builds and the second will |
| 59 // execute only during the first access to the given index, after which |
| 60 // the pointer is cached and the name never needed again. |
| 61 // |
| 62 // This is defined in this way so that it can be moved unchanged into |
| 63 // base/metrics/histogram_macros.h if it is useful in other files. |
| 64 #define STATIC_HISTOGRAM_POINTER_GROUP(constant_histogram_name, index, \ |
| 65 constant_maximum, \ |
| 66 histogram_add_method_invocation, \ |
| 67 histogram_factory_get_invocation) \ |
| 68 do { \ |
| 69 static base::subtle::AtomicWord atomic_histograms[constant_maximum]; \ |
| 70 DCHECK_LE(0, index); \ |
| 71 DCHECK_LT(index, constant_maximum); \ |
| 72 HISTOGRAM_POINTER_USE(&atomic_histograms[index], constant_histogram_name, \ |
| 73 histogram_add_method_invocation, \ |
| 74 histogram_factory_get_invocation); \ |
| 75 } while (0) |
| 76 |
44 namespace { | 77 namespace { |
45 | 78 |
46 std::string EventTypeName(ui::EventType type) { | 79 std::string EventTypeName(ui::EventType type) { |
47 #define RETURN_IF_TYPE(t) if (type == ui::t) return #t | 80 #define RETURN_IF_TYPE(t) if (type == ui::t) return #t |
48 #define CASE_TYPE(t) case ui::t: return #t | 81 #define CASE_TYPE(t) case ui::t: return #t |
49 switch (type) { | 82 switch (type) { |
50 CASE_TYPE(ET_UNKNOWN); | 83 CASE_TYPE(ET_UNKNOWN); |
51 CASE_TYPE(ET_MOUSE_PRESSED); | 84 CASE_TYPE(ET_MOUSE_PRESSED); |
52 CASE_TYPE(ET_MOUSE_DRAGGED); | 85 CASE_TYPE(ET_MOUSE_DRAGGED); |
53 CASE_TYPE(ET_MOUSE_RELEASED); | 86 CASE_TYPE(ET_MOUSE_RELEASED); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 phase_(EP_PREDISPATCH), | 338 phase_(EP_PREDISPATCH), |
306 result_(ER_UNHANDLED), | 339 result_(ER_UNHANDLED), |
307 source_device_id_(ED_UNKNOWN_DEVICE) { | 340 source_device_id_(ED_UNKNOWN_DEVICE) { |
308 base::TimeDelta delta = EventTimeForNow() - time_stamp_; | 341 base::TimeDelta delta = EventTimeForNow() - time_stamp_; |
309 if (type_ < ET_LAST) | 342 if (type_ < ET_LAST) |
310 name_ = EventTypeName(type_); | 343 name_ = EventTypeName(type_); |
311 base::HistogramBase::Sample delta_sample = | 344 base::HistogramBase::Sample delta_sample = |
312 static_cast<base::HistogramBase::Sample>(delta.InMicroseconds()); | 345 static_cast<base::HistogramBase::Sample>(delta.InMicroseconds()); |
313 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser", delta_sample, 1, 1000000, | 346 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser", delta_sample, 1, 1000000, |
314 100); | 347 100); |
315 std::string name_for_event = | 348 |
316 base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()); | 349 // Though it seems inefficient to generate the string twice, the first |
317 base::HistogramBase* counter_for_type = | 350 // instance will be used only for DCHECK builds and the second won't be |
| 351 // executed at all if the histogram was previously accessed here. |
| 352 STATIC_HISTOGRAM_POINTER_GROUP( |
| 353 base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()), |
| 354 type_, ET_LAST, Add(delta_sample), |
318 base::Histogram::FactoryGet( | 355 base::Histogram::FactoryGet( |
319 name_for_event, | 356 base::StringPrintf("Event.Latency.Browser.%s", name_.c_str()), |
320 1, | 357 1, 1000000, 100, |
321 1000000, | 358 base::HistogramBase::kUmaTargetedHistogramFlag)); |
322 100, | |
323 base::HistogramBase::kUmaTargetedHistogramFlag); | |
324 counter_for_type->Add(delta_sample); | |
325 | 359 |
326 #if defined(USE_X11) | 360 #if defined(USE_X11) |
327 if (native_event->type == GenericEvent) { | 361 if (native_event->type == GenericEvent) { |
328 XIDeviceEvent* xiev = | 362 XIDeviceEvent* xiev = |
329 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 363 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
330 source_device_id_ = xiev->sourceid; | 364 source_device_id_ = xiev->sourceid; |
331 } | 365 } |
332 #endif | 366 #endif |
333 #if defined(USE_OZONE) | 367 #if defined(USE_OZONE) |
334 source_device_id_ = | 368 source_device_id_ = |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 gfx::PointF(x, y), | 1201 gfx::PointF(x, y), |
1168 time_stamp, | 1202 time_stamp, |
1169 flags | EF_FROM_TOUCH), | 1203 flags | EF_FROM_TOUCH), |
1170 details_(details) { | 1204 details_(details) { |
1171 } | 1205 } |
1172 | 1206 |
1173 GestureEvent::~GestureEvent() { | 1207 GestureEvent::~GestureEvent() { |
1174 } | 1208 } |
1175 | 1209 |
1176 } // namespace ui | 1210 } // namespace ui |
OLD | NEW |