NetdEventListener: add rolling log of connect and dns stats
This patch adds a rolling time order logs of basic statistics of
connect and dns, grouped by network id and including:
- average error rate
- average latency
- max latency
- total number of operations
The log is segmented in buckets of 5 minutes, and covers the last 4
hours.
Note that only blocking connect() calls latencies are recorded with the
current netd logging infrastructure.
Example of logs:
05:30:00.000: {netId=100, WIFI, dns avg=92ms max=525ms err=00.0% tot=37, connect avg=0ms max=23ms err=00.0% tot=25}
05:35:00.000: {netId=100, WIFI, dns avg=94ms max=537ms err=05.3% tot=57, connect avg=0ms max=0ms err=00.0% tot=69}
05:40:00.000: {netId=100, WIFI, dns avg=220ms max=350ms err=00.0% tot=4, connect avg=0ms max=0ms err=00.0% tot=2}
05:45:00.000: {netId=100, WIFI, dns avg=112ms max=113ms err=00.0% tot=1, connect avg=0ms max=0ms err=00.0% tot=1}
05:50:00.000: {netId=100, WIFI, dns avg=131ms max=269ms err=00.0% tot=2, connect avg=0ms max=0ms err=00.0% tot=1}
Bug: 65700460
Test: runtest frameworks-net
Change-Id: I54e76d18fbaaa92639fb675f93ea90b7615fd6bf
diff --git a/core/java/android/net/metrics/ConnectStats.java b/core/java/android/net/metrics/ConnectStats.java
index 30b2656..2495cab 100644
--- a/core/java/android/net/metrics/ConnectStats.java
+++ b/core/java/android/net/metrics/ConnectStats.java
@@ -20,6 +20,7 @@
import android.system.OsConstants;
import android.util.IntArray;
import android.util.SparseIntArray;
+
import com.android.internal.util.BitUtils;
import com.android.internal.util.TokenBucket;
@@ -43,6 +44,8 @@
public final TokenBucket mLatencyTb;
/** Maximum number of latency values recorded. */
public final int mMaxLatencyRecords;
+ /** Total count of events */
+ public int eventCount = 0;
/** Total count of successful connects. */
public int connectCount = 0;
/** Total count of successful connects done in blocking mode. */
@@ -57,12 +60,15 @@
mMaxLatencyRecords = maxLatencyRecords;
}
- public void addEvent(int errno, int latencyMs, String ipAddr) {
+ boolean addEvent(int errno, int latencyMs, String ipAddr) {
+ eventCount++;
if (isSuccess(errno)) {
countConnect(errno, ipAddr);
countLatency(errno, latencyMs);
+ return true;
} else {
countError(errno);
+ return false;
}
}
@@ -101,7 +107,7 @@
return (errno == 0) || isNonBlocking(errno);
}
- private static boolean isNonBlocking(int errno) {
+ static boolean isNonBlocking(int errno) {
// On non-blocking TCP sockets, connect() immediately returns EINPROGRESS.
// On non-blocking TCP sockets that are connecting, connect() immediately returns EALREADY.
return (errno == EINPROGRESS) || (errno == EALREADY);
@@ -117,6 +123,7 @@
for (int t : BitUtils.unpackBits(transports)) {
builder.append(NetworkCapabilities.transportNameOf(t)).append(", ");
}
+ builder.append(String.format("%d events, ", eventCount));
builder.append(String.format("%d success, ", connectCount));
builder.append(String.format("%d blocking, ", connectBlockingCount));
builder.append(String.format("%d IPv6 dst", ipv6ConnectCount));