From e458428ec5476a14073ecdfb3d96a8e4de5ad50d Mon Sep 17 00:00:00 2001 From: Lee Shombert Date: Mon, 8 Jan 2024 17:46:12 -0800 Subject: Correct a db perf test The two multi-threaded read/write performance tests violate the recommended Android database best practice: the writer loop creates a new SQLiteDatabase on the test database file. This leads to two errors: the writer loop creates its database with an incompatible journal mode in different from the actual database, and the test exits without properly closing the database. This change simply has the writer loop use the existing database for its test. The benchmark values for the multi-threaded read/write tests change dramatically for the TRUNCATE journal mode and slightly for the WAL journal mode; these metric changes are WAI. Test: atest * SQLiteDatabasePerfTest Bug: 318742652 Change-Id: Icb2534c6fbaf8daa3eb38e8b1b7f71331d571e9d --- .../android/database/SQLiteDatabasePerfTest.java | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/apct-tests/perftests/core/src/android/database/SQLiteDatabasePerfTest.java b/apct-tests/perftests/core/src/android/database/SQLiteDatabasePerfTest.java index b7460cd6ead4..fa4387b405c9 100644 --- a/apct-tests/perftests/core/src/android/database/SQLiteDatabasePerfTest.java +++ b/apct-tests/perftests/core/src/android/database/SQLiteDatabasePerfTest.java @@ -433,6 +433,17 @@ public class SQLiteDatabasePerfTest { performMultithreadedReadWriteTest(); } + /** + * This test measures a multi-threaded read-write environment where there are 2 readers and + * 1 writer in the database using WAL journal mode and NORMAL syncMode. + */ + @Test + public void testMultithreadedReadWriteWithWalNormal() { + recreateTestDatabase(SQLiteDatabase.JOURNAL_MODE_WAL, SQLiteDatabase.SYNC_MODE_NORMAL); + insertT1TestDataSet(); + performMultithreadedReadWriteTest(); + } + private void doReadLoop(int totalIterations) { Random rnd = new Random(0); int currentIteration = 0; @@ -472,7 +483,6 @@ public class SQLiteDatabasePerfTest { } private void doUpdateLoop(int totalIterations) { - SQLiteDatabase db = mContext.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null); Random rnd = new Random(0); int i = 0; ContentValues cv = new ContentValues(); @@ -485,24 +495,12 @@ public class SQLiteDatabasePerfTest { cv.put("COL_B", "UpdatedValue"); cv.put("COL_C", i); argArray[0] = String.valueOf(id); - db.update("T1", cv, "_ID=?", argArray); + mDatabase.update("T1", cv, "_ID=?", argArray); i++; android.os.Trace.endSection(); } } - /** - * This test measures a multi-threaded read-write environment where there are 2 readers and - * 1 writer in the database using WAL journal mode and NORMAL syncMode. - */ - @Test - public void testMultithreadedReadWriteWithWalNormal() { - recreateTestDatabase(SQLiteDatabase.JOURNAL_MODE_WAL, SQLiteDatabase.SYNC_MODE_NORMAL); - insertT1TestDataSet(); - - performMultithreadedReadWriteTest(); - } - private void performMultithreadedReadWriteTest() { int totalBGIterations = 10000; // Writer - Fixed iterations to avoid consuming cycles from mainloop benchmark iterations @@ -555,4 +553,3 @@ public class SQLiteDatabasePerfTest { createOrOpenTestDatabase(journalMode, syncMode); } } - -- cgit v1.2.3-59-g8ed1b