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

Commit 4470d5ea authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clean up the procstats dump enums and change component to use message."

parents c7483a0e 676d1ace
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -9451,7 +9451,7 @@ public class Intent implements Parcelable, Cloneable {
            proto.write(IntentProto.PACKAGE, mPackage);
        }
        if (comp && mComponent != null) {
            proto.write(IntentProto.COMPONENT, mComponent.flattenToShortString());
            mComponent.writeToProto(proto, IntentProto.COMPONENT);
        }
        if (mSourceBounds != null) {
            proto.write(IntentProto.SOURCE_BOUNDS, mSourceBounds.toShortString());
+90 −46
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.Parcelable;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.service.procstats.ProcessStatsProto;
import android.text.format.DateFormat;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -46,12 +47,77 @@ import java.util.Objects;
 * Utilities for dumping.
 */
public final class DumpUtils {
    public static final String[] STATE_NAMES = new String[] {
            "Persist", "Top    ", "ImpFg  ", "ImpBg  ",
            "Backup ", "HeavyWt", "Service", "ServRst",
            "Receivr", "Home   ",
            "LastAct", "CchAct ", "CchCAct", "CchEmty"
    };
    public static final String[] STATE_NAMES;
    public static final String[] STATE_NAMES_CSV;
    static final String[] STATE_TAGS;
    static final int[] STATE_PROTO_ENUMS;

    // Make the mapping easy to update.
    static {
        STATE_NAMES = new String[STATE_COUNT];
        STATE_NAMES[STATE_PERSISTENT] = "Persist";
        STATE_NAMES[STATE_TOP] = "Top";
        STATE_NAMES[STATE_IMPORTANT_FOREGROUND] = "ImpFg";
        STATE_NAMES[STATE_IMPORTANT_BACKGROUND] = "ImpBg";
        STATE_NAMES[STATE_BACKUP] = "Backup";
        STATE_NAMES[STATE_SERVICE] = "Service";
        STATE_NAMES[STATE_SERVICE_RESTARTING] = "ServRst";
        STATE_NAMES[STATE_RECEIVER] = "Receivr";
        STATE_NAMES[STATE_HEAVY_WEIGHT] = "HeavyWt";
        STATE_NAMES[STATE_HOME] = "Home";
        STATE_NAMES[STATE_LAST_ACTIVITY] = "LastAct";
        STATE_NAMES[STATE_CACHED_ACTIVITY] = "CchAct";
        STATE_NAMES[STATE_CACHED_ACTIVITY_CLIENT] = "CchCAct";
        STATE_NAMES[STATE_CACHED_EMPTY] = "CchEmty";

        STATE_NAMES_CSV = new String[STATE_COUNT];
        STATE_NAMES_CSV[STATE_PERSISTENT] = "pers";
        STATE_NAMES_CSV[STATE_TOP] = "top";
        STATE_NAMES_CSV[STATE_IMPORTANT_FOREGROUND] = "impfg";
        STATE_NAMES_CSV[STATE_IMPORTANT_BACKGROUND] = "impbg";
        STATE_NAMES_CSV[STATE_BACKUP] = "backup";
        STATE_NAMES_CSV[STATE_SERVICE] = "service";
        STATE_NAMES_CSV[STATE_SERVICE_RESTARTING] = "service-rs";
        STATE_NAMES_CSV[STATE_RECEIVER] = "receiver";
        STATE_NAMES_CSV[STATE_HEAVY_WEIGHT] = "heavy";
        STATE_NAMES_CSV[STATE_HOME] = "home";
        STATE_NAMES_CSV[STATE_LAST_ACTIVITY] = "lastact";
        STATE_NAMES_CSV[STATE_CACHED_ACTIVITY] = "cch-activity";
        STATE_NAMES_CSV[STATE_CACHED_ACTIVITY_CLIENT] = "cch-aclient";
        STATE_NAMES_CSV[STATE_CACHED_EMPTY] = "cch-empty";

        STATE_TAGS = new String[STATE_COUNT];
        STATE_TAGS[STATE_PERSISTENT] = "p";
        STATE_TAGS[STATE_TOP] = "t";
        STATE_TAGS[STATE_IMPORTANT_FOREGROUND] = "f";
        STATE_TAGS[STATE_IMPORTANT_BACKGROUND] = "b";
        STATE_TAGS[STATE_BACKUP] = "u";
        STATE_TAGS[STATE_SERVICE] = "s";
        STATE_TAGS[STATE_SERVICE_RESTARTING] = "x";
        STATE_TAGS[STATE_RECEIVER] = "r";
        STATE_TAGS[STATE_HEAVY_WEIGHT] = "w";
        STATE_TAGS[STATE_HOME] = "h";
        STATE_TAGS[STATE_LAST_ACTIVITY] = "l";
        STATE_TAGS[STATE_CACHED_ACTIVITY] = "a";
        STATE_TAGS[STATE_CACHED_ACTIVITY_CLIENT] = "c";
        STATE_TAGS[STATE_CACHED_EMPTY] = "e";

        STATE_PROTO_ENUMS = new int[STATE_COUNT];
        STATE_PROTO_ENUMS[STATE_PERSISTENT] = ProcessStatsProto.State.PERSISTENT;
        STATE_PROTO_ENUMS[STATE_TOP] = ProcessStatsProto.State.TOP;
        STATE_PROTO_ENUMS[STATE_IMPORTANT_FOREGROUND] = ProcessStatsProto.State.IMPORTANT_FOREGROUND;
        STATE_PROTO_ENUMS[STATE_IMPORTANT_BACKGROUND] = ProcessStatsProto.State.IMPORTANT_BACKGROUND;
        STATE_PROTO_ENUMS[STATE_BACKUP] = ProcessStatsProto.State.BACKUP;
        STATE_PROTO_ENUMS[STATE_SERVICE] = ProcessStatsProto.State.SERVICE;
        STATE_PROTO_ENUMS[STATE_SERVICE_RESTARTING] = ProcessStatsProto.State.SERVICE_RESTARTING;
        STATE_PROTO_ENUMS[STATE_RECEIVER] = ProcessStatsProto.State.RECEIVER;
        STATE_PROTO_ENUMS[STATE_HEAVY_WEIGHT] = ProcessStatsProto.State.HEAVY_WEIGHT;
        STATE_PROTO_ENUMS[STATE_HOME] = ProcessStatsProto.State.HOME;
        STATE_PROTO_ENUMS[STATE_LAST_ACTIVITY] = ProcessStatsProto.State.LAST_ACTIVITY;
        STATE_PROTO_ENUMS[STATE_CACHED_ACTIVITY] = ProcessStatsProto.State.CACHED_ACTIVITY;
        STATE_PROTO_ENUMS[STATE_CACHED_ACTIVITY_CLIENT] = ProcessStatsProto.State.CACHED_ACTIVITY_CLIENT;
        STATE_PROTO_ENUMS[STATE_CACHED_EMPTY] = ProcessStatsProto.State.CACHED_EMPTY;
    }

    public static final String[] ADJ_SCREEN_NAMES_CSV = new String[] {
            "off", "on"
@@ -61,25 +127,26 @@ public final class DumpUtils {
            "norm", "mod",  "low", "crit"
    };

    public static final String[] STATE_NAMES_CSV = new String[] {
            "pers", "top", "impfg", "impbg", "backup", "heavy",
            "service", "service-rs", "receiver", "home", "lastact",
            "cch-activity", "cch-aclient", "cch-empty"
    };

    // State enum is defined in frameworks/base/core/proto/android/service/procstats.proto
    // Update states must sync enum definition as well, the ordering must not be changed.
    static final String[] ADJ_SCREEN_TAGS = new String[] {
            "0", "1"
    };

    static final int[] ADJ_SCREEN_PROTO_ENUMS = new int[] {
            ProcessStatsProto.State.OFF,
            ProcessStatsProto.State.ON
    };

    static final String[] ADJ_MEM_TAGS = new String[] {
            "n", "m",  "l", "c"
    };

    static final String[] STATE_TAGS = new String[] {
            "p", "t", "f", "b", "u", "w",
            "s", "x", "r", "h", "l", "a", "c", "e"
    static final int[] ADJ_MEM_PROTO_ENUMS = new int[] {
            ProcessStatsProto.State.NORMAL,
            ProcessStatsProto.State.MODERATE,
            ProcessStatsProto.State.LOW,
            ProcessStatsProto.State.CRITICAL
    };

    static final String CSV_SEP = "\t";
@@ -182,9 +249,10 @@ public final class DumpUtils {

    public static void printProcStateTagProto(ProtoOutputStream proto, long screenId, long memId,
            long stateId, int state) {
        state = printProto(proto, screenId, ADJ_SCREEN_TAGS, state, ADJ_SCREEN_MOD * STATE_COUNT);
        state = printProto(proto, memId, ADJ_MEM_TAGS, state, STATE_COUNT);
        printProto(proto, stateId, STATE_TAGS, state, 1);
        state = printProto(proto, screenId, ADJ_SCREEN_PROTO_ENUMS,
                state, ADJ_SCREEN_MOD * STATE_COUNT);
        state = printProto(proto, memId, ADJ_MEM_PROTO_ENUMS, state, STATE_COUNT);
        printProto(proto, stateId, STATE_PROTO_ENUMS, state, 1);
    }

    public static void printAdjTag(PrintWriter pw, int state) {
@@ -294,30 +362,6 @@ public final class DumpUtils {
        }
    }

    /*
     * Doesn't seem to be used.
     *
    public static void dumpProcessList(PrintWriter pw, String prefix, ArrayList<ProcessState> procs,
            int[] screenStates, int[] memStates, int[] procStates, long now) {
        String innerPrefix = prefix + "  ";
        for (int i=procs.size()-1; i>=0; i--) {
            ProcessState proc = procs.get(i);
            pw.print(prefix);
            pw.print(proc.mName);
            pw.print(" / ");
            UserHandle.formatUid(pw, proc.mUid);
            pw.print(" (");
            pw.print(proc.durations.getKeyCount());
            pw.print(" entries)");
            pw.println(":");
            proc.dumpProcessState(pw, innerPrefix, screenStates, memStates, procStates, now);
            if (proc.pssTable.getKeyCount() > 0) {
                proc.dumpPss(pw, innerPrefix, screenStates, memStates, procStates);
            }
        }
    }
    */

    public static void dumpProcessSummaryLocked(PrintWriter pw, String prefix,
            ArrayList<ProcessState> procs, int[] screenStates, int[] memStates, int[] procStates,
            long now, long totalTime) {
@@ -362,11 +406,11 @@ public final class DumpUtils {
        return value - index*mod;
    }

    public static int printProto(ProtoOutputStream proto, long fieldId, String[] array, int value, int mod) {
    public static int printProto(ProtoOutputStream proto, long fieldId,
            int[] enums, int value, int mod) {
        int index = value/mod;
        if (index >= 0 && index < array.length) {
            // Valid state enum number starts at 1, 0 stands for unknown.
            proto.write(fieldId, index + 1);
        if (index >= 0 && index < enums.length) {
            proto.write(fieldId, enums[index]);
        } // else enum default is always zero in proto3
        return value - index*mod;
    }
+4 −1
Original line number Diff line number Diff line
@@ -1191,7 +1191,9 @@ public final class ProcessState {
        return sb.toString();
    }

    public void toProto(ProtoOutputStream proto, String procName, int uid, long now) {
    public void writeToProto(ProtoOutputStream proto, long fieldId,
            String procName, int uid, long now) {
        final long token = proto.start(fieldId);
        proto.write(ProcessStatsProto.PROCESS, procName);
        proto.write(ProcessStatsProto.UID, uid);
        if (mNumExcessiveCpu > 0 || mNumCachedKill > 0 ) {
@@ -1261,5 +1263,6 @@ public final class ProcessState {
            proto.write(ProcessStatsProto.State.DURATION_MS, entry.getValue());
            proto.end(stateToken);
        }
        proto.end(token);
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -1776,10 +1776,11 @@ public final class ProcessStats implements Parcelable {
        }
    }

    public void toProto(ProtoOutputStream proto, long now) {
    public void writeToProto(ProtoOutputStream proto, long fieldId, long now) {
        final ArrayMap<String, SparseArray<LongSparseArray<PackageState>>> pkgMap =
                mPackages.getMap();

        final long token = proto.start(fieldId);
        proto.write(ProcessStatsSectionProto.START_REALTIME_MS, mTimePeriodStartRealtime);
        proto.write(ProcessStatsSectionProto.END_REALTIME_MS,
                mRunning ? SystemClock.elapsedRealtime() : mTimePeriodEndRealtime);
@@ -1811,11 +1812,10 @@ public final class ProcessStats implements Parcelable {
            for (int iu=0; iu<uids.size(); iu++) {
                final int uid = uids.keyAt(iu);
                final ProcessState procState = uids.valueAt(iu);
                final long processStateToken = proto.start(ProcessStatsSectionProto.PROCESS_STATS);
                procState.toProto(proto, procName, uid, now);
                proto.end(processStateToken);
                procState.writeToProto(proto, ProcessStatsSectionProto.PROCESS_STATS, procName, uid, now);
            }
        }
        proto.end(token);
    }

    final public static class ProcessStateHolder {
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package android.content;
option java_package = "android.content";
option java_multiple_files = true;

import "frameworks/base/core/proto/android/content/component_name.proto";
import "frameworks/base/core/proto/android/os/patternmatcher.proto";
import "frameworks/base/libs/incident/proto/android/privacy.proto";

@@ -55,7 +56,7 @@ message IntentProto {
    optional string type = 4;
    optional string flag = 5;
    optional string package = 6;
    optional string component = 7;
    optional ComponentNameProto component = 7;
    optional string source_bounds = 8;
    optional string clip_data = 9 [ (.android.privacy).dest = DEST_EXPLICIT ];
    optional string extras = 10 [ (.android.privacy).dest = DEST_EXPLICIT ];
Loading