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

Commit 8df86ad4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "AppProfiler: don't hold lock for CPU times" into udc-dev am: 627b877c

parents 80c83691 627b877c
Loading
Loading
Loading
Loading
+13 −21
Original line number Diff line number Diff line
@@ -80,10 +80,6 @@ public class ProcessCpuTracker {
    /** Stores user time and system time in jiffies. */
    private final long[] mProcessStatsData = new long[4];

    /** Stores user time and system time in jiffies.  Used for
     * public API to retrieve CPU use for a process.  Must lock while in use. */
    private final long[] mSinglePidStatsData = new long[4];

    private static final int[] PROCESS_FULL_STATS_FORMAT = new int[] {
        PROC_SPACE_TERM,
        PROC_SPACE_TERM|PROC_PARENS|PROC_OUT_STRING,    // 2: name
@@ -629,9 +625,8 @@ public class ProcessCpuTracker {
     * executing in both user and system code. Safe to call without lock held.
     */
    public long getCpuTimeForPid(int pid) {
        synchronized (mSinglePidStatsData) {
        final String statFile = "/proc/" + pid + "/stat";
            final long[] statsData = mSinglePidStatsData;
        final long[] statsData = new long[4];
        if (Process.readProcFile(statFile, PROCESS_STATS_FORMAT,
                null, statsData, null)) {
            long time = statsData[PROCESS_STAT_UTIME]
@@ -640,23 +635,20 @@ public class ProcessCpuTracker {
        }
        return 0;
    }
    }

    /**
     * Returns the total time (in milliseconds) the given PID has spent waiting
     * in the runqueue. Safe to call without lock held.
     */
    public long getCpuDelayTimeForPid(int pid) {
        synchronized (mSinglePidStatsData) {
        final String statFile = "/proc/" + pid + "/schedstat";
            final long[] statsData = mSinglePidStatsData;
        final long[] statsData = new long[4];
        if (Process.readProcFile(statFile, PROCESS_SCHEDSTATS_FORMAT,
                null, statsData, null)) {
            return statsData[PROCESS_SCHEDSTAT_CPU_DELAY_TIME] / 1_000_000;
        }
        return 0;
    }
    }

    /**
     * @return time in milliseconds.
+2 −6
Original line number Diff line number Diff line
@@ -1892,16 +1892,12 @@ public class AppProfiler {
    }

    long getCpuTimeForPid(int pid) {
        synchronized (mProcessCpuTracker) {
        return mProcessCpuTracker.getCpuTimeForPid(pid);
    }
    }

    long getCpuDelayTimeForPid(int pid) {
        synchronized (mProcessCpuTracker) {
        return mProcessCpuTracker.getCpuDelayTimeForPid(pid);
    }
    }

    List<ProcessCpuTracker.Stats> getCpuStats(Predicate<ProcessCpuTracker.Stats> predicate) {
        synchronized (mProcessCpuTracker) {