summaryrefslogtreecommitdiffstats
path: root/chrome_elf/dll_hash
diff options
context:
space:
mode:
authorcsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-03 17:01:41 +0000
committercsharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-03 17:01:41 +0000
commitc80b3502ba5dda8c0fa8f712f585aa1aad45f385 (patch)
treebd4ff65796243c61e215dfb2bb0eedc1602369aa /chrome_elf/dll_hash
parent12cc5113da4e1b49cb7c88d56f7c1599365ee3ce (diff)
downloadchromium_src-c80b3502ba5dda8c0fa8f712f585aa1aad45f385.zip
chromium_src-c80b3502ba5dda8c0fa8f712f585aa1aad45f385.tar.gz
chromium_src-c80b3502ba5dda8c0fa8f712f585aa1aad45f385.tar.bz2
Add UMA stats to record when DLLs are successfully blocked in the Browser.
BUG=345287 Review URL: https://codereview.chromium.org/174013007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_elf/dll_hash')
-rw-r--r--chrome_elf/dll_hash/dll_hash.cc14
-rw-r--r--chrome_elf/dll_hash/dll_hash.h13
-rw-r--r--chrome_elf/dll_hash/dll_hash_main.cc28
3 files changed, 55 insertions, 0 deletions
diff --git a/chrome_elf/dll_hash/dll_hash.cc b/chrome_elf/dll_hash/dll_hash.cc
new file mode 100644
index 0000000..ecd1491
--- /dev/null
+++ b/chrome_elf/dll_hash/dll_hash.cc
@@ -0,0 +1,14 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/hash.h"
+#include "chrome_elf/dll_hash/dll_hash.h"
+
+int DllNameToHash(std::string dll_name) {
+ uint32 data = base::Hash(dll_name);
+
+ // Strip off the signed bit because UMA doesn't support negative values,
+ // but takes a signed int as input.
+ return static_cast<int>(data & 0x7fffffff);
+}
diff --git a/chrome_elf/dll_hash/dll_hash.h b/chrome_elf/dll_hash/dll_hash.h
new file mode 100644
index 0000000..82bec8a
--- /dev/null
+++ b/chrome_elf/dll_hash/dll_hash.h
@@ -0,0 +1,13 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_ELF_DLL_HASH_DLL_HASH_H_
+#define CHROME_ELF_DLL_HASH_DLL_HASH_H_
+
+#include <string>
+
+// Convert a dll name to a hash that can be sent via UMA.
+int DllNameToHash(std::string dll_name);
+
+#endif // CHROME_ELF_DLL_HASH_DLL_HASH_H_
diff --git a/chrome_elf/dll_hash/dll_hash_main.cc b/chrome_elf/dll_hash/dll_hash_main.cc
new file mode 100644
index 0000000..a360263
--- /dev/null
+++ b/chrome_elf/dll_hash/dll_hash_main.cc
@@ -0,0 +1,28 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This is a utility executable used for generating hashes for dll names
+// for inclusion in tools/metrics/histograms/histograms.xml. Every
+// dll name must have a corresponding entry in the enum there.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "chrome_elf/dll_hash/dll_hash.h"
+
+int main(int argc, char** argv) {
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <dll name> <dll name> <...>\n", argv[0]);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Prints hashes for dll names.\n");
+ fprintf(stderr, "Example: %s \"my_dll.dll\" \"user32.dll\"\n", argv[0]);
+ return 1;
+ }
+ for (int i = 1; i < argc; i++) {
+ int hash = DllNameToHash(std::string(argv[i]));
+ printf("<int value=\"%d\" label=\"%s\"/>\n", hash, argv[i]);
+ }
+ return 0;
+}