Merge changes from topic "ifaceStats"

am: 90c01b0093

Change-Id: I0b564b2d3b13c0e5d033c5cf4aaddad3a750f2c7
This commit is contained in:
android-build-prod (mdb)
2018-05-01 19:41:39 -07:00
committed by android-build-merger
2 changed files with 0 additions and 55 deletions

View File

@@ -54,8 +54,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}. */
@@ -131,51 +129,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) {

View File

@@ -115,20 +115,6 @@ public class NetworkStatsFactoryTest {
assertStatsEntry(stats, "rmnet1", 10021, SET_FOREGROUND, 0x30100000, 742L, 3L, 1265L, 3L);
}
@Test
public void testNetworkStatsSummary() throws Exception {
stageFile(R.raw.net_dev_typical, file("net/dev"));
final NetworkStats stats = mFactory.readNetworkStatsIfaceDev();
assertEquals(6, stats.size());
assertStatsEntry(stats, "lo", UID_ALL, SET_ALL, TAG_NONE, 8308L, 8308L);
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L, 489339L);
assertStatsEntry(stats, "ifb0", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L);
assertStatsEntry(stats, "ifb1", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L);
assertStatsEntry(stats, "sit0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L);
assertStatsEntry(stats, "ip6tnl0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L);
}
@Test
public void testNetworkStatsSingle() throws Exception {
stageFile(R.raw.xt_qtaguid_iface_typical, file("net/xt_qtaguid/iface_stat_all"));