Accumulate network statistics based on deltas.

Network stats are now read out of the kernel in one sweep, instead of
reading per-UID.  We now accumulate the delta traffic between each
stats snapshot using the well-tested SamplingCounter pattern.

Since Wi-Fi and mobile traffic have different costs, track each
separately.  Avoids counting misc interfaces like loopback and
ethernet under total.

Bug: 5543387
Change-Id: I642004dc530113c27ef79f2abbae51d8af30117f
This commit is contained in:
Jeff Sharkey
2013-06-04 12:29:00 -07:00
parent 34bff87b32
commit 7a1c3fce47
6 changed files with 365 additions and 286 deletions

View File

@@ -50,12 +50,14 @@ import android.os.INetworkManagementService;
import android.os.Process;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.Log;
import android.util.Slog;
import android.util.SparseBooleanArray;
import com.android.internal.app.IBatteryStats;
import com.android.internal.net.NetworkStatsFactory;
import com.android.internal.util.Preconditions;
import com.android.server.NativeDaemonConnector.Command;
@@ -343,6 +345,14 @@ public class NetworkManagementService extends INetworkManagementService.Stub
SystemProperties.set(PROP_QTAGUID_ENABLED, mBandwidthControlEnabled ? "1" : "0");
if (mBandwidthControlEnabled) {
try {
IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"))
.noteNetworkStatsEnabled();
} catch (RemoteException e) {
}
}
// push any existing quota or UID rules
synchronized (mQuotaLock) {
int size = mActiveQuotas.size();