Merge changes I71988117,Ia70379a3
* changes: Move app uid stats map dump to NetworkStatsService Move uid counter set map dump to NetworkStatsService
This commit is contained in:
@@ -2715,6 +2715,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
pw.println("BPF map content:");
|
pw.println("BPF map content:");
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
dumpCookieTagMapLocked(pw);
|
dumpCookieTagMapLocked(pw);
|
||||||
|
dumpUidCounterSetMapLocked(pw);
|
||||||
|
dumpAppUidStatsMapLocked(pw);
|
||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2765,6 +2767,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
private void dumpMapStatus(final IndentingPrintWriter pw) {
|
private void dumpMapStatus(final IndentingPrintWriter pw) {
|
||||||
pw.println("mCookieTagMap: " + getMapStatus(mCookieTagMap, COOKIE_TAG_MAP_PATH));
|
pw.println("mCookieTagMap: " + getMapStatus(mCookieTagMap, COOKIE_TAG_MAP_PATH));
|
||||||
|
pw.println("mUidCounterSetMap: "
|
||||||
|
+ getMapStatus(mUidCounterSetMap, UID_COUNTERSET_MAP_PATH));
|
||||||
|
pw.println("mAppUidStatsMap: " + getMapStatus(mAppUidStatsMap, APP_UID_STATS_MAP_PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("mStatsLock")
|
@GuardedBy("mStatsLock")
|
||||||
@@ -2792,6 +2797,57 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GuardedBy("mStatsLock")
|
||||||
|
private void dumpUidCounterSetMapLocked(final IndentingPrintWriter pw) {
|
||||||
|
if (mUidCounterSetMap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pw.println("mUidCounterSetMap:");
|
||||||
|
pw.increaseIndent();
|
||||||
|
try {
|
||||||
|
mUidCounterSetMap.forEach((uid, set) -> {
|
||||||
|
// set could be null if there is a concurrent entry deletion.
|
||||||
|
// http://b/220084230.
|
||||||
|
if (set != null) {
|
||||||
|
pw.println("uid=" + uid.val + " set=" + set.val);
|
||||||
|
} else {
|
||||||
|
pw.println("Entry is deleted while dumping, iterating from first entry");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (ErrnoException e) {
|
||||||
|
pw.println("mUidCounterSetMap dump end with error: " + Os.strerror(e.errno));
|
||||||
|
}
|
||||||
|
pw.decreaseIndent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GuardedBy("mStatsLock")
|
||||||
|
private void dumpAppUidStatsMapLocked(final IndentingPrintWriter pw) {
|
||||||
|
if (mAppUidStatsMap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pw.println("mAppUidStatsMap:");
|
||||||
|
pw.increaseIndent();
|
||||||
|
pw.println("uid rxBytes rxPackets txBytes txPackets");
|
||||||
|
try {
|
||||||
|
mAppUidStatsMap.forEach((key, value) -> {
|
||||||
|
// value could be null if there is a concurrent entry deletion.
|
||||||
|
// http://b/220084230.
|
||||||
|
if (value != null) {
|
||||||
|
pw.println(key.uid + " "
|
||||||
|
+ value.rxBytes + " "
|
||||||
|
+ value.rxPackets + " "
|
||||||
|
+ value.txBytes + " "
|
||||||
|
+ value.txPackets);
|
||||||
|
} else {
|
||||||
|
pw.println("Entry is deleted while dumping, iterating from first entry");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (ErrnoException e) {
|
||||||
|
pw.println("mAppUidStatsMap dump end with error: " + Os.strerror(e.errno));
|
||||||
|
}
|
||||||
|
pw.decreaseIndent();
|
||||||
|
}
|
||||||
|
|
||||||
private NetworkStats readNetworkStatsSummaryDev() {
|
private NetworkStats readNetworkStatsSummaryDev() {
|
||||||
try {
|
try {
|
||||||
return mStatsFactory.readNetworkStatsSummaryDev();
|
return mStatsFactory.readNetworkStatsSummaryDev();
|
||||||
|
|||||||
@@ -612,10 +612,6 @@ void TrafficController::dump(int fd, bool verbose) {
|
|||||||
ScopedIndent indentPreBpfModule(dw);
|
ScopedIndent indentPreBpfModule(dw);
|
||||||
|
|
||||||
dw.blankline();
|
dw.blankline();
|
||||||
dw.println("mUidCounterSetMap status: %s",
|
|
||||||
getMapStatus(mUidCounterSetMap.getMap(), UID_COUNTERSET_MAP_PATH).c_str());
|
|
||||||
dw.println("mAppUidStatsMap status: %s",
|
|
||||||
getMapStatus(mAppUidStatsMap.getMap(), APP_UID_STATS_MAP_PATH).c_str());
|
|
||||||
dw.println("mStatsMapA status: %s",
|
dw.println("mStatsMapA status: %s",
|
||||||
getMapStatus(mStatsMapA.getMap(), STATS_MAP_A_PATH).c_str());
|
getMapStatus(mStatsMapA.getMap(), STATS_MAP_A_PATH).c_str());
|
||||||
dw.println("mStatsMapB status: %s",
|
dw.println("mStatsMapB status: %s",
|
||||||
@@ -651,32 +647,6 @@ void TrafficController::dump(int fd, bool verbose) {
|
|||||||
|
|
||||||
ScopedIndent indentForMapContent(dw);
|
ScopedIndent indentForMapContent(dw);
|
||||||
|
|
||||||
// Print UidCounterSetMap content.
|
|
||||||
dumpBpfMap("mUidCounterSetMap", dw, "");
|
|
||||||
const auto printUidInfo = [&dw](const uint32_t& key, const uint8_t& value,
|
|
||||||
const BpfMap<uint32_t, uint8_t>&) {
|
|
||||||
dw.println("%u %u", key, value);
|
|
||||||
return base::Result<void>();
|
|
||||||
};
|
|
||||||
base::Result<void> res = mUidCounterSetMap.iterateWithValue(printUidInfo);
|
|
||||||
if (!res.ok()) {
|
|
||||||
dw.println("mUidCounterSetMap print end with error: %s", res.error().message().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print AppUidStatsMap content.
|
|
||||||
std::string appUidStatsHeader = StringPrintf("uid rxBytes rxPackets txBytes txPackets");
|
|
||||||
dumpBpfMap("mAppUidStatsMap:", dw, appUidStatsHeader);
|
|
||||||
auto printAppUidStatsInfo = [&dw](const uint32_t& key, const StatsValue& value,
|
|
||||||
const BpfMap<uint32_t, StatsValue>&) {
|
|
||||||
dw.println("%u %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, key, value.rxBytes,
|
|
||||||
value.rxPackets, value.txBytes, value.txPackets);
|
|
||||||
return base::Result<void>();
|
|
||||||
};
|
|
||||||
res = mAppUidStatsMap.iterateWithValue(printAppUidStatsInfo);
|
|
||||||
if (!res.ok()) {
|
|
||||||
dw.println("mAppUidStatsMap print end with error: %s", res.error().message().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print uidStatsMap content.
|
// Print uidStatsMap content.
|
||||||
std::string statsHeader = StringPrintf("ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes"
|
std::string statsHeader = StringPrintf("ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes"
|
||||||
" rxPackets txBytes txPackets");
|
" rxPackets txBytes txPackets");
|
||||||
@@ -693,7 +663,7 @@ void TrafficController::dump(int fd, bool verbose) {
|
|||||||
value.rxPackets, value.txBytes, value.txPackets);
|
value.rxPackets, value.txBytes, value.txPackets);
|
||||||
return base::Result<void>();
|
return base::Result<void>();
|
||||||
};
|
};
|
||||||
res = mStatsMapA.iterateWithValue(printStatsInfo);
|
base::Result<void> res = mStatsMapA.iterateWithValue(printStatsInfo);
|
||||||
if (!res.ok()) {
|
if (!res.ok()) {
|
||||||
dw.println("mStatsMapA print end with error: %s", res.error().message().c_str());
|
dw.println("mStatsMapA print end with error: %s", res.error().message().c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -791,11 +791,6 @@ TEST_F(TrafficControllerTest, TestDumpsys) {
|
|||||||
// ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets
|
// ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets
|
||||||
// 999 test0 0x2a 10086 1 100 1 0 0
|
// 999 test0 0x2a 10086 1 100 1 0 0
|
||||||
std::vector<std::string> expectedLines = {
|
std::vector<std::string> expectedLines = {
|
||||||
"mUidCounterSetMap:",
|
|
||||||
fmt::format("{} {}", TEST_UID3, TEST_COUNTERSET),
|
|
||||||
"mAppUidStatsMap::", // TODO@: fix double colon
|
|
||||||
"uid rxBytes rxPackets txBytes txPackets",
|
|
||||||
fmt::format("{} {} {} {} {}", TEST_UID, RXBYTES, RXPACKETS, TXBYTES, TXPACKETS),
|
|
||||||
"mStatsMapA",
|
"mStatsMapA",
|
||||||
"ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets",
|
"ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets",
|
||||||
fmt::format("{} {} {:#x} {} {} {} {} {} {}",
|
fmt::format("{} {} {:#x} {} {} {} {} {} {}",
|
||||||
@@ -831,8 +826,6 @@ TEST_F(TrafficControllerTest, dumpsysInvalidMaps) {
|
|||||||
"Read value of map -1 failed: Bad file descriptor";
|
"Read value of map -1 failed: Bad file descriptor";
|
||||||
|
|
||||||
std::vector<std::string> expectedLines = {
|
std::vector<std::string> expectedLines = {
|
||||||
fmt::format("mUidCounterSetMap {}", kErrIterate),
|
|
||||||
fmt::format("mAppUidStatsMap {}", kErrIterate),
|
|
||||||
fmt::format("mStatsMapA {}", kErrIterate),
|
fmt::format("mStatsMapA {}", kErrIterate),
|
||||||
fmt::format("mStatsMapB {}", kErrIterate),
|
fmt::format("mStatsMapB {}", kErrIterate),
|
||||||
fmt::format("mIfaceIndexNameMap {}", kErrIterate),
|
fmt::format("mIfaceIndexNameMap {}", kErrIterate),
|
||||||
|
|||||||
@@ -2343,4 +2343,23 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
assertDumpContains(dump, "cookie=2002 tag=0x1 uid=1002");
|
assertDumpContains(dump, "cookie=2002 tag=0x1 uid=1002");
|
||||||
assertDumpContains(dump, "cookie=3002 tag=0x2 uid=1002");
|
assertDumpContains(dump, "cookie=3002 tag=0x2 uid=1002");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDumpUidCounterSetMap() throws ErrnoException {
|
||||||
|
initBpfMapsWithTagData(UID_BLUE);
|
||||||
|
|
||||||
|
final String dump = getDump();
|
||||||
|
assertDumpContains(dump, "mUidCounterSetMap: OK");
|
||||||
|
assertDumpContains(dump, "uid=1002 set=1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAppUidStatsMap() throws ErrnoException {
|
||||||
|
initBpfMapsWithTagData(UID_BLUE);
|
||||||
|
|
||||||
|
final String dump = getDump();
|
||||||
|
assertDumpContains(dump, "mAppUidStatsMap: OK");
|
||||||
|
assertDumpContains(dump, "uid rxBytes rxPackets txBytes txPackets");
|
||||||
|
assertDumpContains(dump, "1002 10000 10 6000 6");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user