TIF: add query perf tests for a channel/program Uri in TvProviderPerfTest
Bug: 22205522
Change-Id: If175fa70e31d8e174b8b15b62e507e46c9a1c881
diff --git a/suite/cts/deviceTests/tvproviderperf/src/com/android/cts/tvproviderperf/TvProviderPerfTest.java b/suite/cts/deviceTests/tvproviderperf/src/com/android/cts/tvproviderperf/TvProviderPerfTest.java
index 286d4fd..f9daa3c 100644
--- a/suite/cts/deviceTests/tvproviderperf/src/com/android/cts/tvproviderperf/TvProviderPerfTest.java
+++ b/suite/cts/deviceTests/tvproviderperf/src/com/android/cts/tvproviderperf/TvProviderPerfTest.java
@@ -80,7 +80,7 @@
@TimeoutReq(minutes = 8)
public void testChannels() throws Exception {
if (!mHasTvInputFramework) return;
- double[] averages = new double[4];
+ double[] averages = new double[5];
// Insert
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
@@ -138,23 +138,42 @@
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
averages[1] = Stat.getAverage(applyBatchTimes);
- // Query
+ // Query channels
applyBatchTimes = MeasureTime.measure(QUERY_RUNS, new MeasureRun() {
@Override
public void run(int i) {
- int j = 0;
try (Cursor cursor = mContentResolver.query(Channels.CONTENT_URI, null, null,
null, null)) {
while (cursor.moveToNext()) {
- ++j;
+ // Do nothing. Just iterate all the items.
}
}
}
});
- getReportLog().printArray("Elapsed time for query: ",
+ getReportLog().printArray("Elapsed time for query (channels): ",
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
averages[2] = Stat.getAverage(applyBatchTimes);
+ // Query a channel
+ try (final Cursor cursor = mContentResolver.query(Channels.CONTENT_URI,
+ projection, null, null, null)) {
+ final Uri channelUri = TvContract.buildChannelUri(cursor.getLong(0));
+ applyBatchTimes = MeasureTime.measure(QUERY_RUNS, new MeasureRun() {
+ @Override
+ public void run(int i) {
+ assertTrue(cursor.moveToNext());
+ try (Cursor c = mContentResolver.query(channelUri, null, null, null, null)) {
+ while (c.moveToNext()) {
+ // Do nothing. Just iterate all the items.
+ }
+ }
+ }
+ });
+ }
+ getReportLog().printArray("Elapsed time for query (a channel): ",
+ applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
+ averages[3] = Stat.getAverage(applyBatchTimes);
+
// Delete
applyBatchTimes = MeasureTime.measure(1, new MeasureRun() {
@Override
@@ -164,16 +183,17 @@
});
getReportLog().printArray("Elapsed time for delete: ",
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
- averages[3] = Stat.getAverage(applyBatchTimes);
+ averages[4] = Stat.getAverage(applyBatchTimes);
- getReportLog().printArray("Average elapsed time for (insert, update, query, delete): ",
+ getReportLog().printArray("Average elapsed time for insert, update, query (channels), "
+ + "query (a channel), delete: ",
averages, ResultType.LOWER_BETTER, ResultUnit.MS);
}
@TimeoutReq(minutes = 12)
public void testPrograms() throws Exception {
if (!mHasTvInputFramework) return;
- double[] averages = new double[6];
+ double[] averages = new double[7];
// Prepare (insert channels)
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
@@ -262,20 +282,19 @@
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
averages[1] = Stat.getAverage(applyBatchTimes);
- // Query
+ // Query programs
applyBatchTimes = MeasureTime.measure(QUERY_RUNS, new MeasureRun() {
@Override
public void run(int i) {
- int j = 0;
try (Cursor cursor = mContentResolver.query(Programs.CONTENT_URI, null, null,
null, null)) {
while (cursor.moveToNext()) {
- ++j;
+ // Do nothing. Just iterate all the items.
}
}
}
});
- getReportLog().printArray("Elapsed time for query: ",
+ getReportLog().printArray("Elapsed time for query (programs): ",
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
averages[2] = Stat.getAverage(applyBatchTimes);
@@ -284,22 +303,41 @@
@Override
public void run(int i) {
Uri channelUri = channelUris.get(i);
- int j = 0;
try (Cursor cursor = mContentResolver.query(
TvContract.buildProgramsUriForChannel(
channelUri, 0,
PROGRAM_DURATION_MS * TRANSACTION_SIZE / 2),
null, null, null, null)) {
while (cursor.moveToNext()) {
- ++j;
+ // Do nothing. Just iterate all the items.
}
}
}
});
- getReportLog().printArray("Elapsed time for query with selection: ",
+ getReportLog().printArray("Elapsed time for query (programs with selection): ",
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
averages[3] = Stat.getAverage(applyBatchTimes);
+ // Query a program
+ try (final Cursor cursor = mContentResolver.query(Programs.CONTENT_URI,
+ projection, null, null, null)) {
+ final Uri programUri = TvContract.buildProgramUri(cursor.getLong(0));
+ applyBatchTimes = MeasureTime.measure(QUERY_RUNS, new MeasureRun() {
+ @Override
+ public void run(int i) {
+ assertTrue(cursor.moveToNext());
+ try (Cursor c = mContentResolver.query(programUri, null, null, null, null)) {
+ while (c.moveToNext()) {
+ // Do nothing. Just iterate all the items.
+ }
+ }
+ }
+ });
+ }
+ getReportLog().printArray("Elapsed time for query (a program): ",
+ applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
+ averages[4] = Stat.getAverage(applyBatchTimes);
+
// Delete programs
applyBatchTimes = MeasureTime.measure(NUM_CHANNELS, new MeasureRun() {
@Override
@@ -315,7 +353,7 @@
});
getReportLog().printArray("Elapsed time for delete programs: ",
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
- averages[4] = Stat.getAverage(applyBatchTimes);
+ averages[5] = Stat.getAverage(applyBatchTimes);
// Delete channels
applyBatchTimes = MeasureTime.measure(NUM_CHANNELS, new MeasureRun() {
@@ -327,10 +365,11 @@
});
getReportLog().printArray("Elapsed time for delete channels: ",
applyBatchTimes, ResultType.LOWER_BETTER, ResultUnit.MS);
- averages[5] = Stat.getAverage(applyBatchTimes);
+ averages[6] = Stat.getAverage(applyBatchTimes);
- getReportLog().printArray("Average elapsed time for (insert, update, query, "
- + "query with selection, delete channels, delete programs): ",
+ getReportLog().printArray("Average elapsed time for insert, update, query (programs), "
+ + "query (programs with selection), query (a channel), delete (channels), "
+ + "delete (programs): ",
averages, ResultType.LOWER_BETTER, ResultUnit.MS);
}
}