Loading services/java/com/android/server/NetworkManagementService.java +39 −19 Original line number Diff line number Diff line Loading @@ -1033,6 +1033,38 @@ public class NetworkManagementService extends INetworkManagementService.Stub final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6); final NetworkStats.Entry entry = new NetworkStats.Entry(); final HashSet<String> knownIfaces = Sets.newHashSet(); final HashSet<String> activeIfaces = Sets.newHashSet(); // collect any historical stats and active state // TODO: migrate to reading from single file if (mBandwidthControlEnabled) { for (String iface : fileListWithoutNull(mStatsXtIface)) { final File ifacePath = new File(mStatsXtIface, iface); final long active = readSingleLongFromFile(new File(ifacePath, "active")); if (active == 1) { knownIfaces.add(iface); activeIfaces.add(iface); } else if (active == 0) { knownIfaces.add(iface); } else { continue; } entry.iface = iface; entry.uid = UID_ALL; entry.set = SET_DEFAULT; entry.tag = TAG_NONE; entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes")); entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets")); entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes")); entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets")); stats.addValues(entry); } } final ArrayList<String> values = Lists.newArrayList(); BufferedReader reader = null; Loading @@ -1058,7 +1090,13 @@ public class NetworkManagementService extends INetworkManagementService.Stub entry.txBytes = Long.parseLong(values.get(9)); entry.txPackets = Long.parseLong(values.get(10)); if (activeIfaces.contains(entry.iface)) { // combine stats when iface is active stats.combineValues(entry); } else if (!knownIfaces.contains(entry.iface)) { // add stats when iface is unknown stats.addValues(entry); } } catch (NumberFormatException e) { Slog.w(TAG, "problem parsing stats row '" + line + "': " + e); } Loading @@ -1073,24 +1111,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub IoUtils.closeQuietly(reader); } // splice in historical stats not reflected in mStatsIface if (mBandwidthControlEnabled) { for (String iface : fileListWithoutNull(mStatsXtIface)) { final File ifacePath = new File(mStatsXtIface, iface); entry.iface = iface; entry.uid = UID_ALL; entry.set = SET_DEFAULT; entry.tag = TAG_NONE; entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes")); entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets")); entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes")); entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets")); stats.combineValues(entry); } } return stats; } Loading services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ public class NetworkManagementServiceTest extends AndroidTestCase { public void testNetworkStatsSummaryDown() throws Exception { stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/active")); stageLong(1024L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_bytes")); stageLong(128L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_packets")); stageLong(2048L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_bytes")); Loading @@ -119,6 +120,7 @@ public class NetworkManagementServiceTest extends AndroidTestCase { public void testNetworkStatsCombined() throws Exception { stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active")); stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes")); stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets")); stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes")); Loading @@ -129,6 +131,18 @@ public class NetworkManagementServiceTest extends AndroidTestCase { 2205L + 20L, 489339L + 30L, 2237L + 40L); } public void testNetworkStatsCombinedInactive() throws Exception { stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageLong(0L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active")); stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes")); stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets")); stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes")); stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets")); final NetworkStats stats = mService.getNetworkStatsSummary(); assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 10L, 20L, 30L, 40L); } public void testKernelTags() throws Exception { assertEquals("0", tagToKernel(0x0)); assertEquals("214748364800", tagToKernel(0x32)); Loading Loading
services/java/com/android/server/NetworkManagementService.java +39 −19 Original line number Diff line number Diff line Loading @@ -1033,6 +1033,38 @@ public class NetworkManagementService extends INetworkManagementService.Stub final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6); final NetworkStats.Entry entry = new NetworkStats.Entry(); final HashSet<String> knownIfaces = Sets.newHashSet(); final HashSet<String> activeIfaces = Sets.newHashSet(); // collect any historical stats and active state // TODO: migrate to reading from single file if (mBandwidthControlEnabled) { for (String iface : fileListWithoutNull(mStatsXtIface)) { final File ifacePath = new File(mStatsXtIface, iface); final long active = readSingleLongFromFile(new File(ifacePath, "active")); if (active == 1) { knownIfaces.add(iface); activeIfaces.add(iface); } else if (active == 0) { knownIfaces.add(iface); } else { continue; } entry.iface = iface; entry.uid = UID_ALL; entry.set = SET_DEFAULT; entry.tag = TAG_NONE; entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes")); entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets")); entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes")); entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets")); stats.addValues(entry); } } final ArrayList<String> values = Lists.newArrayList(); BufferedReader reader = null; Loading @@ -1058,7 +1090,13 @@ public class NetworkManagementService extends INetworkManagementService.Stub entry.txBytes = Long.parseLong(values.get(9)); entry.txPackets = Long.parseLong(values.get(10)); if (activeIfaces.contains(entry.iface)) { // combine stats when iface is active stats.combineValues(entry); } else if (!knownIfaces.contains(entry.iface)) { // add stats when iface is unknown stats.addValues(entry); } } catch (NumberFormatException e) { Slog.w(TAG, "problem parsing stats row '" + line + "': " + e); } Loading @@ -1073,24 +1111,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub IoUtils.closeQuietly(reader); } // splice in historical stats not reflected in mStatsIface if (mBandwidthControlEnabled) { for (String iface : fileListWithoutNull(mStatsXtIface)) { final File ifacePath = new File(mStatsXtIface, iface); entry.iface = iface; entry.uid = UID_ALL; entry.set = SET_DEFAULT; entry.tag = TAG_NONE; entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes")); entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets")); entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes")); entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets")); stats.combineValues(entry); } } return stats; } Loading
services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ public class NetworkManagementServiceTest extends AndroidTestCase { public void testNetworkStatsSummaryDown() throws Exception { stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/active")); stageLong(1024L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_bytes")); stageLong(128L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_packets")); stageLong(2048L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_bytes")); Loading @@ -119,6 +120,7 @@ public class NetworkManagementServiceTest extends AndroidTestCase { public void testNetworkStatsCombined() throws Exception { stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active")); stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes")); stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets")); stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes")); Loading @@ -129,6 +131,18 @@ public class NetworkManagementServiceTest extends AndroidTestCase { 2205L + 20L, 489339L + 30L, 2237L + 40L); } public void testNetworkStatsCombinedInactive() throws Exception { stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev")); stageLong(0L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active")); stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes")); stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets")); stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes")); stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets")); final NetworkStats stats = mService.getNetworkStatsSummary(); assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 10L, 20L, 30L, 40L); } public void testKernelTags() throws Exception { assertEquals("0", tagToKernel(0x0)); assertEquals("214748364800", tagToKernel(0x32)); Loading