Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48f46ac8 authored by Chenbo Feng's avatar Chenbo Feng Committed by Gerrit Code Review
Browse files

Merge "Use delta reads for per uid traffic stats"

parents 3fc95847 b29a6166
Loading
Loading
Loading
Loading
+26 −9
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ public class NetworkStatsFactory {

    private boolean mUseBpfStats;

    // A persistent Snapshot since device start for eBPF stats
    private final NetworkStats mPersistSnapshot;

    // TODO: only do adjustments in NetworkStatsService and remove this.
    /**
     * (Stacked interface) -> (base interface) association for all connected ifaces since boot.
@@ -135,6 +138,7 @@ public class NetworkStatsFactory {
        mStatsXtIfaceFmt = new File(procRoot, "net/xt_qtaguid/iface_stat_fmt");
        mStatsXtUid = new File(procRoot, "net/xt_qtaguid/stats");
        mUseBpfStats = useBpfStats;
        mPersistSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), -1);
    }

    public NetworkStats readBpfNetworkStatsDev() throws IOException {
@@ -268,6 +272,7 @@ public class NetworkStatsFactory {
        return stats;
    }

    // TODO: delete the lastStats parameter
    private NetworkStats readNetworkStatsDetailInternal(int limitUid, String[] limitIfaces,
            int limitTag, NetworkStats lastStats) throws IOException {
        if (USE_NATIVE_PARSING) {
@@ -278,6 +283,17 @@ public class NetworkStatsFactory {
            } else {
                stats = new NetworkStats(SystemClock.elapsedRealtime(), -1);
            }
            if (mUseBpfStats) {
                if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), UID_ALL,
                        null, TAG_ALL, mUseBpfStats) != 0) {
                    throw new IOException("Failed to parse network stats");
                }
                mPersistSnapshot.setElapsedRealtime(stats.getElapsedRealtime());
                mPersistSnapshot.combineAllValues(stats);
                NetworkStats result = mPersistSnapshot.clone();
                result.filter(limitUid, limitIfaces, limitTag);
                return result;
            } else {
                if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), limitUid,
                        limitIfaces, limitTag, mUseBpfStats) != 0) {
                    throw new IOException("Failed to parse network stats");
@@ -288,6 +304,7 @@ public class NetworkStatsFactory {
                    assertEquals(javaStats, stats);
                }
                return stats;
            }
        } else {
            return javaReadNetworkStatsDetail(mStatsXtUid, limitUid, limitIfaces, limitTag);
        }