DO NOT MERGE Netd events: record connect() success/errno

Test: $ runtest frameworks-net pass
Bug: 32198976

(cherry picked from commit 8b06bcdfd2)

Change-Id: I527f98c28b31f490ea999222ef8d0b685a2f24ed
This commit is contained in:
Hugo Benichi
2016-10-31 15:04:37 +09:00
parent 7af83d0e5a
commit e8fe0aaab9

View File

@@ -46,7 +46,7 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
public static final String SERVICE_NAME = "netd_listener"; public static final String SERVICE_NAME = "netd_listener";
private static final String TAG = NetdEventListenerService.class.getSimpleName(); private static final String TAG = NetdEventListenerService.class.getSimpleName();
private static final boolean DBG = true; private static final boolean DBG = false;
private static final boolean VDBG = false; private static final boolean VDBG = false;
// TODO: read this constant from system property // TODO: read this constant from system property
@@ -88,7 +88,7 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
byte[] returnCodes = Arrays.copyOf(mReturnCodes, mEventCount); byte[] returnCodes = Arrays.copyOf(mReturnCodes, mEventCount);
int[] latenciesMs = Arrays.copyOf(mLatenciesMs, mEventCount); int[] latenciesMs = Arrays.copyOf(mLatenciesMs, mEventCount);
mMetricsLog.log(new DnsEvent(mNetId, eventTypes, returnCodes, latenciesMs)); mMetricsLog.log(new DnsEvent(mNetId, eventTypes, returnCodes, latenciesMs));
maybeLog(String.format("Logging %d results for netId %d", mEventCount, mNetId)); maybeLog("Logging %d results for netId %d", mEventCount, mNetId);
mEventCount = 0; mEventCount = 0;
} }
@@ -155,8 +155,7 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
public synchronized void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs, public synchronized void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs,
String hostname, String[] ipAddresses, int ipAddressesCount, int uid) String hostname, String[] ipAddresses, int ipAddressesCount, int uid)
throws RemoteException { throws RemoteException {
maybeVerboseLog(String.format("onDnsEvent(%d, %d, %d, %d)", maybeVerboseLog("onDnsEvent(%d, %d, %d, %dms)", netId, eventType, returnCode, latencyMs);
netId, eventType, returnCode, latencyMs));
DnsEventBatch batch = mEventBatches.get(netId); DnsEventBatch batch = mEventBatches.get(netId);
if (batch == null) { if (batch == null) {
@@ -174,9 +173,9 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
@Override @Override
// Called concurrently by multiple binder threads. // Called concurrently by multiple binder threads.
// This method must not block or perform long-running operations. // This method must not block or perform long-running operations.
public synchronized void onConnectEvent(int netId, int latencyMs, String ipAddr, int port, public synchronized void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port,
int uid) throws RemoteException { int uid) throws RemoteException {
maybeVerboseLog(String.format("onConnectEvent(%d, %d)", netId, latencyMs)); maybeVerboseLog("onConnectEvent(%d, %d, %dms)", netId, error, latencyMs);
if (mNetdEventCallback != null) { if (mNetdEventCallback != null) {
mNetdEventCallback.onConnectEvent(ipAddr, port, System.currentTimeMillis(), uid); mNetdEventCallback.onConnectEvent(ipAddr, port, System.currentTimeMillis(), uid);
@@ -193,11 +192,11 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
pw.decreaseIndent(); pw.decreaseIndent();
} }
private static void maybeLog(String s) { private static void maybeLog(String s, Object... args) {
if (DBG) Log.d(TAG, s); if (DBG) Log.d(TAG, String.format(s, args));
} }
private static void maybeVerboseLog(String s) { private static void maybeVerboseLog(String s, Object... args) {
if (VDBG) Log.d(TAG, s); if (VDBG) Log.d(TAG, String.format(s, args));
} }
} }