Use eBPF map data for per iface stats
After adding the xt_bpf module and ifaceStatsMap, eBPF tool can now support reading per interface data. So networkStatsFactory should move away from parsing proc/net/dev and use the eBPF map stats instead. Bug: 72111305 Test: atest com.android.server.net.NetworkStatsServiceTest Change-Id: Ibcc6150d00835b3bd33af22a72e4a86e172581cf Merged-In: Ibcc6150d00835b3bd33af22a72e4a86e172581cf (cherry picked from aosp commit dcc56783f5b945b16c9f5e50333fba557a7c3603)
This commit is contained in:
@@ -178,6 +178,14 @@ public class NetworkStatsFactory {
|
||||
return stats;
|
||||
}
|
||||
|
||||
public NetworkStats readBpfNetworkStatsDev() throws IOException {
|
||||
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
|
||||
if (nativeReadNetworkStatsDev(stats) != 0) {
|
||||
throw new IOException("Failed to parse bpf iface stats");
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and return interface-level summary {@link NetworkStats} measured
|
||||
* using {@code /proc/net/dev} style hooks, which may include non IP layer
|
||||
@@ -188,9 +196,9 @@ public class NetworkStatsFactory {
|
||||
*/
|
||||
public NetworkStats readNetworkStatsSummaryDev() throws IOException {
|
||||
|
||||
// Return the stats get from /proc/net/dev if switched to bpf module.
|
||||
// Return xt_bpf stats if switched to bpf module.
|
||||
if (mUseBpfStats)
|
||||
return readNetworkStatsIfaceDev();
|
||||
return readBpfNetworkStatsDev();
|
||||
|
||||
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
|
||||
|
||||
@@ -244,9 +252,9 @@ public class NetworkStatsFactory {
|
||||
*/
|
||||
public NetworkStats readNetworkStatsSummaryXt() throws IOException {
|
||||
|
||||
// Return the stats get from /proc/net/dev if qtaguid module is replaced.
|
||||
// Return xt_bpf stats if qtaguid module is replaced.
|
||||
if (mUseBpfStats)
|
||||
return readNetworkStatsIfaceDev();
|
||||
return readBpfNetworkStatsDev();
|
||||
|
||||
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
|
||||
|
||||
@@ -408,4 +416,7 @@ public class NetworkStatsFactory {
|
||||
@VisibleForTesting
|
||||
public static native int nativeReadNetworkStatsDetail(NetworkStats stats, String path,
|
||||
int limitUid, String[] limitIfaces, int limitTag, boolean useBpfStats);
|
||||
|
||||
@VisibleForTesting
|
||||
public static native int nativeReadNetworkStatsDev(NetworkStats stats);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user