Begin collecting xtables iface counters.

Add method to parse new iface_stat_fmt proc stats, or return null
when kernel support is unavailable. Add test and remove older, unused
parsing code. Create new "xt" recorder to persist the new xtables
counters when available.

Add SSID support to NetworkIdentity to fix policy tests.

Bug: 6422414
Change-Id: I77f70e9acb79a559ab626f3af5c4f3599801ed43
This commit is contained in:
Jeff Sharkey
2012-05-01 16:26:09 -07:00
parent b4e20cdc76
commit cfed18ad5b
4 changed files with 70 additions and 141 deletions

View File

@@ -128,6 +128,9 @@ public class NetworkStatsRecorder {
Map<String, NetworkIdentitySet> ifaceIdent, long currentTimeMillis) {
final HashSet<String> unknownIfaces = Sets.newHashSet();
// skip recording when snapshot missing
if (snapshot == null) return;
// assume first snapshot is bootstrap and don't record
if (mLastSnapshot == null) {
mLastSnapshot = snapshot;

View File

@@ -159,6 +159,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private PendingIntent mPollIntent;
private static final String PREFIX_DEV = "dev";
private static final String PREFIX_XT = "xt";
private static final String PREFIX_UID = "uid";
private static final String PREFIX_UID_TAG = "uid_tag";
@@ -187,6 +188,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
}
public Config getDevConfig();
public Config getXtConfig();
public Config getUidConfig();
public Config getUidTagConfig();
}
@@ -204,6 +206,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
new DropBoxNonMonotonicObserver();
private NetworkStatsRecorder mDevRecorder;
private NetworkStatsRecorder mXtRecorder;
private NetworkStatsRecorder mUidRecorder;
private NetworkStatsRecorder mUidTagRecorder;
@@ -268,6 +271,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// create data recorders along with historical rotators
mDevRecorder = buildRecorder(PREFIX_DEV, mSettings.getDevConfig(), false);
mXtRecorder = buildRecorder(PREFIX_XT, mSettings.getXtConfig(), false);
mUidRecorder = buildRecorder(PREFIX_UID, mSettings.getUidConfig(), false);
mUidTagRecorder = buildRecorder(PREFIX_UID_TAG, mSettings.getUidTagConfig(), true);
@@ -343,10 +347,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// persist any pending stats
mDevRecorder.forcePersistLocked(currentTime);
mXtRecorder.forcePersistLocked(currentTime);
mUidRecorder.forcePersistLocked(currentTime);
mUidTagRecorder.forcePersistLocked(currentTime);
mDevRecorder = null;
mXtRecorder = null;
mUidRecorder = null;
mUidTagRecorder = null;
@@ -772,9 +778,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// snapshot and record current counters; read UID stats first to
// avoid overcounting dev stats.
final NetworkStats uidSnapshot = getNetworkStatsUidDetail();
final NetworkStats devSnapshot = getNetworkStatsSummary();
final NetworkStats xtSnapshot = mNetworkManager.getNetworkStatsSummaryXt();
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
mDevRecorder.recordSnapshotLocked(devSnapshot, mActiveIfaces, currentTime);
mXtRecorder.recordSnapshotLocked(xtSnapshot, mActiveIfaces, currentTime);
mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveIfaces, currentTime);
mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveIfaces, currentTime);
@@ -824,9 +832,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// snapshot and record current counters; read UID stats first to
// avoid overcounting dev stats.
final NetworkStats uidSnapshot = getNetworkStatsUidDetail();
final NetworkStats devSnapshot = getNetworkStatsSummary();
final NetworkStats xtSnapshot = mNetworkManager.getNetworkStatsSummaryXt();
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
mDevRecorder.recordSnapshotLocked(devSnapshot, mActiveIfaces, currentTime);
mXtRecorder.recordSnapshotLocked(xtSnapshot, mActiveIfaces, currentTime);
mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveIfaces, currentTime);
mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveIfaces, currentTime);
@@ -841,11 +851,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// persist any pending data depending on requested flags
if (persistForce) {
mDevRecorder.forcePersistLocked(currentTime);
mXtRecorder.forcePersistLocked(currentTime);
mUidRecorder.forcePersistLocked(currentTime);
mUidTagRecorder.forcePersistLocked(currentTime);
} else {
if (persistNetwork) {
mDevRecorder.maybePersistLocked(currentTime);
mXtRecorder.maybePersistLocked(currentTime);
}
if (persistUid) {
mUidRecorder.maybePersistLocked(currentTime);
@@ -884,7 +896,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// collect mobile sample
template = buildTemplateMobileWildcard();
devTotal = mDevRecorder.getTotalSinceBootLocked(template);
xtTotal = new NetworkStats.Entry();
xtTotal = mXtRecorder.getTotalSinceBootLocked(template);
uidTotal = mUidRecorder.getTotalSinceBootLocked(template);
EventLogTags.writeNetstatsMobileSample(
@@ -896,7 +908,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// collect wifi sample
template = buildTemplateWifiWildcard();
devTotal = mDevRecorder.getTotalSinceBootLocked(template);
xtTotal = new NetworkStats.Entry();
xtTotal = mXtRecorder.getTotalSinceBootLocked(template);
uidTotal = mUidRecorder.getTotalSinceBootLocked(template);
EventLogTags.writeNetstatsWifiSample(
@@ -970,6 +982,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
mDevRecorder.dumpLocked(pw, fullHistory);
pw.decreaseIndent();
pw.println("Xt stats:");
pw.increaseIndent();
mXtRecorder.dumpLocked(pw, fullHistory);
pw.decreaseIndent();
if (includeUid) {
pw.println("UID stats:");
pw.increaseIndent();
@@ -986,10 +1003,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
}
}
private NetworkStats getNetworkStatsSummary() throws RemoteException {
return mNetworkManager.getNetworkStatsSummary();
}
/**
* Return snapshot of current UID statistics, including any
* {@link TrafficStats#UID_TETHERING} and {@link #mUidOperations} values.
@@ -1125,6 +1138,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
getSecureLong(NETSTATS_DEV_DELETE_AGE, 90 * DAY_IN_MILLIS));
}
@Override
public Config getXtConfig() {
return getDevConfig();
}
@Override
public Config getUidConfig() {
return new Config(getSecureLong(NETSTATS_UID_BUCKET_DURATION, 2 * HOUR_IN_MILLIS),