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