import static android.net.NetworkTemplate.MATCH_WIFI;
import static android.net.NetworkTemplate.buildTemplateMobileAll;
import static android.net.TrafficStats.MB_IN_BYTES;
+import static android.os.Trace.TRACE_TAG_NETWORK;
import static android.provider.Settings.Global.NETPOLICY_OVERRIDE_ENABLED;
import static android.provider.Settings.Global.NETPOLICY_QUOTA_ENABLED;
import static android.provider.Settings.Global.NETPOLICY_QUOTA_FRAC_JOBS;
*/
void updateNotificationsNL() {
if (LOGV) Slog.v(TAG, "updateNotificationsNL()");
+ Trace.traceBegin(TRACE_TAG_NETWORK, "updateNotificationsNL");
// keep track of previously active notifications
final ArraySet<NotificationId> beforeNotifs = new ArraySet<NotificationId>(mActiveNotifs);
cancelNotification(notificationId);
}
}
+
+ Trace.traceEnd(TRACE_TAG_NETWORK);
}
/**
*/
void updateNetworkEnabledNL() {
if (LOGV) Slog.v(TAG, "updateNetworkEnabledNL()");
+ Trace.traceBegin(TRACE_TAG_NETWORK, "updateNetworkEnabledNL");
// TODO: reset any policy-disabled networks when any policy is removed
// completely, which is currently rare case.
}
mStatLogger.logDurationStat(Stats.UPDATE_NETWORK_ENABLED, startTime);
+ Trace.traceEnd(TRACE_TAG_NETWORK);
}
/**
*/
void updateNetworkRulesNL() {
if (LOGV) Slog.v(TAG, "updateNetworkRulesNL()");
+ Trace.traceBegin(TRACE_TAG_NETWORK, "updateNetworkRulesNL");
final NetworkState[] states;
try {
mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget();
mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget();
+
+ Trace.traceEnd(TRACE_TAG_NETWORK);
}
/**
import static android.net.NetworkTemplate.buildTemplateWifiWildcard;
import static android.net.TrafficStats.KB_IN_BYTES;
import static android.net.TrafficStats.MB_IN_BYTES;
+import static android.os.Trace.TRACE_TAG_NETWORK;
import static android.provider.Settings.Global.NETSTATS_AUGMENT_ENABLED;
import static android.provider.Settings.Global.NETSTATS_DEV_BUCKET_DURATION;
import static android.provider.Settings.Global.NETSTATS_DEV_DELETE_AGE;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.SystemClock;
+import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.Global;
private void recordSnapshotLocked(long currentTime) throws RemoteException {
// snapshot and record current counters; read UID stats first to
// avoid over counting dev stats.
+ Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotUid");
final NetworkStats uidSnapshot = getNetworkStatsUidDetail(INTERFACES_ALL);
+ Trace.traceEnd(TRACE_TAG_NETWORK);
+ Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotXt");
final NetworkStats xtSnapshot = getNetworkStatsXt();
+ Trace.traceEnd(TRACE_TAG_NETWORK);
+ Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotDev");
final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev();
+ Trace.traceEnd(TRACE_TAG_NETWORK);
// Tethering snapshot for dev and xt stats. Counts per-interface data from tethering stats
// providers that isn't already counted by dev and XT stats.
+ Trace.traceBegin(TRACE_TAG_NETWORK, "snapshotTether");
final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_IFACE);
+ Trace.traceEnd(TRACE_TAG_NETWORK);
xtSnapshot.combineAllValues(tetherSnapshot);
devSnapshot.combineAllValues(tetherSnapshot);
// For xt/dev, we pass a null VPN array because usage is aggregated by UID, so VPN traffic
// can't be reattributed to responsible apps.
+ Trace.traceBegin(TRACE_TAG_NETWORK, "recordDev");
mDevRecorder.recordSnapshotLocked(
devSnapshot, mActiveIfaces, null /* vpnArray */, currentTime);
+ Trace.traceEnd(TRACE_TAG_NETWORK);
+ Trace.traceBegin(TRACE_TAG_NETWORK, "recordXt");
mXtRecorder.recordSnapshotLocked(
xtSnapshot, mActiveIfaces, null /* vpnArray */, currentTime);
+ Trace.traceEnd(TRACE_TAG_NETWORK);
// For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps.
VpnInfo[] vpnArray = mConnManager.getAllVpnInfo();
+ Trace.traceBegin(TRACE_TAG_NETWORK, "recordUid");
mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime);
+ Trace.traceEnd(TRACE_TAG_NETWORK);
+ Trace.traceBegin(TRACE_TAG_NETWORK, "recordUidTag");
mUidTagRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime);
+ Trace.traceEnd(TRACE_TAG_NETWORK);
// We need to make copies of member fields that are sent to the observer to avoid
// a race condition between the service handler thread and the observer's
private void performPollLocked(int flags) {
if (!mSystemReady) return;
if (LOGV) Slog.v(TAG, "performPollLocked(flags=0x" + Integer.toHexString(flags) + ")");
-
- final long startRealtime = SystemClock.elapsedRealtime();
+ Trace.traceBegin(TRACE_TAG_NETWORK, "performPollLocked");
final boolean persistNetwork = (flags & FLAG_PERSIST_NETWORK) != 0;
final boolean persistUid = (flags & FLAG_PERSIST_UID) != 0;
}
// persist any pending data depending on requested flags
+ Trace.traceBegin(TRACE_TAG_NETWORK, "[persisting]");
if (persistForce) {
mDevRecorder.forcePersistLocked(currentTime);
mXtRecorder.forcePersistLocked(currentTime);
mUidTagRecorder.maybePersistLocked(currentTime);
}
}
-
- if (LOGV) {
- final long duration = SystemClock.elapsedRealtime() - startRealtime;
- Slog.v(TAG, "performPollLocked() took " + duration + "ms");
- }
+ Trace.traceEnd(TRACE_TAG_NETWORK);
if (mSettings.getSampleEnabled()) {
// sample stats after each full poll
updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
mContext.sendBroadcastAsUser(updatedIntent, UserHandle.ALL,
READ_NETWORK_USAGE_HISTORY);
+
+ Trace.traceEnd(TRACE_TAG_NETWORK);
}
/**
private class NetworkStatsManagerInternalImpl extends NetworkStatsManagerInternal {
@Override
public long getNetworkTotalBytes(NetworkTemplate template, long start, long end) {
- return NetworkStatsService.this.getNetworkTotalBytes(template, start, end);
+ Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkTotalBytes");
+ try {
+ return NetworkStatsService.this.getNetworkTotalBytes(template, start, end);
+ } finally {
+ Trace.traceEnd(TRACE_TAG_NETWORK);
+ }
}
@Override
public NetworkStats getNetworkUidBytes(NetworkTemplate template, long start, long end) {
- return NetworkStatsService.this.getNetworkUidBytes(template, start, end);
+ Trace.traceBegin(TRACE_TAG_NETWORK, "getNetworkUidBytes");
+ try {
+ return NetworkStatsService.this.getNetworkUidBytes(template, start, end);
+ } finally {
+ Trace.traceEnd(TRACE_TAG_NETWORK);
+ }
}
@Override