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.
5 #include "content/browser/bluetooth/bluetooth_metrics.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"
15 using device::BluetoothUUID
;
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());
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);
33 void RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction function
) {
34 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.FunctionCall.Count",
35 static_cast<int>(function
),
36 static_cast<int>(UMAWebBluetoothFunction::COUNT
));
41 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome
) {
42 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome",
43 static_cast<int>(outcome
),
44 static_cast<int>(UMARequestDeviceOutcome::COUNT
));
47 static void RecordRequestDeviceFilters(
48 const std::vector
<content::BluetoothScanFilter
>& filters
) {
49 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.Filters.Count",
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()));
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()));
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());
83 for (const content::BluetoothScanFilter
& filter
: filters
)
84 union_of_services
.insert(filter
.services
.begin(), filter
.services
.end());
86 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count",
87 union_of_services
.size());
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
);
100 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome
) {
101 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome",
102 static_cast<int>(outcome
),
103 static_cast<int>(UMAConnectGATTOutcome::COUNT
));
106 void RecordConnectGATTTimeSuccess(const base::TimeDelta
& duration
) {
107 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeSuccess", duration
);
110 void RecordConnectGATTTimeFailed(const base::TimeDelta
& duration
) {
111 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeFailed", duration
);
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()));
123 void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome
) {
124 UMA_HISTOGRAM_ENUMERATION(
125 "Bluetooth.Web.GetPrimaryService.Outcome", static_cast<int>(outcome
),
126 static_cast<int>(UMAGetPrimaryServiceOutcome::COUNT
));
131 void RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome outcome
) {
132 UMA_HISTOGRAM_ENUMERATION(
133 "Bluetooth.Web.GetCharacteristic.Outcome", static_cast<int>(outcome
),
134 static_cast<int>(UMAGetCharacteristicOutcome::COUNT
));
137 void RecordGetCharacteristicCharacteristic(const std::string
& characteristic
) {
138 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetCharacteristic.Characteristic",
139 HashUUID(characteristic
));
144 void RecordGATTOperationOutcome(UMAGATTOperation operation
,
145 UMAGATTOperationOutcome outcome
) {
147 case UMAGATTOperation::CHARACTERISTIC_READ
:
148 RecordCharacteristicReadValueOutcome(outcome
);
150 case UMAGATTOperation::CHARACTERISTIC_WRITE
:
151 RecordCharacteristicWriteValueOutcome(outcome
);
153 case UMAGATTOperation::COUNT
:
160 // Characteristic.readValue
163 void RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome outcome
) {
164 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.Characteristic.ReadValue.Outcome",
165 static_cast<int>(outcome
),
166 static_cast<int>(UMAGATTOperationOutcome::COUNT
));
169 // Characteristic.writeValue
171 void RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome outcome
) {
172 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.Characteristic.WriteValue.Outcome",
173 static_cast<int>(outcome
),
174 static_cast<int>(UMAGATTOperationOutcome::COUNT
));
177 } // namespace content