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

Commit b5a29958 authored by Adam Lesinski's avatar Adam Lesinski Committed by Android Git Automerger
Browse files

am 1e9352ae: am b99e6d69: Merge "Parse uid_cputime proc file" into mnc-dev

* commit '1e9352ae':
  Parse uid_cputime proc file
parents 1b9560e2 1e9352ae
Loading
Loading
Loading
Loading
+28 −9
Original line number Diff line number Diff line
@@ -425,6 +425,24 @@ public abstract class BatteryStats implements Parcelable {
        public abstract long getMobileRadioActiveTime(int which);
        public abstract int getMobileRadioActiveCount(int which);

        /**
         * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
         */
        public abstract long getUserCpuTimeUs(int which);

        /**
         * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
         */
        public abstract long getSystemCpuTimeUs(int which);

        /**
         * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
         * @param speedStep the index of the CPU speed. This is not the actual speed of the CPU.
         * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
         * @see BatteryStats#getCpuSpeedSteps()
         */
        public abstract long getTimeAtCpuSpeed(int step, int which);

        public static abstract class Sensor {
            /*
             * FIXME: it's not correct to use this magic value because it
@@ -506,15 +524,6 @@ public abstract class BatteryStats implements Parcelable {
             */
            public abstract long getForegroundTime(int which);

            /**
             * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
             * @param speedStep the index of the CPU speed. This is not the actual speed of the
             * CPU.
             * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
             * @see BatteryStats#getCpuSpeedSteps()
             */
            public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);

            public abstract int countExcessivePowers();

            public abstract ExcessivePower getExcessivePower(int i);
@@ -3873,6 +3882,16 @@ public abstract class BatteryStats implements Parcelable {
                }
            }

            final long userCpuTimeUs = u.getUserCpuTimeUs(which);
            final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
            if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
                sb.setLength(0);
                sb.append(prefix);
                sb.append("    Total cpu time: ");
                formatTimeMs(sb, (userCpuTimeUs + systemCpuTimeUs) / 1000);
                pw.println(sb.toString());
            }

            final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
                    = u.getProcessStats();
            for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
+0 −1
Original line number Diff line number Diff line
@@ -742,7 +742,6 @@ public final class BatteryStatsHelper {
                    parcel.setDataPosition(0);
                    BatteryStatsImpl stats = com.android.internal.os.BatteryStatsImpl.CREATOR
                            .createFromParcel(parcel);
                    stats.distributeWorkLocked(BatteryStats.STATS_SINCE_CHARGED);
                    return stats;
                } catch (IOException e) {
                    Log.w(TAG, "Unable to read statistics stream", e);
+134 −159

File changed.

Preview size limit exceeded, changes collapsed.

+36 −34

File changed.

Preview size limit exceeded, changes collapsed.

+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.os;

import android.text.TextUtils;
import android.util.Slog;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;

/**
 * Reads CPU time spent at various frequencies and provides a delta from the last call to
 * {@link #readDelta}. Each line in the proc file has the format:
 *
 * freq time
 *
 * where time is measured in 1/100 seconds.
 */
public class KernelCpuSpeedReader {
    private static final String TAG = "KernelCpuSpeedReader";
    private static final String sProcFile =
            "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state";
    private static final int MAX_SPEEDS = 60;

    private long[] mLastSpeedTimes = new long[MAX_SPEEDS];
    private long[] mDeltaSpeedTimes = new long[MAX_SPEEDS];

    /**
     * The returned array is modified in subsequent calls to {@link #readDelta}.
     * @return The time (in milliseconds) spent at different cpu speeds since the last call to
     * {@link #readDelta}.
     */
    public long[] readDelta() {
        try (BufferedReader reader = new BufferedReader(new FileReader(sProcFile))) {
            TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(' ');
            String line;
            int speedIndex = 0;
            while ((line = reader.readLine()) != null) {
                splitter.setString(line);
                Long.parseLong(splitter.next());

                // The proc file reports time in 1/100 sec, so convert to milliseconds.
                long time = Long.parseLong(splitter.next()) * 10;
                mDeltaSpeedTimes[speedIndex] = time - mLastSpeedTimes[speedIndex];
                mLastSpeedTimes[speedIndex] = time;
                speedIndex++;
            }
        } catch (IOException e) {
            Slog.e(TAG, "Failed to read cpu-freq", e);
            Arrays.fill(mDeltaSpeedTimes, 0);
        }
        return mDeltaSpeedTimes;
    }
}
Loading