Android: Annotate and generate JNI code for Metrics.java
Bug: webrtc:8278 Change-Id: I54caee1acb483d7554afd6c0958f1929a78d6a56 Reviewed-on: https://webrtc-review.googlesource.com/22720 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20753}
This commit is contained in:
parent
741282aafc
commit
986a79cf3d
@ -353,6 +353,14 @@ rtc_static_library("libjingle_peerconnection_jni") {
|
||||
]
|
||||
}
|
||||
|
||||
generate_jni("generated_metrics_jni") {
|
||||
sources = [
|
||||
"api/org/webrtc/Metrics.java",
|
||||
]
|
||||
jni_package = ""
|
||||
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
||||
}
|
||||
|
||||
rtc_static_library("libjingle_peerconnection_metrics_default_jni") {
|
||||
sources = [
|
||||
"src/jni/androidmetrics_jni.cc",
|
||||
@ -362,6 +370,7 @@ rtc_static_library("libjingle_peerconnection_metrics_default_jni") {
|
||||
|
||||
deps = [
|
||||
":base_jni",
|
||||
":generated_metrics_jni",
|
||||
":peerconnection_jni",
|
||||
"../../pc:peerconnection",
|
||||
"../../system_wrappers",
|
||||
@ -550,6 +559,7 @@ rtc_android_library("libjingle_peerconnection_metrics_default_java") {
|
||||
java_files = [ "api/org/webrtc/Metrics.java" ]
|
||||
|
||||
deps = [
|
||||
":libjingle_peerconnection_java",
|
||||
"../../rtc_base:base_java",
|
||||
]
|
||||
}
|
||||
|
||||
@ -54,11 +54,13 @@ public class Metrics {
|
||||
this.bucketCount = bucketCount;
|
||||
}
|
||||
|
||||
@CalledByNative("HistogramInfo")
|
||||
public void addSample(int value, int numEvents) {
|
||||
samples.put(value, numEvents);
|
||||
}
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private void add(String name, HistogramInfo info) {
|
||||
map.put(name, info);
|
||||
}
|
||||
@ -66,14 +68,26 @@ public class Metrics {
|
||||
// Enables gathering of metrics (which can be fetched with getAndReset()).
|
||||
// Must be called before PeerConnectionFactory is created.
|
||||
public static void enable() {
|
||||
nativeEnable();
|
||||
enableNative();
|
||||
}
|
||||
|
||||
// Gets and clears native histograms.
|
||||
public static Metrics getAndReset() {
|
||||
return nativeGetAndReset();
|
||||
return getAndResetNative();
|
||||
}
|
||||
|
||||
private static native void nativeEnable();
|
||||
private static native Metrics nativeGetAndReset();
|
||||
// TODO(bugs.webrtc.org/8551) Remove.
|
||||
@CalledByNative
|
||||
static Metrics createMetrics() {
|
||||
return new Metrics();
|
||||
}
|
||||
|
||||
// TODO(bugs.webrtc.org/8551) Remove.
|
||||
@CalledByNative
|
||||
static HistogramInfo createHistogramInfo(int min, int max, int bucketCount) {
|
||||
return new HistogramInfo(min, max, bucketCount);
|
||||
}
|
||||
|
||||
private static native void enableNative();
|
||||
private static native Metrics getAndResetNative();
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "sdk/android/generated_metrics_jni/jni/Metrics_jni.h"
|
||||
#include "sdk/android/src/jni/classreferenceholder.h"
|
||||
#include "sdk/android/src/jni/jni_helpers.h"
|
||||
#include "system_wrappers/include/metrics.h"
|
||||
@ -20,40 +21,30 @@
|
||||
namespace webrtc {
|
||||
namespace jni {
|
||||
|
||||
JNI_FUNCTION_DECLARATION(void, Metrics_nativeEnable, JNIEnv* jni, jclass) {
|
||||
JNI_FUNCTION_DECLARATION(void, Metrics_enableNative, JNIEnv* jni, jclass) {
|
||||
metrics::Enable();
|
||||
}
|
||||
|
||||
// Gets and clears native histograms.
|
||||
JNI_FUNCTION_DECLARATION(jobject,
|
||||
Metrics_nativeGetAndReset,
|
||||
Metrics_getAndResetNative,
|
||||
JNIEnv* jni,
|
||||
jclass) {
|
||||
jclass j_metrics_class = jni->FindClass("org/webrtc/Metrics");
|
||||
jmethodID j_add =
|
||||
GetMethodID(jni, j_metrics_class, "add",
|
||||
"(Ljava/lang/String;Lorg/webrtc/Metrics$HistogramInfo;)V");
|
||||
jclass j_info_class = jni->FindClass("org/webrtc/Metrics$HistogramInfo");
|
||||
jmethodID j_add_sample = GetMethodID(jni, j_info_class, "addSample", "(II)V");
|
||||
|
||||
// Create |Metrics|.
|
||||
jobject j_metrics = jni->NewObject(
|
||||
j_metrics_class, GetMethodID(jni, j_metrics_class, "<init>", "()V"));
|
||||
jobject j_metrics = Java_Metrics_createMetrics(jni);
|
||||
|
||||
std::map<std::string, std::unique_ptr<metrics::SampleInfo>> histograms;
|
||||
metrics::GetAndReset(&histograms);
|
||||
for (const auto& kv : histograms) {
|
||||
// Create and add samples to |HistogramInfo|.
|
||||
jobject j_info = jni->NewObject(
|
||||
j_info_class, GetMethodID(jni, j_info_class, "<init>", "(III)V"),
|
||||
kv.second->min, kv.second->max,
|
||||
jobject j_info = Java_Metrics_createHistogramInfo(
|
||||
jni, kv.second->min, kv.second->max,
|
||||
static_cast<int>(kv.second->bucket_count));
|
||||
for (const auto& sample : kv.second->samples) {
|
||||
jni->CallVoidMethod(j_info, j_add_sample, sample.first, sample.second);
|
||||
Java_HistogramInfo_addSample(jni, j_info, sample.first, sample.second);
|
||||
}
|
||||
// Add |HistogramInfo| to |Metrics|.
|
||||
jstring j_name = jni->NewStringUTF(kv.first.c_str());
|
||||
jni->CallVoidMethod(j_metrics, j_add, j_name, j_info);
|
||||
Java_Metrics_add(jni, j_metrics, j_name, j_info);
|
||||
jni->DeleteLocalRef(j_name);
|
||||
jni->DeleteLocalRef(j_info);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user