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

Commit 1ee9b741 authored by Chenjie Yu's avatar Chenjie Yu
Browse files

pull absolute value for cpu time per frequency.

Test: cts test
Change-Id: I519616905ed8ec6afdaa7e1a0743e279009aa0e5
parent 11954f50
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -1109,14 +1109,10 @@ message IsolatedUidChanged {

/**
 * Pulls Cpu time per frequency.
 * Note: this should be pulled for gauge metric only, without condition.
 * The puller keeps internal state of last values. It should not be pulled by
 * different metrics.
 * The pulled data is delta of cpu time from last pull, calculated as
 * following:
 * if current time is larger than last value, take delta between the two.
 * if current time is smaller than last value, there must be a cpu
 * hotplug event, and the current time is taken as delta.
 * Pulls the time the cpu spend on the frequency index. Frequency index
 * starts from highest to lowest. The value should be monotonically
 * increasing since boot. However, if there is a cpu
 * hotplug event, the value would be reset as well.
 */
message CpuTimePerFreq {
    optional uint32 cluster = 1;
+29 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class KernelCpuSpeedReader {
    private static final String TAG = "KernelCpuSpeedReader";

    private final String mProcFile;
    private final int mNumSpeedSteps;
    private final long[] mLastSpeedTimesMs;
    private final long[] mDeltaSpeedTimesMs;

@@ -50,6 +51,7 @@ public class KernelCpuSpeedReader {
    public KernelCpuSpeedReader(int cpuNumber, int numSpeedSteps) {
        mProcFile = String.format("/sys/devices/system/cpu/cpu%d/cpufreq/stats/time_in_state",
                cpuNumber);
        mNumSpeedSteps = numSpeedSteps;
        mLastSpeedTimesMs = new long[numSpeedSteps];
        mDeltaSpeedTimesMs = new long[numSpeedSteps];
        long jiffyHz = Os.sysconf(OsConstants._SC_CLK_TCK);
@@ -90,4 +92,31 @@ public class KernelCpuSpeedReader {
        }
        return mDeltaSpeedTimesMs;
    }

    /**
     * @return The time (in milliseconds) spent at different cpu speeds. The values should be
     * monotonically increasing, unless the cpu was hotplugged.
     */
    public long[] readAbsolute() {
        StrictMode.ThreadPolicy policy = StrictMode.allowThreadDiskReads();
        long[] speedTimeMs = new long[mNumSpeedSteps];
        try (BufferedReader reader = new BufferedReader(new FileReader(mProcFile))) {
            TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(' ');
            String line;
            int speedIndex = 0;
            while (speedIndex < mNumSpeedSteps && (line = reader.readLine()) != null) {
                splitter.setString(line);
                splitter.next();
                long time = Long.parseLong(splitter.next()) * mJiffyMillis;
                speedTimeMs[speedIndex] = time;
                speedIndex++;
            }
        } catch (IOException e) {
            Slog.e(TAG, "Failed to read cpu-freq: " + e.getMessage());
            Arrays.fill(speedTimeMs, 0);
        } finally {
            StrictMode.setThreadPolicy(policy);
        }
        return speedTimeMs;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -555,7 +555,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
            case StatsLog.CPU_TIME_PER_FREQ: {
                List<StatsLogEventWrapper> ret = new ArrayList();
                for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) {
                    long[] clusterTimeMs = mKernelCpuSpeedReaders[cluster].readDelta();
                    long[] clusterTimeMs = mKernelCpuSpeedReaders[cluster].readAbsolute();
                    if (clusterTimeMs != null) {
                        for (int speed = clusterTimeMs.length - 1; speed >= 0; --speed) {
                            StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, 3);