2016-05-23 06:49:36 -07:00
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
|
2017-12-12 12:52:54 +01:00
|
|
|
// Java-side of androidmetrics.cc
|
2016-05-23 06:49:36 -07:00
|
|
|
//
|
|
|
|
|
// 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 {
|
2016-09-09 00:11:48 -07:00
|
|
|
private static final String TAG = "Metrics";
|
|
|
|
|
|
2016-05-23 06:49:36 -07:00
|
|
|
public final Map<String, HistogramInfo> map =
|
|
|
|
|
new HashMap<String, HistogramInfo>(); // <name, HistogramInfo>
|
|
|
|
|
|
2017-11-23 16:56:44 +01:00
|
|
|
@CalledByNative
|
|
|
|
|
Metrics() {}
|
|
|
|
|
|
2016-05-23 06:49:36 -07:00
|
|
|
/**
|
|
|
|
|
* 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>
|
|
|
|
|
|
2017-11-23 16:56:44 +01:00
|
|
|
@CalledByNative("HistogramInfo")
|
2016-05-23 06:49:36 -07:00
|
|
|
public HistogramInfo(int min, int max, int bucketCount) {
|
|
|
|
|
this.min = min;
|
|
|
|
|
this.max = max;
|
|
|
|
|
this.bucketCount = bucketCount;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 16:45:18 +01:00
|
|
|
@CalledByNative("HistogramInfo")
|
2016-05-23 06:49:36 -07:00
|
|
|
public void addSample(int value, int numEvents) {
|
|
|
|
|
samples.put(value, numEvents);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 16:45:18 +01:00
|
|
|
@CalledByNative
|
2016-05-23 06:49:36 -07:00
|
|
|
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() {
|
2017-12-20 15:12:10 +01:00
|
|
|
nativeEnable();
|
2016-05-23 06:49:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets and clears native histograms.
|
|
|
|
|
public static Metrics getAndReset() {
|
2017-12-20 15:12:10 +01:00
|
|
|
return nativeGetAndReset();
|
2016-05-23 06:49:36 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
private static native void nativeEnable();
|
|
|
|
|
private static native Metrics nativeGetAndReset();
|
2016-05-23 06:49:36 -07:00
|
|
|
}
|