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

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

Issue 1828293002: Rewrite Java histograms API implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | base/android/record_histogram.cc » ('j') | base/android/record_histogram.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 0ceddcd3ace2a255fce60b8687af2973fa9338ee..66c1ef0e4d920ce55c95fc272afb61d1b9cee685 100644
--- a/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
+++ b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
@@ -7,6 +7,9 @@ package org.chromium.base.metrics;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.JNINamespace;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
@@ -19,6 +22,8 @@ import java.util.concurrent.TimeUnit;
@JNINamespace("base::android")
public class RecordHistogram {
private static boolean sIsDisabledForTests = false;
+ private static Map<String, Long> sCache =
+ Collections.synchronizedMap(new HashMap<String, Long>());
/**
* Tests may not have native initialized, so they may need to disable metrics.
@@ -28,6 +33,11 @@ public class RecordHistogram {
sIsDisabledForTests = true;
}
+ private static long getCachedHistogramKey(String name) {
nyquist 2016/04/01 21:37:14 Could you add a short comment about what returning
Alexei Svitkine (slow) 2016/04/04 15:08:09 Done.
+ Long key = sCache.get(name);
+ return (key != null ? key : 0);
nyquist 2016/04/01 21:37:14 Nit: I personally think it reads better to use ==
Alexei Svitkine (slow) 2016/04/04 15:08:09 Done.
+ }
+
/**
* Records a sample in a boolean UMA histogram of the given name. Boolean histogram has two
* buckets, corresponding to success (true) and failure (false). This is the Java equivalent of
@@ -37,7 +47,9 @@ public class RecordHistogram {
*/
public static void recordBooleanHistogram(String name, boolean sample) {
if (sIsDisabledForTests) return;
- nativeRecordBooleanHistogram(name, System.identityHashCode(name), sample);
+ long key = getCachedHistogramKey(name);
+ long result = nativeRecordBooleanHistogram(name, key, sample);
+ if (result != key) sCache.put(name, result);
}
/**
@@ -51,7 +63,9 @@ public class RecordHistogram {
*/
public static void recordEnumeratedHistogram(String name, int sample, int boundary) {
if (sIsDisabledForTests) return;
- nativeRecordEnumeratedHistogram(name, System.identityHashCode(name), sample, boundary);
+ long key = getCachedHistogramKey(name);
+ long result = nativeRecordEnumeratedHistogram(name, key, sample, boundary);
+ if (result != key) sCache.put(name, result);
}
/**
@@ -96,8 +110,9 @@ public class RecordHistogram {
public static void recordCustomCountHistogram(
String name, int sample, int min, int max, int numBuckets) {
if (sIsDisabledForTests) return;
- nativeRecordCustomCountHistogram(
- name, System.identityHashCode(name), sample, min, max, numBuckets);
+ long key = getCachedHistogramKey(name);
+ long result = nativeRecordCustomCountHistogram(name, key, sample, min, max, numBuckets);
+ if (result != key) sCache.put(name, result);
}
/**
@@ -112,8 +127,9 @@ public class RecordHistogram {
public static void recordLinearCountHistogram(
String name, int sample, int min, int max, int numBuckets) {
if (sIsDisabledForTests) return;
- nativeRecordLinearCountHistogram(
- name, System.identityHashCode(name), sample, min, max, numBuckets);
+ long key = getCachedHistogramKey(name);
+ long result = nativeRecordLinearCountHistogram(name, key, sample, min, max, numBuckets);
+ if (result != key) sCache.put(name, result);
}
/**
@@ -124,7 +140,9 @@ public class RecordHistogram {
*/
public static void recordPercentageHistogram(String name, int sample) {
if (sIsDisabledForTests) return;
- nativeRecordEnumeratedHistogram(name, System.identityHashCode(name), sample, 101);
+ long key = getCachedHistogramKey(name);
+ long result = nativeRecordEnumeratedHistogram(name, key, sample, 101);
+ if (result != key) sCache.put(name, result);
}
/**
@@ -135,7 +153,9 @@ public class RecordHistogram {
*/
public static void recordSparseSlowlyHistogram(String name, int sample) {
if (sIsDisabledForTests) return;
- nativeRecordSparseHistogram(name, System.identityHashCode(name), sample);
+ long key = getCachedHistogramKey(name);
+ long result = nativeRecordSparseHistogram(name, key, sample);
+ if (result != key) sCache.put(name, result);
}
/**
@@ -201,12 +221,14 @@ public class RecordHistogram {
private static void recordCustomTimesHistogramMilliseconds(
String name, long duration, long min, long max, int numBuckets) {
if (sIsDisabledForTests) return;
+ long key = getCachedHistogramKey(name);
// Note: Duration, min and max are clamped to int here because that's what's expected by
// the native histograms API. Callers of these functions still pass longs because that's
// the types returned by TimeUnit and System.currentTimeMillis() APIs, from which these
// values come.
- nativeRecordCustomTimesHistogramMilliseconds(name, System.identityHashCode(name),
- clampToInt(duration), clampToInt(min), clampToInt(max), numBuckets);
+ long result = nativeRecordCustomTimesHistogramMilliseconds(
+ name, key, clampToInt(duration), clampToInt(min), clampToInt(max), numBuckets);
+ if (result != key) sCache.put(name, result);
}
/**
@@ -227,17 +249,17 @@ public class RecordHistogram {
nativeInitialize();
}
- private static native void nativeRecordCustomTimesHistogramMilliseconds(
- String name, int key, int duration, int min, int max, int numBuckets);
+ private static native long nativeRecordCustomTimesHistogramMilliseconds(
+ String name, long key, int duration, int min, int max, int numBuckets);
- private static native void nativeRecordBooleanHistogram(String name, int key, boolean sample);
- private static native void nativeRecordEnumeratedHistogram(
- String name, int key, int sample, int boundary);
- private static native void nativeRecordCustomCountHistogram(
- String name, int key, int sample, int min, int max, int numBuckets);
- private static native void nativeRecordLinearCountHistogram(
- String name, int key, int sample, int min, int max, int numBuckets);
- private static native void nativeRecordSparseHistogram(String name, int key, int sample);
+ private static native long nativeRecordBooleanHistogram(String name, long key, boolean sample);
+ private static native long nativeRecordEnumeratedHistogram(
+ String name, long key, int sample, int boundary);
+ private static native long nativeRecordCustomCountHistogram(
+ String name, long key, int sample, int min, int max, int numBuckets);
+ private static native long nativeRecordLinearCountHistogram(
+ String name, long key, int sample, int min, int max, int numBuckets);
+ private static native long nativeRecordSparseHistogram(String name, long key, int sample);
private static native int nativeGetHistogramValueCountForTesting(String name, int sample);
private static native void nativeInitialize();
« no previous file with comments | « no previous file | base/android/record_histogram.cc » ('j') | base/android/record_histogram.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698