Loading services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +23 −6 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import static com.android.server.stats.pull.ProcfsMemoryUtil.getProcessCmdlines; import static com.android.server.stats.pull.ProcfsMemoryUtil.readCmdlineFromProcfs; import static com.android.server.stats.pull.ProcfsMemoryUtil.readMemorySnapshotFromProcfs; import static com.android.server.stats.pull.netstats.NetworkStatsUtils.fromPublicNetworkStats; import static com.android.server.stats.pull.netstats.NetworkStatsUtils.isAddEntriesSupported; import static libcore.io.IoUtils.closeQuietly; Loading Loading @@ -1336,14 +1337,22 @@ public class StatsPullAtomService extends SystemService { @NonNull private static NetworkStats removeEmptyEntries(NetworkStats stats) { NetworkStats ret = new NetworkStats(0, 1); final ArrayList<NetworkStats.Entry> entries = new ArrayList<>(); for (NetworkStats.Entry e : stats) { if (e.getRxBytes() != 0 || e.getRxPackets() != 0 || e.getTxBytes() != 0 || e.getTxPackets() != 0 || e.getOperations() != 0) { ret = ret.addEntry(e); entries.add(e); } } return ret; if (isAddEntriesSupported()) { return new NetworkStats(0, entries.size()).addEntries(entries); } else { NetworkStats outputStats = new NetworkStats(0L, 1); for (NetworkStats.Entry e : entries) { outputStats = outputStats.addEntry(e); } return outputStats; } } private void addNetworkStats(int atomTag, @NonNull List<StatsEvent> ret, Loading Loading @@ -1656,11 +1665,19 @@ public class StatsPullAtomService extends SystemService { @NonNull private NetworkStats sliceNetworkStats(@NonNull NetworkStats stats, @NonNull Function<NetworkStats.Entry, NetworkStats.Entry> slicer) { NetworkStats ret = new NetworkStats(0, 1); final ArrayList<NetworkStats.Entry> entries = new ArrayList(); for (NetworkStats.Entry e : stats) { ret = ret.addEntry(slicer.apply(e)); entries.add(slicer.apply(e)); } if (isAddEntriesSupported()) { return new NetworkStats(0, entries.size()).addEntries(entries); } else { NetworkStats outputStats = new NetworkStats(0L, 1); for (NetworkStats.Entry e : entries) { outputStats = outputStats.addEntry(e); } return outputStats; } return ret; } private void registerWifiBytesTransferBackground() { Loading services/core/java/com/android/server/stats/pull/netstats/NetworkStatsUtils.java +19 −3 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ import static android.net.NetworkStats.SET_ALL; import android.app.usage.NetworkStats; import com.android.internal.annotations.VisibleForTesting; import com.android.server.stats.Flags; import java.util.ArrayList; /** * Utility methods for accessing {@link android.net.NetworkStats}. Loading @@ -35,13 +38,22 @@ public class NetworkStatsUtils { */ public static android.net.NetworkStats fromPublicNetworkStats( NetworkStats publiceNetworkStats) { android.net.NetworkStats stats = new android.net.NetworkStats(0L, 0); final ArrayList<android.net.NetworkStats.Entry> entries = new ArrayList<>(); while (publiceNetworkStats.hasNextBucket()) { NetworkStats.Bucket bucket = new NetworkStats.Bucket(); publiceNetworkStats.getNextBucket(bucket); final android.net.NetworkStats.Entry entry = fromBucket(bucket); entries.add(fromBucket(bucket)); } android.net.NetworkStats stats = new android.net.NetworkStats(0L, 1); // The new API is only supported on devices running the mainline version of `NetworkStats`. // It should always be used when available for memory efficiency. if (isAddEntriesSupported()) { stats = stats.addEntries(entries); } else { for (android.net.NetworkStats.Entry entry : entries) { stats = stats.addEntry(entry); } } return stats; } Loading Loading @@ -106,4 +118,8 @@ public class NetworkStatsUtils { } return 0; } public static boolean isAddEntriesSupported() { return Flags.netstatsUseAddEntries(); } } services/core/java/com/android/server/stats/stats_flags.aconfig +14 −0 Original line number Diff line number Diff line package: "com.android.server.stats" container: "system" # Note: To ensure compatibility across all release configurations, initiate the ramp-up process # only after the 'com.android.net.flags.netstats_add_entries' flag has been fully deployed. # This flag provides the necessary API from the Connectivity module. # The flag was added because the flag 'com.android.net.flags.netstats_add_entries' for API # is already being rolled out, and modifying behavior during an active rollout might # lead to unwanted issues. flag { name: "netstats_use_add_entries" namespace: "statsd" description: "Use NetworkStats#addEntries to reduce memory footprint" bug: "335680025" is_fixed_read_only: true } flag { name: "add_mobile_bytes_transfer_by_proc_state_puller" namespace: "statsd" Loading Loading
services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +23 −6 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import static com.android.server.stats.pull.ProcfsMemoryUtil.getProcessCmdlines; import static com.android.server.stats.pull.ProcfsMemoryUtil.readCmdlineFromProcfs; import static com.android.server.stats.pull.ProcfsMemoryUtil.readMemorySnapshotFromProcfs; import static com.android.server.stats.pull.netstats.NetworkStatsUtils.fromPublicNetworkStats; import static com.android.server.stats.pull.netstats.NetworkStatsUtils.isAddEntriesSupported; import static libcore.io.IoUtils.closeQuietly; Loading Loading @@ -1336,14 +1337,22 @@ public class StatsPullAtomService extends SystemService { @NonNull private static NetworkStats removeEmptyEntries(NetworkStats stats) { NetworkStats ret = new NetworkStats(0, 1); final ArrayList<NetworkStats.Entry> entries = new ArrayList<>(); for (NetworkStats.Entry e : stats) { if (e.getRxBytes() != 0 || e.getRxPackets() != 0 || e.getTxBytes() != 0 || e.getTxPackets() != 0 || e.getOperations() != 0) { ret = ret.addEntry(e); entries.add(e); } } return ret; if (isAddEntriesSupported()) { return new NetworkStats(0, entries.size()).addEntries(entries); } else { NetworkStats outputStats = new NetworkStats(0L, 1); for (NetworkStats.Entry e : entries) { outputStats = outputStats.addEntry(e); } return outputStats; } } private void addNetworkStats(int atomTag, @NonNull List<StatsEvent> ret, Loading Loading @@ -1656,11 +1665,19 @@ public class StatsPullAtomService extends SystemService { @NonNull private NetworkStats sliceNetworkStats(@NonNull NetworkStats stats, @NonNull Function<NetworkStats.Entry, NetworkStats.Entry> slicer) { NetworkStats ret = new NetworkStats(0, 1); final ArrayList<NetworkStats.Entry> entries = new ArrayList(); for (NetworkStats.Entry e : stats) { ret = ret.addEntry(slicer.apply(e)); entries.add(slicer.apply(e)); } if (isAddEntriesSupported()) { return new NetworkStats(0, entries.size()).addEntries(entries); } else { NetworkStats outputStats = new NetworkStats(0L, 1); for (NetworkStats.Entry e : entries) { outputStats = outputStats.addEntry(e); } return outputStats; } return ret; } private void registerWifiBytesTransferBackground() { Loading
services/core/java/com/android/server/stats/pull/netstats/NetworkStatsUtils.java +19 −3 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ import static android.net.NetworkStats.SET_ALL; import android.app.usage.NetworkStats; import com.android.internal.annotations.VisibleForTesting; import com.android.server.stats.Flags; import java.util.ArrayList; /** * Utility methods for accessing {@link android.net.NetworkStats}. Loading @@ -35,13 +38,22 @@ public class NetworkStatsUtils { */ public static android.net.NetworkStats fromPublicNetworkStats( NetworkStats publiceNetworkStats) { android.net.NetworkStats stats = new android.net.NetworkStats(0L, 0); final ArrayList<android.net.NetworkStats.Entry> entries = new ArrayList<>(); while (publiceNetworkStats.hasNextBucket()) { NetworkStats.Bucket bucket = new NetworkStats.Bucket(); publiceNetworkStats.getNextBucket(bucket); final android.net.NetworkStats.Entry entry = fromBucket(bucket); entries.add(fromBucket(bucket)); } android.net.NetworkStats stats = new android.net.NetworkStats(0L, 1); // The new API is only supported on devices running the mainline version of `NetworkStats`. // It should always be used when available for memory efficiency. if (isAddEntriesSupported()) { stats = stats.addEntries(entries); } else { for (android.net.NetworkStats.Entry entry : entries) { stats = stats.addEntry(entry); } } return stats; } Loading Loading @@ -106,4 +118,8 @@ public class NetworkStatsUtils { } return 0; } public static boolean isAddEntriesSupported() { return Flags.netstatsUseAddEntries(); } }
services/core/java/com/android/server/stats/stats_flags.aconfig +14 −0 Original line number Diff line number Diff line package: "com.android.server.stats" container: "system" # Note: To ensure compatibility across all release configurations, initiate the ramp-up process # only after the 'com.android.net.flags.netstats_add_entries' flag has been fully deployed. # This flag provides the necessary API from the Connectivity module. # The flag was added because the flag 'com.android.net.flags.netstats_add_entries' for API # is already being rolled out, and modifying behavior during an active rollout might # lead to unwanted issues. flag { name: "netstats_use_add_entries" namespace: "statsd" description: "Use NetworkStats#addEntries to reduce memory footprint" bug: "335680025" is_fixed_read_only: true } flag { name: "add_mobile_bytes_transfer_by_proc_state_puller" namespace: "statsd" Loading