OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 <iostream> | |
6 | |
7 #include "base/hash.h" | |
8 #include "base/logging.h" | |
9 #include "device/bluetooth/bluetooth_uuid.h" | |
10 | |
11 int main(int argc, char** argv) { | |
12 if (argc <= 1) { | |
13 std::cout << "Generates hash values given UUIDs using the same method\n" | |
14 << "as in bluetooth_metrics.cc.\n" | |
15 << "\n" | |
16 << "Output is formatted for including into histograms.xml.\n" | |
17 << "Note that tools/metrics/histograms/pretty_print.py will\n" | |
18 << "sort enum entries for you.\n" | |
19 << "\n" | |
20 << "Usage: " << argv[0] << " <uuid> [uuid2 ...]\n" | |
21 << " The UUIDs may be short UUIDs, and will be made\n" | |
22 << " canonical before being hashed.\n" | |
23 << "\n" | |
24 << "Example: " << argv[0] << " FEFF FEFE\n" | |
25 << " <int value=\"62669585\" " | |
26 "label=\"0000feff-0000-1000-8000-00805f9b34fb\"/>\n" | |
27 << " <int value=\"643543662\" " | |
28 "label=\"0000fefe-0000-1000-8000-00805f9b34fb\"/>\n"; | |
29 return 1; | |
30 } | |
31 | |
32 for (int i = 1; i < argc; i++) { | |
33 std::string input_string(argv[i]); | |
34 device::BluetoothUUID uuid(input_string); | |
35 std::string uuid_canonical_string = uuid.canonical_value(); | |
36 uint32_t hash = base::SuperFastHash(uuid_canonical_string.data(), | |
37 uuid_canonical_string.size()); | |
38 | |
39 // Strip off the sign bit because UMA doesn't support negative values, | |
40 // but takes a signed int as input. | |
41 hash &= 0x7fffffff; | |
42 | |
43 std::cout << " <int value=\"" << hash << "\" label=\"" | |
44 << uuid_canonical_string << "\"/>\n"; | |
45 } | |
46 return 0; | |
47 } | |
OLD | NEW |