Merge changes from topic "ifaceStats" am: eab28ef97c
am: b86d2b4b84 Change-Id: I460bc25806182bc2dc5fcc2512ab01e776a0e8e6
This commit is contained in:
committed by
android-build-merger
commit
93f2f28a66
@@ -56,8 +56,6 @@ public class NetworkStatsFactory {
|
||||
private static final boolean USE_NATIVE_PARSING = true;
|
||||
private static final boolean SANITY_CHECK_NATIVE = false;
|
||||
|
||||
/** Path to {@code /proc/net/dev}. */
|
||||
private final File mStatsIfaceDev;
|
||||
/** Path to {@code /proc/net/xt_qtaguid/iface_stat_all}. */
|
||||
private final File mStatsXtIfaceAll;
|
||||
/** Path to {@code /proc/net/xt_qtaguid/iface_stat_fmt}. */
|
||||
@@ -133,51 +131,12 @@ public class NetworkStatsFactory {
|
||||
|
||||
@VisibleForTesting
|
||||
public NetworkStatsFactory(File procRoot, boolean useBpfStats) {
|
||||
mStatsIfaceDev = new File(procRoot, "net/dev");
|
||||
mStatsXtIfaceAll = new File(procRoot, "net/xt_qtaguid/iface_stat_all");
|
||||
mStatsXtIfaceFmt = new File(procRoot, "net/xt_qtaguid/iface_stat_fmt");
|
||||
mStatsXtUid = new File(procRoot, "net/xt_qtaguid/stats");
|
||||
mUseBpfStats = useBpfStats;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public NetworkStats readNetworkStatsIfaceDev() throws IOException {
|
||||
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
|
||||
|
||||
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
|
||||
final NetworkStats.Entry entry = new NetworkStats.Entry();
|
||||
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(mStatsIfaceDev));
|
||||
|
||||
// skip first two header lines
|
||||
reader.readLine();
|
||||
reader.readLine();
|
||||
|
||||
// parse remaining lines
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] values = line.trim().split("\\:?\\s+");
|
||||
entry.iface = values[0];
|
||||
entry.uid = UID_ALL;
|
||||
entry.set = SET_ALL;
|
||||
entry.tag = TAG_NONE;
|
||||
entry.rxBytes = Long.parseLong(values[1]);
|
||||
entry.rxPackets = Long.parseLong(values[2]);
|
||||
entry.txBytes = Long.parseLong(values[9]);
|
||||
entry.txPackets = Long.parseLong(values[10]);
|
||||
stats.addValues(entry);
|
||||
}
|
||||
} catch (NullPointerException|NumberFormatException e) {
|
||||
throw new ProtocolException("problem parsing stats", e);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(reader);
|
||||
StrictMode.setThreadPolicy(savedPolicy);
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
public NetworkStats readBpfNetworkStatsDev() throws IOException {
|
||||
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
|
||||
if (nativeReadNetworkStatsDev(stats) != 0) {
|
||||
|
||||
Reference in New Issue
Block a user