1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <map>
12 #include <memory>
13
14 #include "sdk/android/generated_base_jni/Histogram_jni.h"
15 #include "sdk/android/native_api/jni/java_types.h"
16 #include "sdk/android/src/jni/jni_helpers.h"
17 #include "system_wrappers/include/metrics.h"
18
19 // Enables collection of native histograms and creating them.
20 namespace webrtc {
21 namespace jni {
22
JNI_Histogram_CreateCounts(JNIEnv * jni,const JavaParamRef<jstring> & j_name,jint min,jint max,jint buckets)23 static jlong JNI_Histogram_CreateCounts(JNIEnv* jni,
24 const JavaParamRef<jstring>& j_name,
25 jint min,
26 jint max,
27 jint buckets) {
28 std::string name = JavaToStdString(jni, j_name);
29 return jlongFromPointer(
30 metrics::HistogramFactoryGetCounts(name, min, max, buckets));
31 }
32
JNI_Histogram_CreateEnumeration(JNIEnv * jni,const JavaParamRef<jstring> & j_name,jint max)33 static jlong JNI_Histogram_CreateEnumeration(
34 JNIEnv* jni,
35 const JavaParamRef<jstring>& j_name,
36 jint max) {
37 std::string name = JavaToStdString(jni, j_name);
38 return jlongFromPointer(metrics::HistogramFactoryGetEnumeration(name, max));
39 }
40
JNI_Histogram_AddSample(JNIEnv * jni,jlong histogram,jint sample)41 static void JNI_Histogram_AddSample(JNIEnv* jni,
42 jlong histogram,
43 jint sample) {
44 if (histogram) {
45 HistogramAdd(reinterpret_cast<metrics::Histogram*>(histogram), sample);
46 }
47 }
48
49 } // namespace jni
50 } // namespace webrtc
51