Count and Report Bandwidth Requests by UID

To debug power drain due to modem wakeups,
one of the signals we'd like to track is
requests for bandwidth estimate to see which
apps are making requests and how often. This
patch keeps a simple count per-UID when an
app requests a bandwidth update, and that
count is made available in dumpsys.

Bug: 77498849
Test: runtest frameworks-net
Change-Id: I30d2ce85f9fa6747030cf4039d1080113a32e386
This commit is contained in:
Nathan Harold
2018-07-30 13:38:01 -07:00
parent dab690a61a
commit b89cbfbdca

View File

@@ -497,6 +497,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
private final IpConnectivityLog mMetricsLog;
@GuardedBy("mBandwidthRequests")
private final SparseArray<Integer> mBandwidthRequests = new SparseArray(10);
@VisibleForTesting
final MultinetworkPolicyTracker mMultinetworkPolicyTracker;
@@ -2069,6 +2072,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
pw.println("currently holding WakeLock for: " + (duration / 1000) + "s");
}
mWakelockLogs.reverseDump(fd, pw, args);
pw.println();
pw.println("bandwidth update requests (by uid):");
pw.increaseIndent();
synchronized (mBandwidthRequests) {
for (int i = 0; i < mBandwidthRequests.size(); i++) {
pw.println("[" + mBandwidthRequests.keyAt(i)
+ "]: " + mBandwidthRequests.valueAt(i));
}
}
pw.decreaseIndent();
pw.decreaseIndent();
}
}
@@ -4223,6 +4238,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
if (nai != null) {
nai.asyncChannel.sendMessage(android.net.NetworkAgent.CMD_REQUEST_BANDWIDTH_UPDATE);
synchronized (mBandwidthRequests) {
final int uid = Binder.getCallingUid();
Integer uidReqs = mBandwidthRequests.get(uid);
if (uidReqs == null) {
uidReqs = new Integer(0);
}
mBandwidthRequests.put(uid, ++uidReqs);
}
return true;
}
return false;
@@ -5803,4 +5826,4 @@ public class ConnectivityService extends IConnectivityManager.Stub
pw.println(" Get airplane mode.");
}
}
}
}