From 78c3f99268311b248bb30feeb344a4f5d2a7a607 Mon Sep 17 00:00:00 2001 From: Richard Gaywood Date: Tue, 23 Jun 2020 17:12:49 +0100 Subject: [PATCH] Add shard ID to statsd atom for procstats collection Without this, RANDOM_ONE_SAMPLE would result in statsd dropping all bar the first shard. Adding the shard id as a dimension field preserves all the data. Bug: 158294266 Test: manual build & test Change-Id: I94ffb610ef3651f460600e3df6b32c87fc430594 --- cmds/statsd/src/atoms.proto | 4 ++++ .../server/stats/pull/StatsPullAtomService.java | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index a5f0ac97cebc6..ca03343ddb801 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -6131,6 +6131,10 @@ message ProcessStatsAvailablePagesProto { */ message ProcStats { optional ProcessStatsSectionProto proc_stats_section = 1; + // Data pulled from device into this is sometimes sharded across multiple atoms to work around + // a size limit. When this happens, this shard ID will contain an increasing 1-indexed integer + // with the number of this shard. + optional int32 shard_id = 2; } /** diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java index 09fd33d5b4ed4..dbdef2368c7c1 100644 --- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java +++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java @@ -2575,11 +2575,17 @@ public class StatsPullAtomService extends SystemService { lastHighWaterMark, section, true, statsFiles, procStats); procStats.dumpAggregatedProtoForStatsd(protoStreams, MAX_PROCSTATS_RAW_SHARD_SIZE); - for (ProtoOutputStream proto : protoStreams) { - if (proto.getBytes().length > 0) { + for (int i = 0; i < protoStreams.length; i++) { + byte[] bytes = protoStreams[i].getBytes(); // cache the value + if (bytes.length > 0) { StatsEvent e = StatsEvent.newBuilder() .setAtomId(atomTag) - .writeByteArray(proto.getBytes()) + .writeByteArray(bytes) + // This is a shard ID, and is specified in the metric definition to be + // a dimension. This will result in statsd using RANDOM_ONE_SAMPLE to + // keep all the shards, as it thinks each shard is a different dimension + // of data. + .writeInt(i) .build(); pulledData.add(e); }