Change perf tests to have less deviation.

Simultaneous writes might get in a way of testing.

BEFORE:
[1/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_badRTC: PASSED (36.482s)
	testPersistedJobReading_fewJobs_badRTC_mean: 10263642
	testPersistedJobReading_fewJobs_badRTC_mean: 10498465
	testPersistedJobReading_fewJobs_badRTC_mean: 10773303
	testPersistedJobReading_fewJobs_badRTC_mean: 10134928
	testPersistedJobReading_fewJobs_badRTC_mean: 10781215
[2/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_manyJobs: PASSED (38.200s)
	testPersistedJobWriting_manyJobs_mean: 37482702
	testPersistedJobWriting_manyJobs_mean: 60457027
	testPersistedJobWriting_manyJobs_mean: 36667759
	testPersistedJobWriting_manyJobs_mean: 36411327
	testPersistedJobWriting_manyJobs_mean: 36966431
[3/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_goodRTC: PASSED (38.297s)
	testPersistedJobReading_manyJobs_goodRTC_mean: 43782739
	testPersistedJobReading_manyJobs_goodRTC_mean: 44142442
	testPersistedJobReading_manyJobs_goodRTC_mean: 43433056
	testPersistedJobReading_manyJobs_goodRTC_mean: 43435353
	testPersistedJobReading_manyJobs_goodRTC_mean: 43571135
[4/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_fewJobs: PASSED (36.485s)
	testPersistedJobWriting_fewJobs_mean: 9229892
	testPersistedJobWriting_fewJobs_mean: 9100376
	testPersistedJobWriting_fewJobs_mean: 8941938
	testPersistedJobWriting_fewJobs_mean: 8922329
	testPersistedJobWriting_fewJobs_mean: 8929850
[5/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_goodRTC: PASSED (36.533s)
	testPersistedJobReading_fewJobs_goodRTC_mean: 10774626
	testPersistedJobReading_fewJobs_goodRTC_mean: 10629069
	testPersistedJobReading_fewJobs_goodRTC_mean: 10166131
	testPersistedJobReading_fewJobs_goodRTC_mean: 10435772
	testPersistedJobReading_fewJobs_goodRTC_mean: 10990735
[6/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_badRTC: PASSED (38.883s)
	testPersistedJobReading_manyJobs_badRTC_mean: 88288009
	testPersistedJobReading_manyJobs_badRTC_mean: 43032098
	testPersistedJobReading_manyJobs_badRTC_mean: 86609764
	testPersistedJobReading_manyJobs_badRTC_mean: 42699765
	testPersistedJobReading_manyJobs_badRTC_mean: 86939196

AFTER:
com.android.frameworks.perftests.job (6 Tests)
[1/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_badRTC: PASSED (20.018s)
	testPersistedJobReading_fewJobs_badRTC_mean: 4403782
	testPersistedJobReading_fewJobs_badRTC_mean: 4329086
	testPersistedJobReading_fewJobs_badRTC_mean: 4361577
[2/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_manyJobs: PASSED (20.894s)
	testPersistedJobWriting_manyJobs_mean: 33269431
	testPersistedJobWriting_manyJobs_mean: 32886187
	testPersistedJobWriting_manyJobs_mean: 33093695
[3/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_goodRTC: PASSED (20.822s)
	testPersistedJobReading_manyJobs_goodRTC_mean: 39305058
	testPersistedJobReading_manyJobs_goodRTC_mean: 38768541
	testPersistedJobReading_manyJobs_goodRTC_mean: 38944530
[4/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobWriting_fewJobs: PASSED (21.046s)
	testPersistedJobWriting_fewJobs_mean: 4301181
	testPersistedJobWriting_fewJobs_mean: 4164938
	testPersistedJobWriting_fewJobs_mean: 4146446
[5/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_fewJobs_goodRTC: PASSED (21.137s)
	testPersistedJobReading_fewJobs_goodRTC_mean: 4230574
	testPersistedJobReading_fewJobs_goodRTC_mean: 4184341
	testPersistedJobReading_fewJobs_goodRTC_mean: 4192015
[6/6] com.android.frameworks.perftests.job.JobStorePerfTests#testPersistedJobReading_manyJobs_badRTC: PASSED (21.016s)
	testPersistedJobReading_manyJobs_badRTC_mean: 39166861
	testPersistedJobReading_manyJobs_badRTC_mean: 39049685
	testPersistedJobReading_manyJobs_badRTC_mean: 38929124

Bug: 135200955
Test: atest JobStoreTest CtsJobSchedulerTestCases JobStorePerfTests

Change-Id: I9e69ded28bed13834ba82a5d74283711422c5124
This commit is contained in:
Alex Buynytskyy
2021-08-17 11:15:21 -07:00
parent 98ed025e06
commit eed98a6083
2 changed files with 22 additions and 7 deletions

View File

@@ -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.

View File

@@ -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();