Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1993)

Unified Diff: base/android/java/src/org/chromium/base/metrics/RecordHistogram.java

Issue 794273004: Add a Java API for UMA histograms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase over the cronet proguard config fix. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
diff --git a/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
new file mode 100644
index 0000000000000000000000000000000000000000..8295a850c0aabaf1b0cd60bd80faf565c70b081e
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
@@ -0,0 +1,62 @@
+// 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.
+
+package org.chromium.base.metrics;
+
+import org.chromium.base.JNINamespace;
+import org.chromium.base.VisibleForTesting;
+
+/**
+ * Java API for recording UMA histograms. As opposed to macros used in native code, these calls are
+ * not caching the histogram pointer; also, the JNI calls are relatively costly - avoid calling
+ * these methods in performance-critical code.
+ */
+@JNINamespace("base::android")
+public class RecordHistogram {
+ /**
+ * Records a sample in a boolean UMA histogram of the given name. Boolean histogram has two
+ * buckets, corresponding to success (true) and failure (false).
+ * @param name name of the histogram
+ * @param sample sample to be recorded, either true or false
+ */
+ public static void recordBooleanHistogram(String name, boolean sample) {
+ nativeRecordBooleanHistogram(name, sample);
+ }
+
+ /**
+ * Records a sample in an enumerated histogram of the given name and boundary. Note that
+ * |boundary| identifies the histogram - it should be the same at every invocation.
+ * @param name name of the histogram
+ * @param sample sample to be recorded, at least 0 and at most |boundary| - 1
+ * @param boundary upper bound for legal sample values - all sample values has to be strictly
+ * lower than |boundary|
+ */
+ public static void recordEnumeratedHistogram(String name, int sample, int boundary) {
+ nativeRecordEnumeratedHistogram(name, sample, boundary);
+ }
+
+ /**
+ * Returns the number of samples recorded in the given bucket of the given histogram.
+ * @param name name of the histogram to look up
+ * @param sample the bucket containing this sample value will be looked up
+ */
+ @VisibleForTesting
+ public static int getHistogramValueCountForTesting(String name, int sample) {
+ return nativeGetHistogramValueCountForTesting(name, sample);
+ }
+
+ /**
+ * Initializes the metrics system.
+ */
+ public static void initialize() {
+ nativeInitialize();
+ }
+
+ private static native void nativeRecordBooleanHistogram(String name, boolean sample);
+ private static native void nativeRecordEnumeratedHistogram(
+ String name, int sample, int boundary);
+
+ private static native int nativeGetHistogramValueCountForTesting(String name, int sample);
+ private static native void nativeInitialize();
+}

Powered by Google App Engine
This is Rietveld 408576698