diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobStore.java b/apex/jobscheduler/service/java/com/android/server/job/JobStore.java index 7a2840709d15f..49d561bb461a3 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobStore.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobStore.java @@ -133,7 +133,7 @@ public final class JobStore { @VisibleForTesting public static JobStore initAndGetForTesting(Context context, File dataDir) { JobStore jobStoreUnderTest = new JobStore(context, new Object(), dataDir); - jobStoreUnderTest.clear(); + jobStoreUnderTest.clearForTesting(); return jobStoreUnderTest; } @@ -222,6 +222,14 @@ public final class JobStore { return replaced; } + /** + * The same as above but does not schedule writing. This makes perf benchmarks more stable. + */ + @VisibleForTesting + public void addForTesting(JobStatus jobStatus) { + mJobSet.add(jobStatus); + } + boolean containsJob(JobStatus jobStatus) { return mJobSet.contains(jobStatus); } @@ -272,6 +280,14 @@ public final class JobStore { maybeWriteStatusToDiskAsync(); } + /** + * The same as above but does not schedule writing. This makes perf benchmarks more stable. + */ + @VisibleForTesting + public void clearForTesting() { + mJobSet.clear(); + } + /** * @param userHandle User for whom we are querying the list of jobs. * @return A list of all the jobs scheduled for the provided user. Never null. diff --git a/tests/JobSchedulerPerfTests/src/com/android/frameworks/perftests/job/JobStorePerfTests.java b/tests/JobSchedulerPerfTests/src/com/android/frameworks/perftests/job/JobStorePerfTests.java index e956be339bc4a..dd9b294a95962 100644 --- a/tests/JobSchedulerPerfTests/src/com/android/frameworks/perftests/job/JobStorePerfTests.java +++ b/tests/JobSchedulerPerfTests/src/com/android/frameworks/perftests/job/JobStorePerfTests.java @@ -82,11 +82,10 @@ public class JobStorePerfTests { long elapsedTimeNs = 0; while (benchmarkState.keepRunning(elapsedTimeNs)) { - sJobStore.clear(); + sJobStore.clearForTesting(); for (JobStatus job : jobList) { - sJobStore.add(job); + sJobStore.addForTesting(job); } - sJobStore.waitForWriteToCompleteForTesting(10_000); final long startTime = SystemClock.elapsedRealtimeNanos(); sJobStore.writeStatusToDiskForTesting(); @@ -110,11 +109,11 @@ public class JobStorePerfTests { long elapsedTimeNs = 0; while (benchmarkState.keepRunning(elapsedTimeNs)) { - sJobStore.clear(); + sJobStore.clearForTesting(); for (JobStatus job : jobList) { - sJobStore.add(job); + sJobStore.addForTesting(job); } - sJobStore.waitForWriteToCompleteForTesting(10_000); + sJobStore.writeStatusToDiskForTesting(); JobSet jobSet = new JobSet();