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

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

Merge "Add stats puller for aggregated procstats" into rvc-dev am: 5c942966 am: 91ea81cd

Change-Id: I808eb4426993450ab5c6d9bf2593142975a19d88
parents 4775ff74 91ea81cd
Loading
Loading
Loading
Loading
+19 −4
Original line number Original line Diff line number Diff line
@@ -534,16 +534,31 @@ public final class DumpUtils {
        int procStateIndex = curState % STATE_COUNT;
        int procStateIndex = curState % STATE_COUNT;


        // Remap process state per array above.
        // Remap process state per array above.
        try {
            procStateIndex = PROCESS_STATS_STATE_TO_AGGREGATED_STATE[procStateIndex];
            procStateIndex = PROCESS_STATS_STATE_TO_AGGREGATED_STATE[procStateIndex];
        } catch (IndexOutOfBoundsException e) {
            procStateIndex = ProcessStatsEnums.AGGREGATED_PROCESS_STATE_UNKNOWN;
        }


        // Pack screen & process state using bit shifting
        // Pack screen & process state using bit shifting
        return (procStateIndex << 8) | screenStateIndex;
        return (procStateIndex << 0xf) | screenStateIndex;
    }
    }


    /** Print aggregated tags generated via {@code #aggregateCurrentProcessState}. */
    /** Print aggregated tags generated via {@code #aggregateCurrentProcessState}. */
    public static void printAggregatedProcStateTagProto(ProtoOutputStream proto, long screenId,
    public static void printAggregatedProcStateTagProto(ProtoOutputStream proto, long screenId,
            long stateId, int state) {
            long stateId, int state) {
        proto.write(screenId, ADJ_SCREEN_PROTO_ENUMS[state >> 8]);
        // screen state is in lowest 0xf bits, process state is in next 0xf bits up
        proto.write(stateId, STATE_PROTO_ENUMS[state]);

        try {
            proto.write(stateId, STATE_PROTO_ENUMS[state >> 0xf]);
        } catch (IndexOutOfBoundsException e) {
            proto.write(stateId, ProcessStatsEnums.PROCESS_STATE_UNKNOWN);
        }

        try {
            proto.write(screenId, ADJ_SCREEN_PROTO_ENUMS[state & 0xf]);
        } catch (IndexOutOfBoundsException e) {
            proto.write(screenId, ProcessStatsEnums.SCREEN_STATE_UNKNOWN);
        }
    }
    }
}
}
+6 −5
Original line number Original line Diff line number Diff line
@@ -1436,7 +1436,7 @@ public final class ProcessState {
            }
            }
            int index = durationByState.indexOfKey(aggregatedType);
            int index = durationByState.indexOfKey(aggregatedType);
            if (index >= 0) {
            if (index >= 0) {
                durationByState.put(aggregatedType, time + durationByState.valueAt(aggregatedType));
                durationByState.put(aggregatedType, time + durationByState.valueAt(index));
            } else {
            } else {
                durationByState.put(aggregatedType, time);
                durationByState.put(aggregatedType, time);
            }
            }
@@ -1502,14 +1502,15 @@ public final class ProcessState {
        proto.write(ProcessStatsProto.UID, uid);
        proto.write(ProcessStatsProto.UID, uid);


        for (int i = 0; i < durationByState.size(); i++) {
        for (int i = 0; i < durationByState.size(); i++) {
            final int aggregatedKey = mPssTable.getKeyAt(i);

            final long stateToken = proto.start(ProcessStatsProto.STATES);
            final long stateToken = proto.start(ProcessStatsProto.STATES);

            final int aggregatedKey = durationByState.keyAt(i);

            DumpUtils.printAggregatedProcStateTagProto(proto,
            DumpUtils.printAggregatedProcStateTagProto(proto,
                    ProcessStatsStateProto.SCREEN_STATE,
                    ProcessStatsStateProto.SCREEN_STATE,
                    ProcessStatsStateProto.PROCESS_STATE,
                    ProcessStatsStateProto.PROCESS_STATE,
                    durationByState.keyAt(i));
                    aggregatedKey);
            proto.write(ProcessStatsStateProto.DURATION_MS, durationByState.valueAt(i));
            proto.write(ProcessStatsStateProto.DURATION_MS, durationByState.get(aggregatedKey));


            ProtoUtils.toAggStatsProto(proto, ProcessStatsStateProto.RSS,
            ProtoUtils.toAggStatsProto(proto, ProcessStatsStateProto.RSS,
                    0, /* do not output a minimum value */
                    0, /* do not output a minimum value */
+44 −23
Original line number Original line Diff line number Diff line
@@ -2178,29 +2178,7 @@ public final class ProcessStats implements Parcelable {
     * Writes to ProtoOutputStream.
     * Writes to ProtoOutputStream.
     */
     */
    public void dumpDebug(ProtoOutputStream proto, long now, int section) {
    public void dumpDebug(ProtoOutputStream proto, long now, int section) {
        proto.write(ProcessStatsSectionProto.START_REALTIME_MS, mTimePeriodStartRealtime);
        dumpProtoPreamble(proto);
        proto.write(ProcessStatsSectionProto.END_REALTIME_MS,
                mRunning ? SystemClock.elapsedRealtime() : mTimePeriodEndRealtime);
        proto.write(ProcessStatsSectionProto.START_UPTIME_MS, mTimePeriodStartUptime);
        proto.write(ProcessStatsSectionProto.END_UPTIME_MS, mTimePeriodEndUptime);
        proto.write(ProcessStatsSectionProto.RUNTIME, mRuntime);
        proto.write(ProcessStatsSectionProto.HAS_SWAPPED_PSS, mHasSwappedOutPss);
        boolean partial = true;
        if ((mFlags & FLAG_SHUTDOWN) != 0) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_SHUTDOWN);
            partial = false;
        }
        if ((mFlags & FLAG_SYSPROPS) != 0) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_SYSPROPS);
            partial = false;
        }
        if ((mFlags & FLAG_COMPLETE) != 0) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_COMPLETE);
            partial = false;
        }
        if (partial) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_PARTIAL);
        }


        final int NPAGETYPES = mPageTypeLabels.size();
        final int NPAGETYPES = mPageTypeLabels.size();
        for (int i = 0; i < NPAGETYPES; i++) {
        for (int i = 0; i < NPAGETYPES; i++) {
@@ -2247,6 +2225,49 @@ public final class ProcessStats implements Parcelable {
        }
        }
    }
    }


    /** Similar to {@code #dumpDebug}, but with a reduced/aggregated subset of states. */
    public void dumpAggregatedProtoForStatsd(ProtoOutputStream proto) {
        dumpProtoPreamble(proto);
        final ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
        for (int ip = 0; ip < procMap.size(); ip++) {
            final String procName = procMap.keyAt(ip);
            final SparseArray<ProcessState> uids = procMap.valueAt(ip);
            for (int iu = 0; iu < uids.size(); iu++) {
                final int uid = uids.keyAt(iu);
                final ProcessState procState = uids.valueAt(iu);
                procState.dumpAggregatedProtoForStatsd(proto,
                        ProcessStatsSectionProto.PROCESS_STATS,
                        procName, uid, mTimePeriodEndRealtime);
            }
        }
    }

    private void dumpProtoPreamble(ProtoOutputStream proto) {
        proto.write(ProcessStatsSectionProto.START_REALTIME_MS, mTimePeriodStartRealtime);
        proto.write(ProcessStatsSectionProto.END_REALTIME_MS,
                mRunning ? SystemClock.elapsedRealtime() : mTimePeriodEndRealtime);
        proto.write(ProcessStatsSectionProto.START_UPTIME_MS, mTimePeriodStartUptime);
        proto.write(ProcessStatsSectionProto.END_UPTIME_MS, mTimePeriodEndUptime);
        proto.write(ProcessStatsSectionProto.RUNTIME, mRuntime);
        proto.write(ProcessStatsSectionProto.HAS_SWAPPED_PSS, mHasSwappedOutPss);
        boolean partial = true;
        if ((mFlags & FLAG_SHUTDOWN) != 0) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_SHUTDOWN);
            partial = false;
        }
        if ((mFlags & FLAG_SYSPROPS) != 0) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_SYSPROPS);
            partial = false;
        }
        if ((mFlags & FLAG_COMPLETE) != 0) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_COMPLETE);
            partial = false;
        }
        if (partial) {
            proto.write(ProcessStatsSectionProto.STATUS, ProcessStatsSectionProto.STATUS_PARTIAL);
        }
    }

    final public static class ProcessStateHolder {
    final public static class ProcessStateHolder {
        public final long appVersion;
        public final long appVersion;
        public ProcessState state;
        public ProcessState state;
+17 −14
Original line number Original line Diff line number Diff line
@@ -2059,32 +2059,35 @@ public class StatsPullAtomService extends SystemService {
        synchronized (mProcessStatsLock) {
        synchronized (mProcessStatsLock) {
            final long token = Binder.clearCallingIdentity();
            final long token = Binder.clearCallingIdentity();
            try {
            try {
                // force procstats to flush & combine old files into one store
                long lastHighWaterMark = readProcStatsHighWaterMark(section);
                long lastHighWaterMark = readProcStatsHighWaterMark(section);
                List<ParcelFileDescriptor> statsFiles = new ArrayList<>();
                List<ParcelFileDescriptor> statsFiles = new ArrayList<>();
                long highWaterMark = processStatsService.getCommittedStats(

                        lastHighWaterMark, section, true, statsFiles);
                ProcessStats procStats = new ProcessStats(false);
                if (statsFiles.size() != 1) {
                long highWaterMark = processStatsService.getCommittedStatsMerged(
                    return StatsManager.PULL_SKIP;
                        lastHighWaterMark, section, true, statsFiles, procStats);
                }

                unpackStreamedData(atomTag, pulledData, statsFiles);
                // aggregate the data together for westworld consumption
                ProtoOutputStream proto = new ProtoOutputStream();
                procStats.dumpAggregatedProtoForStatsd(proto);

                StatsEvent e = StatsEvent.newBuilder()
                        .setAtomId(atomTag)
                        .writeByteArray(proto.getBytes())
                        .build();
                pulledData.add(e);

                new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + lastHighWaterMark)
                new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + lastHighWaterMark)
                        .delete();
                        .delete();
                new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + highWaterMark)
                new File(mBaseDir.getAbsolutePath() + "/" + section + "_" + highWaterMark)
                        .createNewFile();
                        .createNewFile();
            } catch (IOException e) {
            } catch (RemoteException | IOException e) {
                Slog.e(TAG, "Getting procstats failed: ", e);
                return StatsManager.PULL_SKIP;
            } catch (RemoteException e) {
                Slog.e(TAG, "Getting procstats failed: ", e);
                return StatsManager.PULL_SKIP;
            } catch (SecurityException e) {
                Slog.e(TAG, "Getting procstats failed: ", e);
                Slog.e(TAG, "Getting procstats failed: ", e);
                return StatsManager.PULL_SKIP;
                return StatsManager.PULL_SKIP;
            } finally {
            } finally {
                Binder.restoreCallingIdentity(token);
                Binder.restoreCallingIdentity(token);
            }
            }
        }
        }

        return StatsManager.PULL_SUCCESS;
        return StatsManager.PULL_SUCCESS;
    }
    }