diff options
author | 2022-08-20 03:27:02 +0000 | |
---|---|---|
committer | 2022-08-20 03:27:02 +0000 | |
commit | 4d83b1589f353bc6562905b5df62ed65f536940c (patch) | |
tree | 99853c25ce3ffae971d09839c702765f692ae790 | |
parent | 5eb053047b36d67d612973ca4be72da9c5771cf6 (diff) | |
parent | 6d1be638de96a8aef566a592862f26de1de712f2 (diff) |
Merge "Dump cancelled jobs for testing."
-rw-r--r-- | apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java index 794362bd682b..f0f00ea37d5a 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java @@ -310,11 +310,25 @@ public class JobSchedulerService extends com.android.server.SystemService */ boolean mReportedActive; + /** + * Track the most recently completed jobs (that had been executing and were stopped for any + * reason, including successful completion). + */ private int mLastCompletedJobIndex = 0; private final JobStatus[] mLastCompletedJobs = new JobStatus[NUM_COMPLETED_JOB_HISTORY]; private final long[] mLastCompletedJobTimeElapsed = new long[NUM_COMPLETED_JOB_HISTORY]; /** + * Track the most recently cancelled jobs (that had internal reason + * {@link JobParameters#INTERNAL_STOP_REASON_CANCELED}. + */ + private int mLastCancelledJobIndex = 0; + private final JobStatus[] mLastCancelledJobs = + new JobStatus[DEBUG ? NUM_COMPLETED_JOB_HISTORY : 0]; + private final long[] mLastCancelledJobTimeElapsed = + new long[DEBUG ? NUM_COMPLETED_JOB_HISTORY : 0]; + + /** * A mapping of which uids are currently in the foreground to their effective bias. */ final SparseIntArray mUidBiasOverride = new SparseIntArray(); @@ -1398,6 +1412,12 @@ public class JobSchedulerService extends com.android.server.SystemService startTrackingJobLocked(incomingJob, cancelled); } reportActiveLocked(); + if (mLastCancelledJobs.length > 0 + && internalReasonCode == JobParameters.INTERNAL_STOP_REASON_CANCELED) { + mLastCancelledJobs[mLastCancelledJobIndex] = cancelled; + mLastCancelledJobTimeElapsed[mLastCancelledJobIndex] = sElapsedRealtimeClock.millis(); + mLastCancelledJobIndex = (mLastCancelledJobIndex + 1) % mLastCancelledJobs.length; + } } void updateUidState(int uid, int procState) { @@ -3848,6 +3868,38 @@ public class JobSchedulerService extends com.android.server.SystemService pw.decreaseIndent(); pw.println(); + boolean recentCancellationsPrinted = false; + for (int r = 1; r <= mLastCancelledJobs.length; ++r) { + // Print most recent first + final int idx = (mLastCancelledJobIndex + mLastCancelledJobs.length - r) + % mLastCancelledJobs.length; + job = mLastCancelledJobs[idx]; + if (job != null) { + if (!predicate.test(job)) { + continue; + } + if (!recentCancellationsPrinted) { + pw.println(); + pw.println("Recently cancelled jobs:"); + pw.increaseIndent(); + recentCancellationsPrinted = true; + } + TimeUtils.formatDuration(mLastCancelledJobTimeElapsed[idx], nowElapsed, pw); + pw.println(); + // Double indent for readability + pw.increaseIndent(); + pw.increaseIndent(); + pw.println(job.toShortString()); + job.dump(pw, true, nowElapsed); + pw.decreaseIndent(); + pw.decreaseIndent(); + } + } + if (!recentCancellationsPrinted) { + pw.decreaseIndent(); + pw.println(); + } + if (filterUid == -1) { pw.println(); pw.print("mReadyToRock="); pw.println(mReadyToRock); |