IP connectivity metrics: ConnectStats additions
This patch:
- adds a counter to ConnectStats for counting the number of successful
connect() calls done in blocking mode. This allows to compute error
rates for connect() in blocking mode.
- add printing of ConnectStats when dumping NetdEventListenerService
and/or IpConnectivityMetrics service.
Test: $ runtest frameworks-net, + manual tests verifying logged events.
Bug: 34901696
Change-Id: I889e8ccd12681b0511be487e9d2ee44290a2d7d7
This commit is contained in:
@@ -43,6 +43,8 @@ public class ConnectStats {
|
||||
private final int mMaxLatencyRecords;
|
||||
/** Total count of successful connects. */
|
||||
private int mConnectCount = 0;
|
||||
/** Total count of successful connects done in blocking mode. */
|
||||
private int mConnectBlockingCount = 0;
|
||||
/** Total count of successful connects with IPv6 socket address. */
|
||||
private int mIpv6ConnectCount = 0;
|
||||
|
||||
@@ -54,6 +56,7 @@ public class ConnectStats {
|
||||
public ConnectStatistics toProto() {
|
||||
ConnectStatistics stats = new ConnectStatistics();
|
||||
stats.connectCount = mConnectCount;
|
||||
stats.connectBlockingCount = mConnectBlockingCount;
|
||||
stats.ipv6AddrCount = mIpv6ConnectCount;
|
||||
stats.latenciesMs = mLatencies.toArray();
|
||||
stats.errnosCounters = toPairArrays(mErrnos);
|
||||
@@ -62,16 +65,21 @@ public class ConnectStats {
|
||||
|
||||
public void addEvent(int errno, int latencyMs, String ipAddr) {
|
||||
if (isSuccess(errno)) {
|
||||
countConnect(ipAddr);
|
||||
countConnect(errno, ipAddr);
|
||||
countLatency(errno, latencyMs);
|
||||
} else {
|
||||
countError(errno);
|
||||
}
|
||||
}
|
||||
|
||||
private void countConnect(String ipAddr) {
|
||||
private void countConnect(int errno, String ipAddr) {
|
||||
mConnectCount++;
|
||||
if (isIPv6(ipAddr)) mIpv6ConnectCount++;
|
||||
if (!isNonBlocking(errno)) {
|
||||
mConnectBlockingCount++;
|
||||
}
|
||||
if (isIPv6(ipAddr)) {
|
||||
mIpv6ConnectCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void countLatency(int errno, int ms) {
|
||||
@@ -120,4 +128,18 @@ public class ConnectStats {
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("ConnectStats(")
|
||||
.append(String.format("%d success, ", mConnectCount))
|
||||
.append(String.format("%d blocking, ", mConnectBlockingCount))
|
||||
.append(String.format("%d IPv6 dst", mIpv6ConnectCount));
|
||||
for (int i = 0; i < mErrnos.size(); i++) {
|
||||
String errno = OsConstants.errnoName(mErrnos.keyAt(i));
|
||||
int count = mErrnos.valueAt(i);
|
||||
builder.append(String.format(", %s: %d", errno, count));
|
||||
}
|
||||
return builder.append(")").toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,12 +201,18 @@ final public class IpConnectivityMetrics extends SystemService {
|
||||
for (IpConnectivityEvent ev : IpConnectivityEventBuilder.toProto(events)) {
|
||||
pw.print(ev.toString());
|
||||
}
|
||||
if (mNetdListener != null) {
|
||||
mNetdListener.listAsProtos(pw);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (ConnectivityMetricsEvent ev : events) {
|
||||
pw.println(ev.toString());
|
||||
}
|
||||
if (mNetdListener != null) {
|
||||
mNetdListener.list(pw);
|
||||
}
|
||||
}
|
||||
|
||||
private void cmdStats(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
|
||||
@@ -204,10 +204,15 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
|
||||
// TODO: migrate DnsEventBatch to IpConnectivityLogClass.DNSLatencies
|
||||
}
|
||||
|
||||
private IpConnectivityEvent flushConnectStats() {
|
||||
private IpConnectivityEvent connectStatsProto() {
|
||||
// TODO: add transport information
|
||||
IpConnectivityEvent ev = new IpConnectivityEvent();
|
||||
ev.setConnectStatistics(mConnectStats.toProto());
|
||||
// TODO: add transport information
|
||||
return ev;
|
||||
}
|
||||
|
||||
private IpConnectivityEvent flushConnectStats() {
|
||||
IpConnectivityEvent ev = connectStatsProto();
|
||||
mConnectStats = makeConnectStats();
|
||||
return ev;
|
||||
}
|
||||
@@ -216,11 +221,19 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
|
||||
IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
|
||||
pw.println(TAG + ":");
|
||||
pw.increaseIndent();
|
||||
list(pw);
|
||||
pw.decreaseIndent();
|
||||
}
|
||||
|
||||
public synchronized void list(PrintWriter pw) {
|
||||
for (DnsEventBatch batch : mEventBatches.values()) {
|
||||
pw.println(batch.toString());
|
||||
}
|
||||
// TODO: also dump ConnectStats
|
||||
pw.decreaseIndent();
|
||||
pw.println(mConnectStats.toString());
|
||||
}
|
||||
|
||||
public synchronized void listAsProtos(PrintWriter pw) {
|
||||
pw.println(connectStatsProto().toString());
|
||||
}
|
||||
|
||||
private ConnectStats makeConnectStats() {
|
||||
|
||||
@@ -219,7 +219,7 @@ public class NetdEventListenerServiceTest extends TestCase {
|
||||
"time_ms: 0",
|
||||
"transports: 0",
|
||||
"connect_statistics <",
|
||||
" connect_blocking_count: 0",
|
||||
" connect_blocking_count: 7",
|
||||
" connect_count: 12",
|
||||
" errnos_counters <",
|
||||
" key: 1",
|
||||
|
||||
Reference in New Issue
Block a user