From 7224ab835afd9314e0d2a6b3eac809a6246a8879 Mon Sep 17 00:00:00 2001 From: Chenbo Feng Date: Mon, 20 Nov 2017 17:03:59 -0800 Subject: [PATCH 1/2] Add bpf support for NetworkStatsFactory Add the native method used to read the detail information of network stats from bpf maps. The native method of NetworkStatsFactory should choose the correct implementation to get the stats detail depending on the kernel version. Currently the bpf result is printed as a reference and the actual behavior of NetworkStatsFactory should not change. Test: NetworkStatsFactory related cts test should not fail. Bug: 30950746 Change-Id: I4715a23559b5b2306bd556cea0431f0ed172a993 --- .../java/com/android/internal/net/NetworkStatsFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java index 56b8e608da..b267cb53d3 100644 --- a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java +++ b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java @@ -67,7 +67,7 @@ public class NetworkStatsFactoryTest { IoUtils.deleteContents(mTestProc); } - mFactory = new NetworkStatsFactory(mTestProc); + mFactory = new NetworkStatsFactory(mTestProc, false); } @After From b25ada36572d160586680ec36a523855d49d79e0 Mon Sep 17 00:00:00 2001 From: Chenbo Feng Date: Thu, 18 Jan 2018 19:48:52 -0800 Subject: [PATCH 2/2] Use /proc/net/dev to get stats summary If the qtaguid proc file is no longer exist, the device is running new eBPF module to do traffic accounting. So the NetworkStatsFactory need to use the proc/net/dev interface to get the per interface traffic stats summary. Also, adding a test to verify the helper function work properly Bug: 30950746 Test: run NetworkStatsFactoryTest Change-Id: Ia36808bf02f1637dd41a3e7c50917b91b1a77524 --- .../internal/net/NetworkStatsFactoryTest.java | 14 ++++++++++++++ tests/net/res/raw/net_dev_typical | 8 ++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/net/res/raw/net_dev_typical diff --git a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java index b267cb53d3..b14f5509b7 100644 --- a/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java +++ b/tests/net/java/com/android/internal/net/NetworkStatsFactoryTest.java @@ -115,6 +115,20 @@ 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")); diff --git a/tests/net/res/raw/net_dev_typical b/tests/net/res/raw/net_dev_typical new file mode 100644 index 0000000000..290bf03eb9 --- /dev/null +++ b/tests/net/res/raw/net_dev_typical @@ -0,0 +1,8 @@ +Inter-| Receive | Transmit + face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed + lo: 8308 116 0 0 0 0 0 0 8308 116 0 0 0 0 0 0 +rmnet0: 1507570 2205 0 0 0 0 0 0 489339 2237 0 0 0 0 0 0 + ifb0: 52454 151 0 151 0 0 0 0 0 0 0 0 0 0 0 0 + ifb1: 52454 151 0 151 0 0 0 0 0 0 0 0 0 0 0 0 + sit0: 0 0 0 0 0 0 0 0 0 0 148 0 0 0 0 0 +ip6tnl0: 0 0 0 0 0 0 0 0 0 0 151 151 0 0 0 0