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

Commit 13ac041b authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Update procstats to start collecting/reporting pss.

Completely reworked how it manages its data, since trying
to keep track of all of the possible pss data with the old
data structures would have made it huge.  Now we have a sparse
data structure for pss and process times.  (Will switch service
times over to it soon.)

Currently the only thing that collects pss data is running
"dumpsys meminfo".  More will be added later.

Modified checkin output to also scale better as more distinct
data categories are added, and added output of pss data.  Now
instead of dumping every possible entry as a comma-separated
list, it dumps a comma-separated list of only the entries with
data, tagged with the state they go with.

Also fixed some problems in the checkin reporting of batterystats
(it needs to escape commas), added checkin reporting of the history
list, fixed parsing of kernel wake locks to strip quotes, fixed
wake lock name that the sync manager generates to be more sane.

Change-Id: Ibf4010838a9f685ebe1d93aff86c064ccc52b861
parent bf991a8f
Loading
Loading
Loading
Loading
+48 −5
Original line number Diff line number Diff line
@@ -1214,7 +1214,7 @@ public abstract class BatteryStats implements Parcelable {
            pw.print(',');
            pw.print(arg);
        }
        pw.print('\n');
        pw.println();
    }
    
    /**
@@ -1407,7 +1407,11 @@ public abstract class BatteryStats implements Parcelable {
                    
                    // Only log if we had at lease one wakelock...
                    if (sb.length() > 0) {
                       dumpLine(pw, uid, category, WAKELOCK_DATA, ent.getKey(), sb.toString());
                        String name = ent.getKey();
                        if (name.indexOf(',') >= 0) {
                            name = name.replace(',', '_');
                        }
                        dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
                    }
                }
            }
@@ -2274,6 +2278,30 @@ public abstract class BatteryStats implements Parcelable {
            }
            oldState = rec.states;
        }

        public void printNextItemCheckin(PrintWriter pw, HistoryItem rec, long now) {
            pw.print(rec.time-now);
            pw.print(",");
            if (rec.cmd == HistoryItem.CMD_START) {
                pw.print("start");
            } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
                pw.print("overflow");
            } else {
                pw.print(rec.batteryLevel);
                pw.print(",");
                pw.print(rec.states);
                pw.print(",");
                pw.print(rec.batteryStatus);
                pw.print(",");
                pw.print(rec.batteryHealth);
                pw.print(",");
                pw.print(rec.batteryPlugType);
                pw.print(",");
                pw.print((int)rec.batteryTemperature);
                pw.print(",");
                pw.print((int)rec.batteryVoltage);
            }
        }
    }

    /**
@@ -2351,6 +2379,21 @@ public abstract class BatteryStats implements Parcelable {
            PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly) {
        prepareForDumpLocked();
        
        long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();

        final HistoryItem rec = new HistoryItem();
        if (startIteratingHistoryLocked()) {
            HistoryPrinter hprinter = new HistoryPrinter();
            while (getNextHistoryLocked(rec)) {
                pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                pw.print(0); pw.print(',');
                pw.print("h"); pw.print(',');
                hprinter.printNextItemCheckin(pw, rec, now);
                pw.println();
            }
            finishIteratingHistoryLocked();
        }

        if (apps != null) {
            SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
            for (int i=0; i<apps.size(); i++) {
+2 −0
Original line number Diff line number Diff line
@@ -976,6 +976,8 @@ public class Process {
    /** @hide */
    public static final int PROC_PARENS = 0x200;
    /** @hide */
    public static final int PROC_QUOTES = 0x400;
    /** @hide */
    public static final int PROC_OUT_STRING = 0x1000;
    /** @hide */
    public static final int PROC_OUT_LONG = 0x2000;
+2 −1
Original line number Diff line number Diff line
@@ -302,7 +302,8 @@ public final class BatteryStatsImpl extends BatteryStats {
    private static int sKernelWakelockUpdateVersion = 0;

    private static final int[] PROC_WAKELOCKS_FORMAT = new int[] {
        Process.PROC_TAB_TERM|Process.PROC_OUT_STRING,                // 0: name
        Process.PROC_TAB_TERM|Process.PROC_OUT_STRING|                // 0: name
                              Process.PROC_QUOTES,
        Process.PROC_TAB_TERM|Process.PROC_OUT_LONG,                  // 1: count
        Process.PROC_TAB_TERM,
        Process.PROC_TAB_TERM,
+14 −1
Original line number Diff line number Diff line
@@ -678,6 +678,7 @@ enum {
    PROC_SPACE_TERM = ' ',
    PROC_COMBINE = 0x100,
    PROC_PARENS = 0x200,
    PROC_QUOTES = 0x400,
    PROC_OUT_STRING = 0x1000,
    PROC_OUT_LONG = 0x2000,
    PROC_OUT_FLOAT = 0x4000,
@@ -719,9 +720,15 @@ jboolean android_os_Process_parseProcLineArray(JNIEnv* env, jobject clazz,
    jboolean res = JNI_TRUE;

    for (jsize fi=0; fi<NF; fi++) {
        const jint mode = formatData[fi];
        jint mode = formatData[fi];
        if ((mode&PROC_PARENS) != 0) {
            i++;
        } else if ((mode&PROC_QUOTES != 0)) {
            if (buffer[i] == '"') {
                i++;
            } else {
                mode &= ~PROC_QUOTES;
            }
        }
        const char term = (char)(mode&PROC_TERM_MASK);
        const jsize start = i;
@@ -737,6 +744,12 @@ jboolean android_os_Process_parseProcLineArray(JNIEnv* env, jobject clazz,
            }
            end = i;
            i++;
        } else if ((mode&PROC_QUOTES) != 0) {
            while (buffer[i] != '"' && i < endIndex) {
                i++;
            }
            end = i;
            i++;
        }
        while (buffer[i] != term && i < endIndex) {
            i++;
+4 −0
Original line number Diff line number Diff line
@@ -10933,6 +10933,10 @@ public final class ActivityManagerService extends ActivityManagerNative
                            r.processName, myTotalPss, 0);
                    procMems.add(pssItem);
                    synchronized (this) {
                        r.baseProcessTracker.addPss(myTotalPss);
                    }
                    nativePss += mi.nativePss;
                    dalvikPss += mi.dalvikPss;
                    otherPss += mi.otherPss;
Loading