Merge "Always splice historical data stats, debug info."
This commit is contained in:
@@ -43,6 +43,9 @@ import com.android.internal.telephony.Phone;
|
|||||||
import com.android.internal.telephony.TelephonyIntents;
|
import com.android.internal.telephony.TelephonyIntents;
|
||||||
import com.android.internal.util.AsyncChannel;
|
import com.android.internal.util.AsyncChannel;
|
||||||
|
|
||||||
|
import java.io.CharArrayWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track the state of mobile data connectivity. This is done by
|
* Track the state of mobile data connectivity. This is done by
|
||||||
* receiving broadcast intents from the Phone process whenever
|
* receiving broadcast intents from the Phone process whenever
|
||||||
@@ -69,6 +72,11 @@ public class MobileDataStateTracker implements NetworkStateTracker {
|
|||||||
private boolean mPrivateDnsRouteSet = false;
|
private boolean mPrivateDnsRouteSet = false;
|
||||||
private boolean mDefaultRouteSet = false;
|
private boolean mDefaultRouteSet = false;
|
||||||
|
|
||||||
|
// NOTE: these are only kept for debugging output; actual values are
|
||||||
|
// maintained in DataConnectionTracker.
|
||||||
|
protected boolean mUserDataEnabled = true;
|
||||||
|
protected boolean mPolicyDataEnabled = true;
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private AsyncChannel mDataConnectionTrackerAc;
|
private AsyncChannel mDataConnectionTrackerAc;
|
||||||
private Messenger mMessenger;
|
private Messenger mMessenger;
|
||||||
@@ -458,6 +466,7 @@ public class MobileDataStateTracker implements NetworkStateTracker {
|
|||||||
final AsyncChannel channel = mDataConnectionTrackerAc;
|
final AsyncChannel channel = mDataConnectionTrackerAc;
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
channel.sendMessage(CMD_SET_USER_DATA_ENABLE, enabled ? ENABLED : DISABLED);
|
channel.sendMessage(CMD_SET_USER_DATA_ENABLE, enabled ? ENABLED : DISABLED);
|
||||||
|
mUserDataEnabled = enabled;
|
||||||
}
|
}
|
||||||
if (VDBG) log("setUserDataEnable: X enabled=" + enabled);
|
if (VDBG) log("setUserDataEnable: X enabled=" + enabled);
|
||||||
}
|
}
|
||||||
@@ -468,6 +477,7 @@ public class MobileDataStateTracker implements NetworkStateTracker {
|
|||||||
final AsyncChannel channel = mDataConnectionTrackerAc;
|
final AsyncChannel channel = mDataConnectionTrackerAc;
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
channel.sendMessage(CMD_SET_POLICY_DATA_ENABLE, enabled ? ENABLED : DISABLED);
|
channel.sendMessage(CMD_SET_POLICY_DATA_ENABLE, enabled ? ENABLED : DISABLED);
|
||||||
|
mPolicyDataEnabled = enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,10 +502,12 @@ public class MobileDataStateTracker implements NetworkStateTracker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer("Mobile data state: ");
|
final CharArrayWriter writer = new CharArrayWriter();
|
||||||
|
final PrintWriter pw = new PrintWriter(writer);
|
||||||
sb.append(mMobileDataState);
|
pw.print("Mobile data state: "); pw.println(mMobileDataState);
|
||||||
return sb.toString();
|
pw.print("Data enabled: user="); pw.print(mUserDataEnabled);
|
||||||
|
pw.print(", policy="); pw.println(mPolicyDataEnabled);
|
||||||
|
return writer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package android.net;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
|
|
||||||
import com.android.internal.util.Objects;
|
import com.android.internal.util.Objects;
|
||||||
@@ -38,6 +39,8 @@ import java.util.HashSet;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class NetworkStats implements Parcelable {
|
public class NetworkStats implements Parcelable {
|
||||||
|
private static final String TAG = "NetworkStats";
|
||||||
|
|
||||||
/** {@link #iface} value when interface details unavailable. */
|
/** {@link #iface} value when interface details unavailable. */
|
||||||
public static final String IFACE_ALL = null;
|
public static final String IFACE_ALL = null;
|
||||||
/** {@link #uid} value when UID details unavailable. */
|
/** {@link #uid} value when UID details unavailable. */
|
||||||
@@ -397,7 +400,10 @@ public class NetworkStats implements Parcelable {
|
|||||||
if (enforceMonotonic
|
if (enforceMonotonic
|
||||||
&& (entry.rxBytes < 0 || entry.rxPackets < 0 || entry.txBytes < 0
|
&& (entry.rxBytes < 0 || entry.rxPackets < 0 || entry.txBytes < 0
|
||||||
|| entry.txPackets < 0 || entry.operations < 0)) {
|
|| entry.txPackets < 0 || entry.operations < 0)) {
|
||||||
throw new IllegalArgumentException("found non-monotonic values");
|
Log.v(TAG, "lhs=" + this);
|
||||||
|
Log.v(TAG, "rhs=" + value);
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"found non-monotonic values at lhs[" + i + "] - rhs[" + j + "]");
|
||||||
}
|
}
|
||||||
if (clampNegative) {
|
if (clampNegative) {
|
||||||
entry.rxBytes = Math.max(0, entry.rxBytes);
|
entry.rxBytes = Math.max(0, entry.rxBytes);
|
||||||
|
|||||||
@@ -482,12 +482,12 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
for (int i = start; i < bucketCount; i++) {
|
for (int i = start; i < bucketCount; i++) {
|
||||||
pw.print(prefix);
|
pw.print(prefix);
|
||||||
pw.print(" bucketStart="); pw.print(bucketStart[i]);
|
pw.print(" bucketStart="); pw.print(bucketStart[i]);
|
||||||
if (activeTime != null) pw.print(" activeTime="); pw.print(activeTime[i]);
|
if (activeTime != null) { pw.print(" activeTime="); pw.print(activeTime[i]); }
|
||||||
if (rxBytes != null) pw.print(" rxBytes="); pw.print(rxBytes[i]);
|
if (rxBytes != null) { pw.print(" rxBytes="); pw.print(rxBytes[i]); }
|
||||||
if (rxPackets != null) pw.print(" rxPackets="); pw.print(rxPackets[i]);
|
if (rxPackets != null) { pw.print(" rxPackets="); pw.print(rxPackets[i]); }
|
||||||
if (txBytes != null) pw.print(" txBytes="); pw.print(txBytes[i]);
|
if (txBytes != null) { pw.print(" txBytes="); pw.print(txBytes[i]); }
|
||||||
if (txPackets != null) pw.print(" txPackets="); pw.print(txPackets[i]);
|
if (txPackets != null) { pw.print(" txPackets="); pw.print(txPackets[i]); }
|
||||||
if (operations != null) pw.print(" operations="); pw.print(operations[i]);
|
if (operations != null) { pw.print(" operations="); pw.print(operations[i]); }
|
||||||
pw.println();
|
pw.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.DUMP;
|
||||||
import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
|
import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
|
||||||
import static android.net.NetworkStats.IFACE_ALL;
|
import static android.net.NetworkStats.IFACE_ALL;
|
||||||
import static android.net.NetworkStats.SET_DEFAULT;
|
import static android.net.NetworkStats.SET_DEFAULT;
|
||||||
@@ -51,10 +52,12 @@ import com.google.android.collect.Sets;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileDescriptor;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -288,7 +291,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
for (INetworkManagementEventObserver obs : mObservers) {
|
for (INetworkManagementEventObserver obs : mObservers) {
|
||||||
try {
|
try {
|
||||||
obs.limitReached(limitName, iface);
|
obs.limitReached(limitName, iface);
|
||||||
Slog.d(TAG, "Observer notified limit reached for " + limitName + " " + iface);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Slog.w(TAG, "Observer notifier failed", ex);
|
Slog.w(TAG, "Observer notifier failed", ex);
|
||||||
}
|
}
|
||||||
@@ -1031,7 +1033,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
|
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
|
||||||
final NetworkStats.Entry entry = new NetworkStats.Entry();
|
final NetworkStats.Entry entry = new NetworkStats.Entry();
|
||||||
|
|
||||||
final HashSet<String> activeIfaces = Sets.newHashSet();
|
|
||||||
final ArrayList<String> values = Lists.newArrayList();
|
final ArrayList<String> values = Lists.newArrayList();
|
||||||
|
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
@@ -1057,7 +1058,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
entry.txBytes = Long.parseLong(values.get(9));
|
entry.txBytes = Long.parseLong(values.get(9));
|
||||||
entry.txPackets = Long.parseLong(values.get(10));
|
entry.txPackets = Long.parseLong(values.get(10));
|
||||||
|
|
||||||
activeIfaces.add(entry.iface);
|
|
||||||
stats.addValues(entry);
|
stats.addValues(entry);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Slog.w(TAG, "problem parsing stats row '" + line + "': " + e);
|
Slog.w(TAG, "problem parsing stats row '" + line + "': " + e);
|
||||||
@@ -1073,14 +1073,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
IoUtils.closeQuietly(reader);
|
IoUtils.closeQuietly(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBG) Slog.d(TAG, "recorded active stats from " + activeIfaces);
|
// splice in historical stats not reflected in mStatsIface
|
||||||
|
|
||||||
// splice in stats from any disabled ifaces
|
|
||||||
if (mBandwidthControlEnabled) {
|
if (mBandwidthControlEnabled) {
|
||||||
final HashSet<String> xtIfaces = Sets.newHashSet(fileListWithoutNull(mStatsXtIface));
|
for (String iface : fileListWithoutNull(mStatsXtIface)) {
|
||||||
xtIfaces.removeAll(activeIfaces);
|
|
||||||
|
|
||||||
for (String iface : xtIfaces) {
|
|
||||||
final File ifacePath = new File(mStatsXtIface, iface);
|
final File ifacePath = new File(mStatsXtIface, iface);
|
||||||
|
|
||||||
entry.iface = iface;
|
entry.iface = iface;
|
||||||
@@ -1092,10 +1087,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes"));
|
entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes"));
|
||||||
entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets"));
|
entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets"));
|
||||||
|
|
||||||
stats.addValues(entry);
|
stats.combineValues(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBG) Slog.d(TAG, "recorded stale stats from " + xtIfaces);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
@@ -1583,4 +1576,26 @@ public class NetworkManagementService extends INetworkManagementService.Stub
|
|||||||
mConnector.monitor();
|
mConnector.monitor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
|
mContext.enforceCallingOrSelfPermission(DUMP, TAG);
|
||||||
|
|
||||||
|
pw.print("Bandwidth control enabled: "); pw.println(mBandwidthControlEnabled);
|
||||||
|
|
||||||
|
synchronized (mQuotaLock) {
|
||||||
|
pw.print("Active quota ifaces: "); pw.println(mActiveQuotaIfaces.toString());
|
||||||
|
pw.print("Active alert ifaces: "); pw.println(mActiveAlertIfaces.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (mUidRejectOnQuota) {
|
||||||
|
pw.print("UID reject on quota ifaces: [");
|
||||||
|
final int size = mUidRejectOnQuota.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
pw.print(mUidRejectOnQuota.keyAt(i));
|
||||||
|
if (i < size - 1) pw.print(",");
|
||||||
|
}
|
||||||
|
pw.println("]");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
@@ -766,9 +767,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
&& totalBytes > policy.limitBytes && policy.lastSnooze < start;
|
&& totalBytes > policy.limitBytes && policy.lastSnooze < start;
|
||||||
final boolean enabled = !overLimit;
|
final boolean enabled = !overLimit;
|
||||||
|
|
||||||
if (LOGD) {
|
|
||||||
Slog.d(TAG, "setting template=" + policy.template + " enabled=" + enabled);
|
|
||||||
}
|
|
||||||
setNetworkTemplateEnabled(policy.template, enabled);
|
setNetworkTemplateEnabled(policy.template, enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -835,9 +833,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
|
|
||||||
// collect all active ifaces that match this template
|
// collect all active ifaces that match this template
|
||||||
ifaceList.clear();
|
ifaceList.clear();
|
||||||
for (NetworkIdentity ident : networks.keySet()) {
|
for (Map.Entry<NetworkIdentity, String> entry : networks.entrySet()) {
|
||||||
|
final NetworkIdentity ident = entry.getKey();
|
||||||
if (policy.template.matches(ident)) {
|
if (policy.template.matches(ident)) {
|
||||||
final String iface = networks.get(ident);
|
final String iface = entry.getValue();
|
||||||
ifaceList.add(iface);
|
ifaceList.add(iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -707,7 +707,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
mLastPersistUidSnapshot, uidSnapshot, true);
|
mLastPersistUidSnapshot, uidSnapshot, true);
|
||||||
if (forcePersist || persistUidDelta.getTotalBytes() > persistThreshold) {
|
if (forcePersist || persistUidDelta.getTotalBytes() > persistThreshold) {
|
||||||
writeUidStatsLocked();
|
writeUidStatsLocked();
|
||||||
mLastPersistNetworkSnapshot = networkSnapshot;
|
mLastPersistUidSnapshot = networkSnapshot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,18 @@ public class NetworkManagementServiceTest extends AndroidTestCase {
|
|||||||
assertStatsEntry(stats, "wlan0", UID_ALL, SET_DEFAULT, TAG_NONE, 1024L, 2048L);
|
assertStatsEntry(stats, "wlan0", UID_ALL, SET_DEFAULT, TAG_NONE, 1024L, 2048L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNetworkStatsCombined() throws Exception {
|
||||||
|
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
|
||||||
|
stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes"));
|
||||||
|
stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets"));
|
||||||
|
stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes"));
|
||||||
|
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
|
||||||
|
|
||||||
|
final NetworkStats stats = mService.getNetworkStatsSummary();
|
||||||
|
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 1507570L + 10L,
|
||||||
|
2205L + 20L, 489339L + 30L, 2237L + 40L);
|
||||||
|
}
|
||||||
|
|
||||||
public void testKernelTags() throws Exception {
|
public void testKernelTags() throws Exception {
|
||||||
assertEquals("0", tagToKernel(0x0));
|
assertEquals("0", tagToKernel(0x0));
|
||||||
assertEquals("214748364800", tagToKernel(0x32));
|
assertEquals("214748364800", tagToKernel(0x32));
|
||||||
|
|||||||
Reference in New Issue
Block a user