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

Commit 59182b3b authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge changes from topic "oct3"

* changes:
  BroadcastQueue: periodic internal health check.
  BroadcastQueue: mark dump methods @NeverCompile.
  More tests for BroadcastRecord.
  Relax broadcast ANR timeouts based on run_delay.
  BroadcastQueue: more debugging information.
  BroadcastQueue: add support for wait-for-barrier.
  BroadcastQueue: add support for REPLACE_PENDING.
  BroadcastQueue: add support for priority tranches.
parents c62b8283 620bd16a
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -119,6 +119,14 @@ public class ProcessCpuTracker {
    private final String[] mProcessFullStatsStringData = new String[6];
    private final long[] mProcessFullStatsData = new long[6];

    private static final int[] PROCESS_SCHEDSTATS_FORMAT = new int[] {
            PROC_SPACE_TERM|PROC_OUT_LONG,
            PROC_SPACE_TERM|PROC_OUT_LONG,
    };

    static final int PROCESS_SCHEDSTAT_CPU_TIME = 0;
    static final int PROCESS_SCHEDSTAT_CPU_DELAY_TIME = 1;

    private static final int[] SYSTEM_CPU_FORMAT = new int[] {
        PROC_SPACE_TERM|PROC_COMBINE,
        PROC_SPACE_TERM|PROC_OUT_LONG,                  // 1: user time
@@ -617,8 +625,8 @@ public class ProcessCpuTracker {
    }

    /**
     * Returns the total time (in milliseconds) spent executing in
     * both user and system code.  Safe to call without lock held.
     * Returns the total time (in milliseconds) the given PID has spent
     * executing in both user and system code. Safe to call without lock held.
     */
    public long getCpuTimeForPid(int pid) {
        synchronized (mSinglePidStatsData) {
@@ -634,6 +642,22 @@ public class ProcessCpuTracker {
        }
    }

    /**
     * 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;
            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.
     */
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 static com.google.common.truth.Truth.assertThat;

import androidx.test.filters.SmallTest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@SmallTest
@RunWith(JUnit4.class)
public class ProcessCpuTrackerTest {
    @Test
    public void testGetCpuTime() throws Exception {
        final ProcessCpuTracker tracker = new ProcessCpuTracker(false);
        assertThat(tracker.getCpuTimeForPid(android.os.Process.myPid())).isGreaterThan(0L);
    }

    @Test
    public void testGetCpuDelayTime() throws Exception {
        final ProcessCpuTracker tracker = new ProcessCpuTracker(false);
        assertThat(tracker.getCpuDelayTimeForPid(android.os.Process.myPid())).isGreaterThan(0L);
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -34,7 +34,15 @@ public abstract class DropBoxManagerInternal {
     * to dynamically generate the entry contents.
     */
    public interface EntrySource extends Closeable {
        public @BytesLong long length();
        public void writeTo(@NonNull FileDescriptor fd) throws IOException;

        public default @BytesLong long length() {
            // By default, length is unknown
            return 0;
        }

        public default void close() throws IOException {
            // By default, no resources to close
        }
    }
}
+8 −3
Original line number Diff line number Diff line
@@ -2441,8 +2441,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mEnableOffloadQueue = SystemProperties.getBoolean(
                "persist.device_config.activity_manager_native_boot.offload_queue_enabled", true);
        mEnableModernQueue = SystemProperties.getBoolean(
                "persist.device_config.activity_manager_native_boot.modern_queue_enabled", false);
        mEnableModernQueue = foreConstants.MODERN_QUEUE_ENABLED;
        if (mEnableModernQueue) {
            mBroadcastQueues = new BroadcastQueue[1];
@@ -10697,8 +10696,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    @NeverCompile
    void dumpBroadcastsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
            int opti, boolean dumpAll, String dumpPackage) {
        boolean dumpConstants = true;
        boolean dumpHistory = true;
        boolean needSep = false;
        boolean onlyHistory = false;
        boolean printedAnything = false;
@@ -10783,7 +10785,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (!onlyReceivers) {
            for (BroadcastQueue q : mBroadcastQueues) {
                needSep = q.dumpLocked(fd, pw, args, opti, dumpAll, dumpPackage, needSep);
                needSep = q.dumpLocked(fd, pw, args, opti,
                        dumpConstants, dumpHistory, dumpAll, dumpPackage, needSep);
                printedAnything |= needSep;
            }
        }
@@ -10841,6 +10844,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    @NeverCompile
    void dumpBroadcastStatsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
            int opti, boolean dumpAll, String dumpPackage) {
        if (mCurBroadcastStats == null) {
@@ -10874,6 +10878,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    @NeverCompile
    void dumpBroadcastStatsCheckinLocked(FileDescriptor fd, PrintWriter pw, String[] args,
            int opti, boolean fullCheckin, String dumpPackage) {
        if (mCurBroadcastStats == null) {
+6 −0
Original line number Diff line number Diff line
@@ -1892,6 +1892,12 @@ public class AppProfiler {
        }
    }

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

    List<ProcessCpuTracker.Stats> getCpuStats(Predicate<ProcessCpuTracker.Stats> predicate) {
        synchronized (mProcessCpuTracker) {
            return mProcessCpuTracker.getStats(st -> predicate.test(st));
Loading