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

Commit 334899b0 authored by Rajeev Kumar's avatar Rajeev Kumar Committed by Android (Google) Code Review
Browse files

Merge "Implement atom puller for ProcessMemoryState."

parents c076dcd4 22d92b76
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -115,7 +115,10 @@ const std::map<int, PullAtomInfo> StatsPullerManagerImpl::kAllPullAtomInfo = {
         {{}, {}, 1, new ResourceHealthManagerPuller(android::util::REMAINING_BATTERY_CAPACITY)}},
        // full_battery_capacity
        {android::util::FULL_BATTERY_CAPACITY,
         {{}, {}, 1, new ResourceHealthManagerPuller(android::util::FULL_BATTERY_CAPACITY)}}};
         {{}, {}, 1, new ResourceHealthManagerPuller(android::util::FULL_BATTERY_CAPACITY)}},
        // process_memory_state
        {android::util::PROCESS_MEMORY_STATE,
         {{4,5,6,7,8}, {2,3}, 0, new StatsCompanionServicePuller(android::util::PROCESS_MEMORY_STATE)}}};

StatsPullerManagerImpl::StatsPullerManagerImpl()
    : mCurrentPullingInterval(LONG_MAX) {
+5 −0
Original line number Diff line number Diff line
@@ -356,4 +356,9 @@ public abstract class ActivityManagerInternal {
     * Whether an UID is active or idle.
     */
    public abstract boolean isUidActive(int uid);

    /**
     * Returns a list that contains the memory stats for currently running processes.
     */
    public abstract List<ProcessMemoryState> getMemoryStateForProcesses();
}
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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 android.app;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * The memory stats for a process.
 * {@hide}
 */
public class ProcessMemoryState implements Parcelable {
    public int uid;
    public String processName;
    public int oomScore;
    public long pgfault;
    public long pgmajfault;
    public long rssInBytes;
    public long cacheInBytes;
    public long swapInBytes;

    public ProcessMemoryState(int uid, String processName, int oomScore, long pgfault,
                              long pgmajfault, long rssInBytes, long cacheInBytes,
                              long swapInBytes) {
        this.uid = uid;
        this.processName = processName;
        this.oomScore = oomScore;
        this.pgfault = pgfault;
        this.pgmajfault = pgmajfault;
        this.rssInBytes = rssInBytes;
        this.cacheInBytes = cacheInBytes;
        this.swapInBytes = swapInBytes;
    }

    private ProcessMemoryState(Parcel in) {
        uid = in.readInt();
        processName = in.readString();
        oomScore = in.readInt();
        pgfault = in.readLong();
        pgmajfault = in.readLong();
        rssInBytes = in.readLong();
        cacheInBytes = in.readLong();
        swapInBytes = in.readLong();
    }

    public static final Creator<ProcessMemoryState> CREATOR = new Creator<ProcessMemoryState>() {
        @Override
        public ProcessMemoryState createFromParcel(Parcel in) {
            return new ProcessMemoryState(in);
        }

        @Override
        public ProcessMemoryState[] newArray(int size) {
            return new ProcessMemoryState[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(uid);
        parcel.writeString(processName);
        parcel.writeInt(oomScore);
        parcel.writeLong(pgfault);
        parcel.writeLong(pgmajfault);
        parcel.writeLong(rssInBytes);
        parcel.writeLong(cacheInBytes);
        parcel.writeLong(swapInBytes);
    }
}
+30 −0
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS
import static com.android.server.am.ActivityStackSupervisor.ON_TOP;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.am.ActivityStackSupervisor.REMOVE_FROM_RECENTS;
import static com.android.server.am.MemoryStatUtil.readMemoryStatFromMemcg;
import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT;
@@ -248,6 +249,7 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.PictureInPictureParams;
import android.app.ProcessMemoryState;
import android.app.ProfilerInfo;
import android.app.RemoteAction;
import android.app.WaitResult;
@@ -436,6 +438,7 @@ import com.android.server.SystemServiceManager;
import com.android.server.ThreadPriorityBooster;
import com.android.server.Watchdog;
import com.android.server.am.ActivityStack.ActivityState;
import com.android.server.am.MemoryStatUtil.MemoryStat;
import com.android.server.am.proto.ActivityManagerServiceProto;
import com.android.server.am.proto.BroadcastProto;
import com.android.server.am.proto.GrantUriProto;
@@ -26097,6 +26100,33 @@ public class ActivityManagerService extends IActivityManager.Stub
                return (uidRec != null) && !uidRec.idle;
            }
        }
        @Override
        public List<ProcessMemoryState> getMemoryStateForProcesses() {
            List<ProcessMemoryState> processMemoryStates = new ArrayList<>();
            synchronized (mPidsSelfLocked) {
                for (int i = 0, size = mPidsSelfLocked.size(); i < size; i++) {
                    final ProcessRecord r = mPidsSelfLocked.valueAt(i);
                    final int pid = r.pid;
                    final int uid = r.uid;
                    final MemoryStat memoryStat = readMemoryStatFromMemcg(uid, pid);
                    if (memoryStat == null) {
                        continue;
                    }
                    ProcessMemoryState processMemoryState =
                            new ProcessMemoryState(uid,
                                    r.processName,
                                    r.maxAdj,
                                    memoryStat.pgfault,
                                    memoryStat.pgmajfault,
                                    memoryStat.rssInBytes,
                                    memoryStat.cacheInBytes,
                                    memoryStat.swapInBytes);
                    processMemoryStates.add(processMemoryState);
                }
            }
            return processMemoryStates;
        }
    }
    /**
+6 −4
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import com.android.internal.annotations.VisibleForTesting;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -52,8 +52,9 @@ final class MemoryStatUtil {
    /**
     * Reads memory.stat of a process from memcg.
     */
    static @Nullable MemoryStat readMemoryStatFromMemcg(int uid, int pid) {
        final String memoryStatPath = String.format(MEMORY_STAT_FILE_FMT, uid, pid);
    @Nullable
    static MemoryStat readMemoryStatFromMemcg(int uid, int pid) {
        final String memoryStatPath = String.format(Locale.US, MEMORY_STAT_FILE_FMT, uid, pid);
        final File memoryStatFile = new File(memoryStatPath);
        if (!memoryStatFile.exists()) {
            if (DEBUG_METRICS) Slog.i(TAG, memoryStatPath + " not found");
@@ -74,7 +75,8 @@ final class MemoryStatUtil {
     * Parses relevant statistics out from the contents of a memory.stat file in memcg.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    static @Nullable MemoryStat parseMemoryStat(String memoryStatContents) {
    @Nullable
    static MemoryStat parseMemoryStat(String memoryStatContents) {
        MemoryStat memoryStat = new MemoryStat();
        if (memoryStatContents == null) {
            return memoryStat;
Loading