Merge "BpfNetworkStats - remove spurious code & use static maps"
This commit is contained in:
@@ -58,13 +58,7 @@ int bpfGetUidStatsInternal(uid_t uid, Stats* stats,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int bpfGetUidStats(uid_t uid, Stats* stats) {
|
int bpfGetUidStats(uid_t uid, Stats* stats) {
|
||||||
BpfMapRO<uint32_t, StatsValue> appUidStatsMap(APP_UID_STATS_MAP_PATH);
|
static BpfMapRO<uint32_t, StatsValue> appUidStatsMap(APP_UID_STATS_MAP_PATH);
|
||||||
|
|
||||||
if (!appUidStatsMap.isValid()) {
|
|
||||||
int ret = -errno;
|
|
||||||
ALOGE("Opening appUidStatsMap(%s) failed: %s", APP_UID_STATS_MAP_PATH, strerror(errno));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return bpfGetUidStatsInternal(uid, stats, appUidStatsMap);
|
return bpfGetUidStatsInternal(uid, stats, appUidStatsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,19 +94,8 @@ int bpfGetIfaceStatsInternal(const char* iface, Stats* stats,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int bpfGetIfaceStats(const char* iface, Stats* stats) {
|
int bpfGetIfaceStats(const char* iface, Stats* stats) {
|
||||||
BpfMapRO<uint32_t, StatsValue> ifaceStatsMap(IFACE_STATS_MAP_PATH);
|
static BpfMapRO<uint32_t, StatsValue> ifaceStatsMap(IFACE_STATS_MAP_PATH);
|
||||||
int ret;
|
static BpfMapRO<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
||||||
if (!ifaceStatsMap.isValid()) {
|
|
||||||
ret = -errno;
|
|
||||||
ALOGE("get ifaceStats map fd failed: %s", strerror(errno));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
BpfMapRO<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
|
||||||
if (!ifaceIndexNameMap.isValid()) {
|
|
||||||
ret = -errno;
|
|
||||||
ALOGE("get ifaceIndexName map fd failed: %s", strerror(errno));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return bpfGetIfaceStatsInternal(iface, stats, ifaceStatsMap, ifaceIndexNameMap);
|
return bpfGetIfaceStatsInternal(iface, stats, ifaceStatsMap, ifaceIndexNameMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,19 +169,8 @@ int parseBpfNetworkStatsDetailInternal(std::vector<stats_line>* lines,
|
|||||||
int parseBpfNetworkStatsDetail(std::vector<stats_line>* lines,
|
int parseBpfNetworkStatsDetail(std::vector<stats_line>* lines,
|
||||||
const std::vector<std::string>& limitIfaces, int limitTag,
|
const std::vector<std::string>& limitIfaces, int limitTag,
|
||||||
int limitUid) {
|
int limitUid) {
|
||||||
BpfMapRO<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
static BpfMapRO<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
||||||
if (!ifaceIndexNameMap.isValid()) {
|
static BpfMapRO<uint32_t, uint32_t> configurationMap(CONFIGURATION_MAP_PATH);
|
||||||
int ret = -errno;
|
|
||||||
ALOGE("get ifaceIndexName map fd failed: %s", strerror(errno));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
BpfMapRO<uint32_t, uint32_t> configurationMap(CONFIGURATION_MAP_PATH);
|
|
||||||
if (!configurationMap.isValid()) {
|
|
||||||
int ret = -errno;
|
|
||||||
ALOGE("get configuration map fd failed: %s", strerror(errno));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
auto configuration = configurationMap.readValue(CURRENT_STATS_MAP_CONFIGURATION_KEY);
|
auto configuration = configurationMap.readValue(CURRENT_STATS_MAP_CONFIGURATION_KEY);
|
||||||
if (!configuration.ok()) {
|
if (!configuration.ok()) {
|
||||||
ALOGE("Cannot read the old configuration from map: %s",
|
ALOGE("Cannot read the old configuration from map: %s",
|
||||||
@@ -210,12 +182,8 @@ int parseBpfNetworkStatsDetail(std::vector<stats_line>* lines,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
const char* statsMapPath = STATS_MAP_PATH[configuration.value()];
|
const char* statsMapPath = STATS_MAP_PATH[configuration.value()];
|
||||||
|
// TODO: fix this to not constantly reopen the bpf map
|
||||||
BpfMap<StatsKey, StatsValue> statsMap(statsMapPath);
|
BpfMap<StatsKey, StatsValue> statsMap(statsMapPath);
|
||||||
if (!statsMap.isValid()) {
|
|
||||||
int ret = -errno;
|
|
||||||
ALOGE("get stats map fd failed: %s, path: %s", strerror(errno), statsMapPath);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// It is safe to read and clear the old map now since the
|
// It is safe to read and clear the old map now since the
|
||||||
// networkStatsFactory should call netd to swap the map in advance already.
|
// networkStatsFactory should call netd to swap the map in advance already.
|
||||||
@@ -266,20 +234,8 @@ int parseBpfNetworkStatsDevInternal(std::vector<stats_line>* lines,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int parseBpfNetworkStatsDev(std::vector<stats_line>* lines) {
|
int parseBpfNetworkStatsDev(std::vector<stats_line>* lines) {
|
||||||
int ret = 0;
|
static BpfMapRO<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
||||||
BpfMapRO<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
static BpfMapRO<uint32_t, StatsValue> ifaceStatsMap(IFACE_STATS_MAP_PATH);
|
||||||
if (!ifaceIndexNameMap.isValid()) {
|
|
||||||
ret = -errno;
|
|
||||||
ALOGE("get ifaceIndexName map fd failed: %s", strerror(errno));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
BpfMapRO<uint32_t, StatsValue> ifaceStatsMap(IFACE_STATS_MAP_PATH);
|
|
||||||
if (!ifaceStatsMap.isValid()) {
|
|
||||||
ret = -errno;
|
|
||||||
ALOGE("get ifaceStats map fd failed: %s", strerror(errno));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return parseBpfNetworkStatsDevInternal(lines, ifaceStatsMap, ifaceIndexNameMap);
|
return parseBpfNetworkStatsDevInternal(lines, ifaceStatsMap, ifaceIndexNameMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user