diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 8567ff2fa5dde..d77d0a8e300ac 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -3326,10 +3326,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 39b12c279a7a3..21adc47b1e306 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,23 +1673,18 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { continue; } - 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); - 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); } } }