Merge "Add some more metrics: IpManager, IpReachabilityMonitor" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f824e58d49
@@ -28,14 +28,17 @@ public class IpConnectivityEvent implements Parcelable {
|
||||
// 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;
|
||||
|
||||
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;
|
||||
@@ -43,6 +46,9 @@ public class IpConnectivityEvent implements Parcelable {
|
||||
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;
|
||||
|
||||
private static ConnectivityMetricsLogger mMetricsLogger = new ConnectivityMetricsLogger();
|
||||
|
||||
|
||||
58
core/java/android/net/metrics/IpManagerEvent.java
Normal file
58
core/java/android/net/metrics/IpManagerEvent.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 IpManagerEvent extends IpConnectivityEvent implements Parcelable {
|
||||
private String mIfName;
|
||||
private long mDurationMs;
|
||||
|
||||
public IpManagerEvent(String ifName, long duration) {
|
||||
mIfName = ifName;
|
||||
mDurationMs = duration;
|
||||
}
|
||||
|
||||
public IpManagerEvent(Parcel in) {
|
||||
mIfName = in.readString();
|
||||
mDurationMs = in.readLong();
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(mIfName);
|
||||
out.writeLong(mDurationMs);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<IpManagerEvent> CREATOR
|
||||
= new Parcelable.Creator<IpManagerEvent>() {
|
||||
public IpManagerEvent createFromParcel(Parcel in) {
|
||||
return new IpManagerEvent(in);
|
||||
}
|
||||
|
||||
public IpManagerEvent[] newArray(int size) {
|
||||
return new IpManagerEvent[size];
|
||||
}
|
||||
};
|
||||
|
||||
public static void logEvent(int eventType, String ifName, long durationMs) {
|
||||
IpConnectivityEvent.logEvent(eventType, new IpManagerEvent(ifName, durationMs));
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 IpReachabilityMonitorLostEvent extends IpConnectivityEvent
|
||||
implements Parcelable {
|
||||
private String mIfName;
|
||||
|
||||
public IpReachabilityMonitorLostEvent(String ifName) {
|
||||
mIfName = ifName;
|
||||
}
|
||||
|
||||
public IpReachabilityMonitorLostEvent(Parcel in) {
|
||||
mIfName = in.readString();
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(mIfName);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<IpReachabilityMonitorLostEvent> CREATOR
|
||||
= new Parcelable.Creator<IpReachabilityMonitorLostEvent>() {
|
||||
public IpReachabilityMonitorLostEvent createFromParcel(Parcel in) {
|
||||
return new IpReachabilityMonitorLostEvent(in);
|
||||
}
|
||||
|
||||
public IpReachabilityMonitorLostEvent[] newArray(int size) {
|
||||
return new IpReachabilityMonitorLostEvent[size];
|
||||
}
|
||||
};
|
||||
|
||||
public static void logEvent(String ifName) {
|
||||
IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_IPRM_REACHABILITY_LOST,
|
||||
new IpReachabilityMonitorLostEvent(ifName));
|
||||
}
|
||||
};
|
||||
@@ -30,10 +30,12 @@ import android.net.ProxyInfo;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.StaticIpConfiguration;
|
||||
import android.net.dhcp.DhcpClient;
|
||||
import android.net.metrics.IpManagerEvent;
|
||||
import android.os.INetworkManagementService;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
@@ -52,6 +54,10 @@ import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static android.net.metrics.IpConnectivityEvent.IPCE_IPMGR_PROVISIONING_OK;
|
||||
import static android.net.metrics.IpConnectivityEvent.IPCE_IPMGR_PROVISIONING_FAIL;
|
||||
import static android.net.metrics.IpConnectivityEvent.IPCE_IPMGR_COMPLETE_LIFECYCLE;
|
||||
|
||||
|
||||
/**
|
||||
* IpManager
|
||||
@@ -264,6 +270,7 @@ public class IpManager extends StateMachine {
|
||||
private ProxyInfo mHttpProxy;
|
||||
private ApfFilter mApfFilter;
|
||||
private boolean mMulticastFiltering;
|
||||
private long mStartTimeMillis;
|
||||
|
||||
/**
|
||||
* Member variables accessed both from within the StateMachine thread
|
||||
@@ -479,6 +486,12 @@ public class IpManager extends StateMachine {
|
||||
}
|
||||
}
|
||||
|
||||
private void recordMetric(final int type) {
|
||||
if (mStartTimeMillis <= 0) { Log.wtf(mTag, "Start time undefined!"); }
|
||||
IpManagerEvent.logEvent(type, mInterfaceName,
|
||||
SystemClock.elapsedRealtime() - mStartTimeMillis);
|
||||
}
|
||||
|
||||
// For now: use WifiStateMachine's historical notion of provisioned.
|
||||
private static boolean isProvisioned(LinkProperties lp) {
|
||||
// For historical reasons, we should connect even if all we have is
|
||||
@@ -554,11 +567,13 @@ public class IpManager extends StateMachine {
|
||||
switch (delta) {
|
||||
case GAINED_PROVISIONING:
|
||||
if (VDBG) { Log.d(mTag, "onProvisioningSuccess()"); }
|
||||
recordMetric(IPCE_IPMGR_PROVISIONING_OK);
|
||||
mCallback.onProvisioningSuccess(newLp);
|
||||
break;
|
||||
|
||||
case LOST_PROVISIONING:
|
||||
if (VDBG) { Log.d(mTag, "onProvisioningFailure()"); }
|
||||
recordMetric(IPCE_IPMGR_PROVISIONING_FAIL);
|
||||
mCallback.onProvisioningFailure(newLp);
|
||||
break;
|
||||
|
||||
@@ -734,6 +749,10 @@ public class IpManager extends StateMachine {
|
||||
}
|
||||
|
||||
resetLinkProperties();
|
||||
if (mStartTimeMillis > 0) {
|
||||
recordMetric(IPCE_IPMGR_COMPLETE_LIFECYCLE);
|
||||
mStartTimeMillis = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -804,11 +823,16 @@ public class IpManager extends StateMachine {
|
||||
class StartedState extends State {
|
||||
@Override
|
||||
public void enter() {
|
||||
mStartTimeMillis = SystemClock.elapsedRealtime();
|
||||
|
||||
mApfFilter = ApfFilter.maybeCreate(mConfiguration.mApfCapabilities, mNetworkInterface,
|
||||
mCallback, mMulticastFiltering);
|
||||
// TODO: investigate the effects of any multicast filtering racing/interfering with the
|
||||
// rest of this IP configuration startup.
|
||||
if (mApfFilter == null) mCallback.setFallbackMulticastFilter(mMulticastFiltering);
|
||||
if (mApfFilter == null) {
|
||||
mCallback.setFallbackMulticastFilter(mMulticastFiltering);
|
||||
}
|
||||
|
||||
// Set privacy extensions.
|
||||
try {
|
||||
mNwService.setInterfaceIpv6PrivacyExtensions(mInterfaceName, true);
|
||||
@@ -839,6 +863,7 @@ public class IpManager extends StateMachine {
|
||||
handleIPv4Success(new DhcpResults(mConfiguration.mStaticIpConfig));
|
||||
} else {
|
||||
if (VDBG) { Log.d(mTag, "onProvisioningFailure()"); }
|
||||
recordMetric(IPCE_IPMGR_PROVISIONING_FAIL);
|
||||
mCallback.onProvisioningFailure(getLinkProperties());
|
||||
transitionTo(mStoppingState);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.net.ProxyInfo;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.metrics.IpReachabilityMonitorMessageEvent;
|
||||
import android.net.metrics.IpReachabilityMonitorProbeEvent;
|
||||
import android.net.metrics.IpReachabilityMonitorLostEvent;
|
||||
import android.net.netlink.NetlinkConstants;
|
||||
import android.net.netlink.NetlinkErrorMessage;
|
||||
import android.net.netlink.NetlinkMessage;
|
||||
@@ -353,6 +354,7 @@ public class IpReachabilityMonitor {
|
||||
}
|
||||
|
||||
if (delta == ProvisioningChange.LOST_PROVISIONING) {
|
||||
IpReachabilityMonitorLostEvent.logEvent(mInterfaceName);
|
||||
final String logMsg = "FAILURE: LOST_PROVISIONING, " + msg;
|
||||
Log.w(TAG, logMsg);
|
||||
if (mCallback != null) {
|
||||
@@ -521,7 +523,7 @@ public class IpReachabilityMonitor {
|
||||
|
||||
final short msgType = neighMsg.getHeader().nlmsg_type;
|
||||
final short nudState = ndMsg.ndm_state;
|
||||
IpReachabilityMonitorMessageEvent.logEvent(maybeGetInterfaceName(mInterfaceIndex),
|
||||
IpReachabilityMonitorMessageEvent.logEvent(mInterfaceName,
|
||||
destination.getHostAddress(), msgType, nudState);
|
||||
final String eventMsg = "NeighborEvent{"
|
||||
+ "elapsedMs=" + whenMs + ", "
|
||||
@@ -553,11 +555,4 @@ public class IpReachabilityMonitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String maybeGetInterfaceName(int index) {
|
||||
if (index == mInterfaceIndex) {
|
||||
return mInterfaceName;
|
||||
}
|
||||
return "ifindex-" + index;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user