mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-17 07:37:51 +01:00

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}
93 lines
2.7 KiB
Java
93 lines
2.7 KiB
Java
/*
|
|
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
package org.webrtc;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
// Java-side of androidmetrics_jni.cc.
|
|
//
|
|
// Rtc histograms can be queried through the API, getAndReset().
|
|
// The returned map holds the name of a histogram and its samples.
|
|
//
|
|
// Example of |map| with one histogram:
|
|
// |name|: "WebRTC.Video.InputFramesPerSecond"
|
|
// |min|: 1
|
|
// |max|: 100
|
|
// |bucketCount|: 50
|
|
// |samples|: [30]:1
|
|
//
|
|
// Most histograms are not updated frequently (e.g. most video metrics are an
|
|
// average over the call and recorded when a stream is removed).
|
|
// The metrics can for example be retrieved when a peer connection is closed.
|
|
|
|
public class Metrics {
|
|
private static final String TAG = "Metrics";
|
|
|
|
static {
|
|
System.loadLibrary("jingle_peerconnection_so");
|
|
}
|
|
public final Map<String, HistogramInfo> map =
|
|
new HashMap<String, HistogramInfo>(); // <name, HistogramInfo>
|
|
|
|
/**
|
|
* Class holding histogram information.
|
|
*/
|
|
public static class HistogramInfo {
|
|
public final int min;
|
|
public final int max;
|
|
public final int bucketCount;
|
|
public final Map<Integer, Integer> samples =
|
|
new HashMap<Integer, Integer>(); // <value, # of events>
|
|
|
|
public HistogramInfo(int min, int max, int bucketCount) {
|
|
this.min = min;
|
|
this.max = max;
|
|
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);
|
|
}
|
|
|
|
// Enables gathering of metrics (which can be fetched with getAndReset()).
|
|
// Must be called before PeerConnectionFactory is created.
|
|
public static void enable() {
|
|
enableNative();
|
|
}
|
|
|
|
// Gets and clears native histograms.
|
|
public static Metrics getAndReset() {
|
|
return getAndResetNative();
|
|
}
|
|
|
|
// 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();
|
|
}
|