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

Side by Side Diff: webrtc/api/android/java/src/org/webrtc/Metrics.java

Issue 2320473002: Make UMA stats creation available in the Java interface. (Closed)
Patch Set: New approach that doesn't involve macros Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 12 matching lines...) Expand all
23 // |min|: 1 23 // |min|: 1
24 // |max|: 100 24 // |max|: 100
25 // |bucketCount|: 50 25 // |bucketCount|: 50
26 // |samples|: [30]:1 26 // |samples|: [30]:1
27 // 27 //
28 // Most histograms are not updated frequently (e.g. most video metrics are an 28 // Most histograms are not updated frequently (e.g. most video metrics are an
29 // average over the call and recorded when a stream is removed). 29 // average over the call and recorded when a stream is removed).
30 // The metrics can for example be retrieved when a peer connection is closed. 30 // The metrics can for example be retrieved when a peer connection is closed.
31 31
32 public class Metrics { 32 public class Metrics {
33 private static final String TAG = "Metrics";
34
33 static { 35 static {
34 System.loadLibrary("jingle_peerconnection_so"); 36 System.loadLibrary("jingle_peerconnection_so");
35 } 37 }
36 public final Map<String, HistogramInfo> map = 38 public final Map<String, HistogramInfo> map =
37 new HashMap<String, HistogramInfo>(); // <name, HistogramInfo> 39 new HashMap<String, HistogramInfo>(); // <name, HistogramInfo>
38 40
39 /** 41 /**
40 * Class holding histogram information. 42 * Class holding histogram information.
41 */ 43 */
42 public static class HistogramInfo { 44 public static class HistogramInfo {
43 public final int min; 45 public final int min;
44 public final int max; 46 public final int max;
45 public final int bucketCount; 47 public final int bucketCount;
46 public final Map<Integer, Integer> samples = 48 public final Map<Integer, Integer> samples =
47 new HashMap<Integer, Integer>(); // <value, # of events> 49 new HashMap<Integer, Integer>(); // <value, # of events>
48 50
49 public HistogramInfo(int min, int max, int bucketCount) { 51 public HistogramInfo(int min, int max, int bucketCount) {
50 this.min = min; 52 this.min = min;
51 this.max = max; 53 this.max = max;
52 this.bucketCount = bucketCount; 54 this.bucketCount = bucketCount;
53 } 55 }
54 56
55 public void addSample(int value, int numEvents) { 57 public void addSample(int value, int numEvents) {
56 samples.put(value, numEvents); 58 samples.put(value, numEvents);
57 } 59 }
58 } 60 }
59 61
62 /**
63 * Class for holding the native pointer of a histogram. Since there is no way to destroy a
64 * histogram, please don't create unnecessary instances of this object. This c lass is thread safe.
65 *
66 * Usage example:
67 * private static final Histogram someMetricHistogram =
68 * Histogram.createCounts("WebRTC.Video.SomeMetric", 1, 10000, 50);
69 * someMetricHistogram.addSampleLogged(someVariable);
70 */
71 static class Histogram {
72 private final long handle;
73 private final String name; // Only used for logging.
74
75 private Histogram(long handle, String name) {
76 this.handle = handle;
77 this.name = name;
78 }
79
80 static public Histogram createCounts(String name, int min, int max, int buck etCount) {
81 return new Histogram(nativeCreateCounts(name, min, max, bucketCount), name );
82 }
83
84 public void addSample(int sample) {
85 nativeAddSample(handle, sample);
86 }
87
88 public void addSampleLogged(int sample) {
89 Logging.d(TAG, "Add sample " + this.name + ": " + sample);
90 addSample(sample);
91 }
92
93 private static native long nativeCreateCounts(String name, int min, int max, int bucketCount);
94 private static native void nativeAddSample(long handle, int sample);
95 }
96
60 private void add(String name, HistogramInfo info) { 97 private void add(String name, HistogramInfo info) {
61 map.put(name, info); 98 map.put(name, info);
62 } 99 }
63 100
64 // Enables gathering of metrics (which can be fetched with getAndReset()). 101 // Enables gathering of metrics (which can be fetched with getAndReset()).
65 // Must be called before PeerConnectionFactory is created. 102 // Must be called before PeerConnectionFactory is created.
66 public static void enable() { 103 public static void enable() {
67 nativeEnable(); 104 nativeEnable();
68 } 105 }
69 106
70 // Gets and clears native histograms. 107 // Gets and clears native histograms.
71 public static Metrics getAndReset() { 108 public static Metrics getAndReset() {
72 return nativeGetAndReset(); 109 return nativeGetAndReset();
73 } 110 }
74 111
75 private static native void nativeEnable(); 112 private static native void nativeEnable();
76 private static native Metrics nativeGetAndReset(); 113 private static native Metrics nativeGetAndReset();
77 } 114 }
OLDNEW
« no previous file with comments | « no previous file | webrtc/api/android/jni/androidmetrics_jni.cc » ('j') | webrtc/api/android/jni/androidmetrics_jni.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698