Make UMA stats creation available in the Java interface.
Only has counts stats right now but enumeration stats can easily be added in the future if needed. BUG=webrtc:6313 Review-Url: https://codereview.webrtc.org/2320473002 Cr-Commit-Position: refs/heads/master@{#14146}
This commit is contained in:
@ -30,6 +30,8 @@ import java.util.Map;
|
|||||||
// The metrics can for example be retrieved when a peer connection is closed.
|
// The metrics can for example be retrieved when a peer connection is closed.
|
||||||
|
|
||||||
public class Metrics {
|
public class Metrics {
|
||||||
|
private static final String TAG = "Metrics";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("jingle_peerconnection_so");
|
System.loadLibrary("jingle_peerconnection_so");
|
||||||
}
|
}
|
||||||
@ -57,6 +59,36 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for holding the native pointer of a histogram. Since there is no way to destroy a
|
||||||
|
* histogram, please don't create unnecessary instances of this object. This class is thread safe.
|
||||||
|
*
|
||||||
|
* Usage example:
|
||||||
|
* private static final Histogram someMetricHistogram =
|
||||||
|
* Histogram.createCounts("WebRTC.Video.SomeMetric", 1, 10000, 50);
|
||||||
|
* someMetricHistogram.addSample(someVariable);
|
||||||
|
*/
|
||||||
|
static class Histogram {
|
||||||
|
private final long handle;
|
||||||
|
private final String name; // Only used for logging.
|
||||||
|
|
||||||
|
private Histogram(long handle, String name) {
|
||||||
|
this.handle = handle;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public Histogram createCounts(String name, int min, int max, int bucketCount) {
|
||||||
|
return new Histogram(nativeCreateCounts(name, min, max, bucketCount), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSample(int sample) {
|
||||||
|
nativeAddSample(handle, sample);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native long nativeCreateCounts(String name, int min, int max, int bucketCount);
|
||||||
|
private static native void nativeAddSample(long handle, int sample);
|
||||||
|
}
|
||||||
|
|
||||||
private void add(String name, HistogramInfo info) {
|
private void add(String name, HistogramInfo info) {
|
||||||
map.put(name, info);
|
map.put(name, info);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,12 @@
|
|||||||
#include "webrtc/api/android/jni/classreferenceholder.h"
|
#include "webrtc/api/android/jni/classreferenceholder.h"
|
||||||
#include "webrtc/api/android/jni/jni_helpers.h"
|
#include "webrtc/api/android/jni/jni_helpers.h"
|
||||||
#include "webrtc/api/android/jni/native_handle_impl.h"
|
#include "webrtc/api/android/jni/native_handle_impl.h"
|
||||||
|
#include "webrtc/system_wrappers/include/metrics.h"
|
||||||
#include "webrtc/system_wrappers/include/metrics_default.h"
|
#include "webrtc/system_wrappers/include/metrics_default.h"
|
||||||
|
|
||||||
// Enables collection of native histograms.
|
// Enables collection of native histograms and creating them.
|
||||||
namespace webrtc_jni {
|
namespace webrtc_jni {
|
||||||
|
|
||||||
JOW(void, Metrics_nativeEnable)(JNIEnv* jni, jclass) {
|
JOW(void, Metrics_nativeEnable)(JNIEnv* jni, jclass) {
|
||||||
webrtc::metrics::Enable();
|
webrtc::metrics::Enable();
|
||||||
}
|
}
|
||||||
@ -56,4 +58,18 @@ JOW(jobject, Metrics_nativeGetAndReset)(JNIEnv* jni, jclass) {
|
|||||||
CHECK_EXCEPTION(jni);
|
CHECK_EXCEPTION(jni);
|
||||||
return j_metrics;
|
return j_metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JOW(jlong, Metrics_00024Histogram_nativeCreateCounts)
|
||||||
|
(JNIEnv* jni, jclass, jstring j_name, jint min, jint max, jint buckets) {
|
||||||
|
std::string name = JavaToStdString(jni, j_name);
|
||||||
|
return jlongFromPointer(
|
||||||
|
webrtc::metrics::HistogramFactoryGetCounts(name, min, max, buckets));
|
||||||
|
}
|
||||||
|
|
||||||
|
JOW(void, Metrics_00024Histogram_nativeAddSample)
|
||||||
|
(JNIEnv* jni, jclass, jlong histogram, jint sample) {
|
||||||
|
HistogramAdd(reinterpret_cast<webrtc::metrics::Histogram*>(histogram),
|
||||||
|
sample);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace webrtc_jni
|
} // namespace webrtc_jni
|
||||||
|
|||||||
@ -18,6 +18,10 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace metrics {
|
namespace metrics {
|
||||||
|
|
||||||
|
// This class does not actually exist. It is casted to an implementation defined
|
||||||
|
// pointer inside the functions.
|
||||||
|
class Histogram;
|
||||||
|
|
||||||
struct SampleInfo {
|
struct SampleInfo {
|
||||||
SampleInfo(const std::string& name, int min, int max, size_t bucket_count);
|
SampleInfo(const std::string& name, int min, int max, size_t bucket_count);
|
||||||
~SampleInfo();
|
~SampleInfo();
|
||||||
@ -51,6 +55,9 @@ int NumSamples(const std::string& name);
|
|||||||
// Returns the minimum sample value (or -1 if the histogram has no samples).
|
// Returns the minimum sample value (or -1 if the histogram has no samples).
|
||||||
int MinSample(const std::string& name);
|
int MinSample(const std::string& name);
|
||||||
|
|
||||||
|
// Function for adding a |sample| to a histogram without checkking the name.
|
||||||
|
void HistogramAdd(Histogram* histogram_pointer, int sample);
|
||||||
|
|
||||||
} // namespace metrics
|
} // namespace metrics
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
|
|||||||
@ -244,6 +244,15 @@ void HistogramAdd(Histogram* histogram_pointer,
|
|||||||
ptr->Add(sample);
|
ptr->Add(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fast path. Adds |sample| to cached |histogram_pointer|.
|
||||||
|
void HistogramAdd(Histogram* histogram_pointer, int sample) {
|
||||||
|
if (!histogram_pointer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer);
|
||||||
|
ptr->Add(sample);
|
||||||
|
}
|
||||||
|
|
||||||
SampleInfo::SampleInfo(const std::string& name,
|
SampleInfo::SampleInfo(const std::string& name,
|
||||||
int min,
|
int min,
|
||||||
int max,
|
int max,
|
||||||
|
|||||||
Reference in New Issue
Block a user