From 72c8610064292e0dbd1531886b91e8c7e18ac682 Mon Sep 17 00:00:00 2001 From: Misha Wagner Date: Thu, 22 Nov 2018 11:41:37 +0000 Subject: [PATCH 1/2] Remove filtering out frequencies with zero usage for CpuTimePerThreadFreq This was originally included to reduce the amount of data reported. As we now bucket the frequencies collected (ag/5327120), this is not needed. Test: build, flash, run unit tests, manual inspection. Change-Id: Iba86e8e3c3926301dae4d4d8320a8450874f0b11 --- .../java/com/android/server/stats/StatsCompanionService.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/services/core/java/com/android/server/stats/StatsCompanionService.java b/services/core/java/com/android/server/stats/StatsCompanionService.java index aa11e1e3285c0..08147cfea12ad 100644 --- a/services/core/java/com/android/server/stats/StatsCompanionService.java +++ b/services/core/java/com/android/server/stats/StatsCompanionService.java @@ -1668,11 +1668,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { } for (int k = 0; k < threadCpuUsage.usageTimesMillis.length; k++) { - // Do not report CPU usage at a frequency when it's zero - if (threadCpuUsage.usageTimesMillis[k] == 0) { - continue; - } - StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); e.writeInt(processCpuUsage.uid); From fde6958b8b4858a168fa72c8de4355547b072c20 Mon Sep 17 00:00:00 2001 From: Misha Wagner Date: Wed, 28 Nov 2018 13:26:32 +0000 Subject: [PATCH 2/2] Change CpuTimePerThreadFreq to contain all frequencies in one atom Test: make, flash, inspect pull-source output Bug: 120016054 Change-Id: I56de3aec85d5f82339eb4eb876a1349d66698a63 --- cmds/statsd/src/atoms.proto | 25 ++++++++++++++++--- .../src/external/StatsPullerManager.cpp | 2 +- .../server/stats/StatsCompanionService.java | 24 +++++++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index c8405a279f7de..7f88136d7eb57 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -3331,10 +3331,27 @@ message CpuTimePerThreadFreq { optional string process_name = 4; // Name of the thread taken from `/proc/$PID/task/$TID/comm` optional string thread_name = 5; - // What frequency the CPU was running at, in KHz - optional int32 frequency_khz = 6; - // Time spent in frequency in milliseconds, since thread start. - optional int32 time_millis = 7; + + // Report eight different frequencies, and how much time is spent in each frequency. Frequencies + // are given in KHz, and time is given in milliseconds since the thread started. All eight + // frequencies are given here as the alternative is sending eight separate atoms. This method + // significantly reduces the amount of data created + optional int32 frequency1_khz = 6; + optional int32 time1_millis = 7; + optional int32 frequency2_khz = 8; + optional int32 time2_millis = 9; + optional int32 frequency3_khz = 10; + optional int32 time3_millis = 11; + optional int32 frequency4_khz = 12; + optional int32 time4_millis = 13; + optional int32 frequency5_khz = 14; + optional int32 time5_millis = 15; + optional int32 frequency6_khz = 16; + optional int32 time6_millis = 17; + optional int32 frequency7_khz = 18; + optional int32 time7_millis = 19; + optional int32 frequency8_khz = 20; + optional int32 time8_millis = 21; } /** diff --git a/cmds/statsd/src/external/StatsPullerManager.cpp b/cmds/statsd/src/external/StatsPullerManager.cpp index f9b79823741b3..c070ca375d74e 100644 --- a/cmds/statsd/src/external/StatsPullerManager.cpp +++ b/cmds/statsd/src/external/StatsPullerManager.cpp @@ -210,7 +210,7 @@ const std::map StatsPullerManager::kAllPullAtomInfo = { 5 * NS_PER_SEC /* min cool-down in seconds*/, new StatsCompanionServicePuller(android::util::PROCESS_CPU_TIME)}}, {android::util::CPU_TIME_PER_THREAD_FREQ, - {{7}, + {{7, 9, 11, 13, 15, 17, 19, 21}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::CPU_TIME_PER_THREAD_FREQ)}}, // DeviceCalculatedPowerUse. diff --git a/services/core/java/com/android/server/stats/StatsCompanionService.java b/services/core/java/com/android/server/stats/StatsCompanionService.java index 08147cfea12ad..60485d0da66d6 100644 --- a/services/core/java/com/android/server/stats/StatsCompanionService.java +++ b/services/core/java/com/android/server/stats/StatsCompanionService.java @@ -201,6 +201,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { // "zygote64", }; + private static final int CPU_TIME_PER_THREAD_FREQ_NUM_FREQUENCIES = 8; static final class CompanionHandler extends Handler { CompanionHandler(Looper looper) { @@ -1654,6 +1655,11 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { return; } int[] cpuFrequencies = mKernelCpuThreadReader.getCpuFrequenciesKhz(); + if (cpuFrequencies.length != CPU_TIME_PER_THREAD_FREQ_NUM_FREQUENCIES) { + Slog.w(TAG, "Expected " + CPU_TIME_PER_THREAD_FREQ_NUM_FREQUENCIES + + " frequencies, but got " + cpuFrequencies.length); + return; + } for (int i = 0; i < processCpuUsages.size(); i++) { KernelCpuThreadReader.ProcessCpuUsage processCpuUsage = processCpuUsages.get(i); ArrayList threadCpuUsages = @@ -1667,18 +1673,18 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { continue; } - for (int k = 0; k < threadCpuUsage.usageTimesMillis.length; k++) { - StatsLogEventWrapper e = - new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); - e.writeInt(processCpuUsage.uid); - e.writeInt(processCpuUsage.processId); - e.writeInt(threadCpuUsage.threadId); - e.writeString(processCpuUsage.processName); - e.writeString(threadCpuUsage.threadName); + StatsLogEventWrapper e = + new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); + e.writeInt(processCpuUsage.uid); + e.writeInt(processCpuUsage.processId); + e.writeInt(threadCpuUsage.threadId); + e.writeString(processCpuUsage.processName); + e.writeString(threadCpuUsage.threadName); + for (int k = 0; k < CPU_TIME_PER_THREAD_FREQ_NUM_FREQUENCIES; k++) { e.writeInt(cpuFrequencies[k]); e.writeInt(threadCpuUsage.usageTimesMillis[k]); - pulledData.add(e); } + pulledData.add(e); } } }