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

Commit 11702d2c authored by ELIYAZ MOMIN (xWF)'s avatar ELIYAZ MOMIN (xWF) Committed by Android (Google) Code Review
Browse files

Revert "Account for interpolation loss in cumulative network stats"

This reverts commit 68c8ddab.

Reason for revert: <Potential culprit for b/376773905  - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.>

Change-Id: Ia7a3d1cdb0e9afb86c527464a8ecdecf2248bfb7
parent 68c8ddab
Loading
Loading
Loading
Loading
+4 −20
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.stats.pull.netstats;
import android.annotation.NonNull;
import android.net.NetworkStats;
import android.net.NetworkTemplate;
import android.util.Log;

import java.util.Objects;

@@ -34,7 +33,6 @@ import java.util.Objects;
 */
public class NetworkStatsAccumulator {

    private static final String TAG = "NetworkStatsAccumulator";
    private final NetworkTemplate mTemplate;
    private final boolean mWithTags;
    private final long mBucketDurationMillis;
@@ -59,9 +57,8 @@ public class NetworkStatsAccumulator {
    @NonNull
    public NetworkStats queryStats(long currentTimeMillis,
            @NonNull StatsQueryFunction queryFunction) {
        NetworkStats completeStats = snapshotPlusFollowingStats(currentTimeMillis, queryFunction);
        maybeExpandSnapshot(currentTimeMillis, completeStats, queryFunction);
        return completeStats;
        maybeExpandSnapshot(currentTimeMillis, queryFunction);
        return snapshotPlusFollowingStats(currentTimeMillis, queryFunction);
    }

    /**
@@ -75,28 +72,15 @@ public class NetworkStatsAccumulator {
     * Expands the internal cumulative stats snapshot, if possible, by querying NetworkStats.
     */
    private void maybeExpandSnapshot(long currentTimeMillis,
            NetworkStats completeStatsUntilCurrentTime,
            @NonNull StatsQueryFunction queryFunction) {
        // Update snapshot only if it is possible to expand it by at least one full bucket, and only
        // if the new snapshot's end is not in the active bucket.
        long newEndTimeMillis = currentTimeMillis - mBucketDurationMillis;
        if (newEndTimeMillis - mSnapshotEndTimeMillis > mBucketDurationMillis) {
            Log.v(TAG,
                    "Expanding snapshot (mTemplate=" + mTemplate + ", mWithTags=" + mWithTags
                            + ") from " + mSnapshotEndTimeMillis + " to " + newEndTimeMillis
                            + " at " + currentTimeMillis);
            NetworkStats extraStats = queryFunction.queryNetworkStats(
                    mTemplate, mWithTags, mSnapshotEndTimeMillis, newEndTimeMillis);
            NetworkStats extraStats = queryFunction.queryNetworkStats(mTemplate, mWithTags,
                    mSnapshotEndTimeMillis, newEndTimeMillis);
            mSnapshot = mSnapshot.add(extraStats);
            mSnapshotEndTimeMillis = newEndTimeMillis;

            // NetworkStats queries interpolate historical data using integers maths, which makes
            // queries non-transitive: Query(t0, t1) + Query(t1, t2) <= Query(t0, t2).
            // Compute interpolation data loss from moving the snapshot's end-point, and add it to
            // the snapshot to avoid under-counting.
            NetworkStats newStats = snapshotPlusFollowingStats(currentTimeMillis, queryFunction);
            NetworkStats interpolationLoss = completeStatsUntilCurrentTime.subtract(newStats);
            mSnapshot = mSnapshot.add(interpolationLoss);
        }
    }