OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "content/browser/bluetooth/bluetooth_metrics.h" |
| 6 |
| 7 #include <map> |
| 8 #include <set> |
| 9 #include "base/hash.h" |
| 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "content/common/bluetooth/bluetooth_scan_filter.h" |
| 13 #include "device/bluetooth/bluetooth_uuid.h" |
| 14 |
| 15 using device::BluetoothUUID; |
| 16 |
| 17 namespace { |
| 18 // TODO(ortuno): Remove once we have a macro to histogram strings. |
| 19 // http://crbug.com/520284 |
| 20 int HashUUID(const std::string& uuid) { |
| 21 uint32 data = base::SuperFastHash(uuid.data(), uuid.size()); |
| 22 |
| 23 // Strip off the signed bit because UMA doesn't support negative values, |
| 24 // but takes a signed int as input. |
| 25 return static_cast<int>(data & 0x7fffffff); |
| 26 } |
| 27 } // namespace |
| 28 |
| 29 namespace content { |
| 30 |
| 31 // General |
| 32 |
| 33 void RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction function) { |
| 34 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.FunctionCall.Count", |
| 35 static_cast<int>(function), |
| 36 static_cast<int>(UMAWebBluetoothFunction::COUNT)); |
| 37 } |
| 38 |
| 39 // requestDevice() |
| 40 |
| 41 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { |
| 42 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome", |
| 43 static_cast<int>(outcome), |
| 44 static_cast<int>(UMARequestDeviceOutcome::COUNT)); |
| 45 } |
| 46 |
| 47 static void RecordRequestDeviceFilters( |
| 48 const std::vector<content::BluetoothScanFilter>& filters) { |
| 49 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.Filters.Count", |
| 50 filters.size()); |
| 51 for (const content::BluetoothScanFilter& filter : filters) { |
| 52 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.FilterSize", |
| 53 filter.services.size()); |
| 54 for (const BluetoothUUID& service : filter.services) { |
| 55 // TODO(ortuno): Use a macro to histogram strings. |
| 56 // http://crbug.com/520284 |
| 57 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 58 "Bluetooth.Web.RequestDevice.Filters.Services", |
| 59 HashUUID(service.canonical_value())); |
| 60 } |
| 61 } |
| 62 } |
| 63 |
| 64 static void RecordRequestDeviceOptionalServices( |
| 65 const std::vector<BluetoothUUID>& optional_services) { |
| 66 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.OptionalServices.Count", |
| 67 optional_services.size()); |
| 68 for (const BluetoothUUID& service : optional_services) { |
| 69 // TODO(ortuno): Use a macro to histogram strings. |
| 70 // http://crbug.com/520284 |
| 71 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 72 "Bluetooth.Web.RequestDevice.OptionalServices.Services", |
| 73 HashUUID(service.canonical_value())); |
| 74 } |
| 75 } |
| 76 |
| 77 static void RecordUnionOfServices( |
| 78 const std::vector<content::BluetoothScanFilter>& filters, |
| 79 const std::vector<BluetoothUUID>& optional_services) { |
| 80 std::set<BluetoothUUID> union_of_services(optional_services.begin(), |
| 81 optional_services.end()); |
| 82 |
| 83 for (const content::BluetoothScanFilter& filter : filters) |
| 84 union_of_services.insert(filter.services.begin(), filter.services.end()); |
| 85 |
| 86 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", |
| 87 union_of_services.size()); |
| 88 } |
| 89 |
| 90 void RecordRequestDeviceArguments( |
| 91 const std::vector<content::BluetoothScanFilter>& filters, |
| 92 const std::vector<device::BluetoothUUID>& optional_services) { |
| 93 RecordRequestDeviceFilters(filters); |
| 94 RecordRequestDeviceOptionalServices(optional_services); |
| 95 RecordUnionOfServices(filters, optional_services); |
| 96 } |
| 97 |
| 98 // connectGATT |
| 99 |
| 100 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) { |
| 101 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome", |
| 102 static_cast<int>(outcome), |
| 103 static_cast<int>(UMAConnectGATTOutcome::COUNT)); |
| 104 } |
| 105 |
| 106 void RecordConnectGATTTimeSuccess(const base::TimeDelta& duration) { |
| 107 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeSuccess", duration); |
| 108 } |
| 109 |
| 110 void RecordConnectGATTTimeFailed(const base::TimeDelta& duration) { |
| 111 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeFailed", duration); |
| 112 } |
| 113 |
| 114 // getPrimaryService |
| 115 |
| 116 void RecordGetPrimaryServiceService(const BluetoothUUID& service) { |
| 117 // TODO(ortuno): Use a macro to histogram strings. |
| 118 // http://crbug.com/520284 |
| 119 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetPrimaryService.Services", |
| 120 HashUUID(service.canonical_value())); |
| 121 } |
| 122 |
| 123 void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome) { |
| 124 UMA_HISTOGRAM_ENUMERATION( |
| 125 "Bluetooth.Web.GetPrimaryService.Outcome", static_cast<int>(outcome), |
| 126 static_cast<int>(UMAGetPrimaryServiceOutcome::COUNT)); |
| 127 } |
| 128 |
| 129 // read/write characteristic |
| 130 |
| 131 void RecordGATTError(UMAGATTError error) { |
| 132 UMA_HISTOGRAM_ENUMERATION("Bluetooth.GATTErrors", static_cast<int>(error), |
| 133 static_cast<int>(UMAGATTError::MAX_ERROR)); |
| 134 } |
| 135 |
| 136 } // namespace content |
OLD | NEW |