diff options
| author | Lorenzo Colitti <lorenzo@google.com> | 2016-04-12 23:29:19 +0900 |
|---|---|---|
| committer | Lorenzo Colitti <lorenzo@google.com> | 2016-04-15 16:54:39 +0900 |
| commit | 43724734d76c900fba9a004e28ff0ea4bd9d07ec (patch) | |
| tree | 12400696afd0568336d5963059f257412bcc94fd /core/java | |
| parent | 88bc0bbb13cee43e777fd88c2681d1f033faece5 (diff) | |
Metrics logging for DNS queries.
Bug: 28204408
Change-Id: I05fc9b580aa20d99e8766057e17a38b5eb6267e8
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/net/metrics/DnsEvent.java | 77 | ||||
| -rw-r--r-- | core/java/android/net/metrics/IpConnectivityEvent.java | 50 |
2 files changed, 106 insertions, 21 deletions
diff --git a/core/java/android/net/metrics/DnsEvent.java b/core/java/android/net/metrics/DnsEvent.java new file mode 100644 index 000000000000..200b81645409 --- /dev/null +++ b/core/java/android/net/metrics/DnsEvent.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.metrics; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * {@hide} + */ +public class DnsEvent extends IpConnectivityEvent implements Parcelable { + public final int netId; + + // The event type is currently only 1 or 2, so we store it as a byte. + public final byte[] eventTypes; + // Current getaddrinfo codes go from 1 to EAI_MAX = 15. gethostbyname returns errno, but there + // are fewer than 255 errno values. So we store the result code in a byte as well. + public final byte[] returnCodes; + // The latency is an integer because a) short arrays aren't parcelable and b) a short can only + // store a maximum latency of 32757 or 65535 ms, which is too short for pathologically slow + // queries. + public final int[] latenciesMs; + + private DnsEvent(int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) { + this.netId = netId; + this.eventTypes = eventTypes; + this.returnCodes = returnCodes; + this.latenciesMs = latenciesMs; + } + + private DnsEvent(Parcel in) { + netId = in.readInt(); + eventTypes = in.createByteArray(); + returnCodes = in.createByteArray(); + latenciesMs = in.createIntArray(); + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeInt(netId); + out.writeByteArray(eventTypes); + out.writeByteArray(returnCodes); + out.writeIntArray(latenciesMs); + } + + public static final Parcelable.Creator<DnsEvent> CREATOR = new Parcelable.Creator<DnsEvent>() { + @Override + public DnsEvent createFromParcel(Parcel in) { + return new DnsEvent(in); + } + + @Override + public DnsEvent[] newArray(int size) { + return new DnsEvent[size]; + } + }; + + public static void logEvent( + int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) { + IpConnectivityEvent.logEvent(IPCE_DNS_LOOKUPS, + new DnsEvent(netId, eventTypes, returnCodes, latenciesMs)); + } +} diff --git a/core/java/android/net/metrics/IpConnectivityEvent.java b/core/java/android/net/metrics/IpConnectivityEvent.java index 59c1cfe25be0..f0a3c902a355 100644 --- a/core/java/android/net/metrics/IpConnectivityEvent.java +++ b/core/java/android/net/metrics/IpConnectivityEvent.java @@ -24,31 +24,39 @@ import android.os.Parcelable; * {@hide} */ public class IpConnectivityEvent implements Parcelable { - // IPRM = IpReachabilityMonitor - // DHCP = DhcpClient + public static final String TAG = "IpConnectivityEvent"; + + // IPRM = IpReachabilityMonitor + // DHCP = DhcpClient // NETMON = NetworkMonitorEvent // CONSRV = ConnectivityServiceEvent - // IPMGR = IpManager - public static final String TAG = "IpConnectivityEvent"; - public static final int IPCE_IPRM_BASE = 0*1024; - public static final int IPCE_DHCP_BASE = 1*1024; - public static final int IPCE_NETMON_BASE = 2*1024; - public static final int IPCE_CONSRV_BASE = 3*1024; - public static final int IPCE_IPMGR_BASE = 4*1024; + // IPMGR = IpManager + public static final int IPCE_IPRM_BASE = 0 * 1024; + public static final int IPCE_DHCP_BASE = 1 * 1024; + public static final int IPCE_NETMON_BASE = 2 * 1024; + public static final int IPCE_CONSRV_BASE = 3 * 1024; + public static final int IPCE_IPMGR_BASE = 4 * 1024; + public static final int IPCE_DNS_BASE = 5 * 1024; + + public static final int IPCE_IPRM_PROBE_RESULT = IPCE_IPRM_BASE + 0; + public static final int IPCE_IPRM_MESSAGE_RECEIVED = IPCE_IPRM_BASE + 1; + public static final int IPCE_IPRM_REACHABILITY_LOST = IPCE_IPRM_BASE + 2; + + public static final int IPCE_DHCP_RECV_ERROR = IPCE_DHCP_BASE + 0; + public static final int IPCE_DHCP_PARSE_ERROR = IPCE_DHCP_BASE + 1; + public static final int IPCE_DHCP_TIMEOUT = IPCE_DHCP_BASE + 2; + public static final int IPCE_DHCP_STATE_CHANGE = IPCE_DHCP_BASE + 3; + + public static final int IPCE_NETMON_STATE_CHANGE = IPCE_NETMON_BASE + 0; + public static final int IPCE_NETMON_CHECK_RESULT = IPCE_NETMON_BASE + 1; - public static final int IPCE_IPRM_PROBE_RESULT = IPCE_IPRM_BASE + 0; - public static final int IPCE_IPRM_MESSAGE_RECEIVED = IPCE_IPRM_BASE + 1; - public static final int IPCE_IPRM_REACHABILITY_LOST = IPCE_IPRM_BASE + 2; - public static final int IPCE_DHCP_RECV_ERROR = IPCE_DHCP_BASE + 0; - public static final int IPCE_DHCP_PARSE_ERROR = IPCE_DHCP_BASE + 1; - public static final int IPCE_DHCP_TIMEOUT = IPCE_DHCP_BASE + 2; - public static final int IPCE_DHCP_STATE_CHANGE = IPCE_DHCP_BASE + 3; - public static final int IPCE_NETMON_STATE_CHANGE = IPCE_NETMON_BASE + 0; - public static final int IPCE_NETMON_CHECK_RESULT = IPCE_NETMON_BASE + 1; public static final int IPCE_CONSRV_DEFAULT_NET_CHANGE = IPCE_CONSRV_BASE + 0; - public static final int IPCE_IPMGR_PROVISIONING_OK = IPCE_IPMGR_BASE + 0; - public static final int IPCE_IPMGR_PROVISIONING_FAIL = IPCE_IPMGR_BASE + 1; - public static final int IPCE_IPMGR_COMPLETE_LIFECYCLE = IPCE_IPMGR_BASE + 2; + + public static final int IPCE_IPMGR_PROVISIONING_OK = IPCE_IPMGR_BASE + 0; + public static final int IPCE_IPMGR_PROVISIONING_FAIL = IPCE_IPMGR_BASE + 1; + public static final int IPCE_IPMGR_COMPLETE_LIFECYCLE = IPCE_IPMGR_BASE + 2; + + public static final int IPCE_DNS_LOOKUPS = IPCE_DNS_BASE + 0; private static ConnectivityMetricsLogger mMetricsLogger = new ConnectivityMetricsLogger(); |
