Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c357d11 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Aggregate prepared statement cache stats from individual connections." into main

parents 39e16db6 48733910
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -141,11 +141,6 @@ public class SQLiteDatabasePerfTest {
            }
        }

        Log.d("testSelectMemory",
                "cacheMissRate: " + mDatabase.getStatementCacheMissRate()
                        + "Total Statements: " + mDatabase.getTotalPreparedStatements()
                        + ". Misses: " + mDatabase.getTotalStatementCacheMisses());

        // Make sure caching is working and our miss rate should definitely be less than 100%
        // however, we would expect this number to be actually closer to 0.
        assertTrue(mDatabase.getStatementCacheMissRate() < 1);
+15 −5
Original line number Diff line number Diff line
@@ -1080,7 +1080,6 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
     * Return a {@link #PreparedStatement}, possibly from the cache.
     */
    private PreparedStatement acquirePreparedStatementLI(String sql) {
        ++mPool.mTotalPrepareStatements;
        PreparedStatement statement = mPreparedStatementCache.getStatement(sql);
        long seqNum = mPreparedStatementCache.getLastSeqNum();

@@ -1105,7 +1104,6 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
                skipCache = true;
            }
        }
        ++mPool.mTotalPrepareStatementCacheMiss;
        final long statementPtr = mPreparedStatementCache.createStatement(sql);
        seqNum = mPreparedStatementCache.getLastSeqNum();
        try {
@@ -1441,9 +1439,21 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
        } else {
            label = mConfiguration.path + " (" + mConnectionId + ")";
        }
        return new DbStats(label, pageCount, pageSize, lookaside,
                mPreparedStatementCache.hitCount(), mPreparedStatementCache.missCount(),
                mPreparedStatementCache.size(), false);
        DbStats dbStats = new DbStats(label, pageCount, pageSize, lookaside, 0, 0, 0, false);
        dbStats.addCacheStatsFrom(this);
        return dbStats;
    }

    int getPreparedStatementCacheHitCount() {
        return mPreparedStatementCache.hitCount();
    }

    int getPreparedStatementCacheMissCount() {
        return mPreparedStatementCache.missCount();
    }

    int getPreparedStatementCacheSize() {
        return mPreparedStatementCache.size();
    }

    @Override
+22 −10
Original line number Diff line number Diff line
@@ -109,10 +109,6 @@ public final class SQLiteConnectionPool implements Closeable {
            new ArrayList<SQLiteConnection>();
    private SQLiteConnection mAvailablePrimaryConnection;

    // Prepare statement cache statistics
    public int mTotalPrepareStatementCacheMiss = 0;
    public int mTotalPrepareStatements = 0;

    @GuardedBy("mLock")
    private IdleConnectionHandler mIdleConnectionHandler;

@@ -528,9 +524,15 @@ public final class SQLiteConnectionPool implements Closeable {
            }

            // Global pool stats
            DbStats poolStats = new DbStats(mConfiguration.path, 0, 0, 0,
                    mTotalPrepareStatements - mTotalPrepareStatementCacheMiss,
                    mTotalPrepareStatementCacheMiss, mTotalPrepareStatements, true);
            DbStats poolStats = new DbStats(mConfiguration.path, 0, 0, 0, 0, 0, 0, true);

            if (mAvailablePrimaryConnection != null) {
                poolStats.addCacheStatsFrom(mAvailablePrimaryConnection);
            }
            for (SQLiteConnection connection : mAvailableNonPrimaryConnections) {
                poolStats.addCacheStatsFrom(connection);
            }

            dbStatsList.add(poolStats);
        }
    }
@@ -1246,11 +1248,21 @@ public final class SQLiteConnectionPool implements Closeable {
    /** @hide */
    @NeverCompile
    public double getStatementCacheMissRate() {
        if (mTotalPrepareStatements == 0) {
            // no statements executed thus no miss rate.
        int cacheHits = 0;
        int cacheMisses = 0;

        if (mAvailablePrimaryConnection != null) {
            cacheHits += mAvailablePrimaryConnection.getPreparedStatementCacheHitCount();
            cacheMisses += mAvailablePrimaryConnection.getPreparedStatementCacheMissCount();
        }
        for (SQLiteConnection connection : mAvailableNonPrimaryConnections) {
            cacheHits += connection.getPreparedStatementCacheHitCount();
            cacheMisses += connection.getPreparedStatementCacheMissCount();
        }
        if (cacheMisses == 0) {
            return 0;
        }
        return (double) mTotalPrepareStatementCacheMiss / (double) mTotalPrepareStatements;
        return (double) cacheMisses / (double) (cacheHits + cacheMisses);
    }

    public long getTotalStatementsTime() {
+0 −16
Original line number Diff line number Diff line
@@ -2725,22 +2725,6 @@ public final class SQLiteDatabase extends SQLiteClosable {
        return connectionPools;
    }

    /** @hide */
    @NeverCompile
    public int getTotalPreparedStatements() {
        throwIfNotOpenLocked();

        return mConnectionPoolLocked.mTotalPrepareStatements;
    }

    /** @hide */
    @NeverCompile
    public int getTotalStatementCacheMisses() {
        throwIfNotOpenLocked();

        return mConnectionPoolLocked.mTotalPrepareStatementCacheMiss;
    }

    /**
     * Dump detailed information about all open databases in the current process.
     * Used by bug report.
+9 −3
Original line number Diff line number Diff line
@@ -182,11 +182,11 @@ public final class SQLiteDebug {
        public int lookaside;

        /** @hide */
        final public int cacheHits;
        public int cacheHits;
        /** @hide */
        final public int cacheMisses;
        public int cacheMisses;
        /** @hide */
        final public int cacheSize;
        public int cacheSize;

        /** true if connection specific stats or whole connection pool if false */
        public final boolean arePoolStats;
@@ -202,6 +202,12 @@ public final class SQLiteDebug {
            this.cacheSize = cachesize;
            this.arePoolStats = arePoolStats;
        }

        void addCacheStatsFrom(SQLiteConnection connection) {
            cacheHits += connection.getPreparedStatementCacheHitCount();
            cacheMisses += connection.getPreparedStatementCacheMissCount();
            cacheSize += connection.getPreparedStatementCacheSize();
        }
    }

    /**