Merge "Limit the number of dumped processes in the CPU usage section in dropbox files to 10"

This commit is contained in:
Mohamad Mahmoud
2022-12-22 11:50:44 +00:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 4 deletions

View File

@@ -841,7 +841,19 @@ public class ProcessCpuTracker {
return sw.toString();
}
final public String printCurrentState(long now) {
/**
* Returns current CPU state with all the processes as a String, sorted by load
* in descending order.
*/
public final String printCurrentState(long now) {
return printCurrentState(now, Integer.MAX_VALUE);
}
/**
* Returns current CPU state with the top {@code maxProcessesToDump} highest load
* processes as a String, sorted by load in descending order.
*/
public final String printCurrentState(long now, int maxProcessesToDump) {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
buildWorkingProcs();
@@ -883,8 +895,8 @@ public class ProcessCpuTracker {
if (DEBUG) Slog.i(TAG, "totalTime " + totalTime + " over sample time "
+ (mCurrentSampleTime-mLastSampleTime));
int N = mWorkingProcs.size();
for (int i=0; i<N; i++) {
int dumpedProcessCount = Math.min(maxProcessesToDump, mWorkingProcs.size());
for (int i = 0; i < dumpedProcessCount; i++) {
Stats st = mWorkingProcs.get(i);
printProcessCPU(pw, st.added ? " +" : (st.removed ? " -": " "),
st.pid, st.name, (int)st.rel_uptime,

View File

@@ -2314,7 +2314,8 @@ public class AppProfiler {
void printCurrentCpuState(StringBuilder report, long time) {
synchronized (mProcessCpuTracker) {
report.append(mProcessCpuTracker.printCurrentState(time));
// Only print the first 10 processes
report.append(mProcessCpuTracker.printCurrentState(time, /* maxProcesses= */10));
}
}