Search in sources :

Example 1 with DbStats

use of android.database.sqlite.SQLiteDebug.DbStats in project XobotOS by xamarin.

the class SQLiteDatabase method getDbStats.

/**
     * this method is used to collect data about ALL open databases in the current process.
     * bugreport is a user of this data.
     */
/* package */
static ArrayList<DbStats> getDbStats() {
    ArrayList<DbStats> dbStatsList = new ArrayList<DbStats>();
    // make a local copy of mActiveDatabases - so that this method is not competing
    // for synchronization lock on mActiveDatabases
    ArrayList<WeakReference<SQLiteDatabase>> tempList;
    synchronized (mActiveDatabases) {
        tempList = (ArrayList<WeakReference<SQLiteDatabase>>) mActiveDatabases.clone();
    }
    for (WeakReference<SQLiteDatabase> w : tempList) {
        SQLiteDatabase db = w.get();
        if (db == null || !db.isOpen()) {
            continue;
        }
        try {
            // get SQLITE_DBSTATUS_LOOKASIDE_USED for the db
            int lookasideUsed = db.native_getDbLookaside();
            // get the lastnode of the dbname
            String path = db.getPath();
            int indx = path.lastIndexOf("/");
            String lastnode = path.substring((indx != -1) ? ++indx : 0);
            // get list of attached dbs and for each db, get its size and pagesize
            List<Pair<String, String>> attachedDbs = db.getAttachedDbs();
            if (attachedDbs == null) {
                continue;
            }
            for (int i = 0; i < attachedDbs.size(); i++) {
                Pair<String, String> p = attachedDbs.get(i);
                long pageCount = DatabaseUtils.longForQuery(db, "PRAGMA " + p.first + ".page_count;", null);
                // first entry in the attached db list is always the main database
                // don't worry about prefixing the dbname with "main"
                String dbName;
                if (i == 0) {
                    dbName = lastnode;
                } else {
                    // lookaside is only relevant for the main db
                    lookasideUsed = 0;
                    dbName = "  (attached) " + p.first;
                    // if the attached db has a path, attach the lastnode from the path to above
                    if (p.second.trim().length() > 0) {
                        int idx = p.second.lastIndexOf("/");
                        dbName += " : " + p.second.substring((idx != -1) ? ++idx : 0);
                    }
                }
                if (pageCount > 0) {
                    dbStatsList.add(new DbStats(dbName, pageCount, db.getPageSize(), lookasideUsed, db.getCacheHitNum(), db.getCacheMissNum(), db.getCachesize()));
                }
            }
            // if there are pooled connections, return the cache stats for them also.
            // while we are trying to query the pooled connections for stats, some other thread
            // could be disabling conneciton pool. so, grab a reference to the connection pool.
            DatabaseConnectionPool connPool = db.mConnectionPool;
            if (connPool != null) {
                for (SQLiteDatabase pDb : connPool.getConnectionList()) {
                    dbStatsList.add(new DbStats("(pooled # " + pDb.mConnectionNum + ") " + lastnode, 0, 0, 0, pDb.getCacheHitNum(), pDb.getCacheMissNum(), pDb.getCachesize()));
                }
            }
        } catch (SQLiteException e) {
        // ignore. we don't care about exceptions when we are taking adb
        // bugreport!
        }
    }
    return dbStatsList;
}
Also used : ArrayList(java.util.ArrayList) DbStats(android.database.sqlite.SQLiteDebug.DbStats) WeakReference(java.lang.ref.WeakReference) Pair(android.util.Pair)

Example 2 with DbStats

use of android.database.sqlite.SQLiteDebug.DbStats in project android_frameworks_base by DirtyUnicorns.

the class SQLiteConnection method collectDbStats.

/**
     * Collects statistics about database connection memory usage.
     *
     * @param dbStatsList The list to populate.
     */
void collectDbStats(ArrayList<DbStats> dbStatsList) {
    // Get information about the main database.
    int lookaside = nativeGetDbLookaside(mConnectionPtr);
    long pageCount = 0;
    long pageSize = 0;
    try {
        pageCount = executeForLong("PRAGMA page_count;", null, null);
        pageSize = executeForLong("PRAGMA page_size;", null, null);
    } catch (SQLiteException ex) {
    // Ignore.
    }
    dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
    // Get information about attached databases.
    // We ignore the first row in the database list because it corresponds to
    // the main database which we have already described.
    CursorWindow window = new CursorWindow("collectDbStats");
    try {
        executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null);
        for (int i = 1; i < window.getNumRows(); i++) {
            String name = window.getString(i, 1);
            String path = window.getString(i, 2);
            pageCount = 0;
            pageSize = 0;
            try {
                pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
                pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
            } catch (SQLiteException ex) {
            // Ignore.
            }
            String label = "  (attached) " + name;
            if (!path.isEmpty()) {
                label += ": " + path;
            }
            dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
        }
    } catch (SQLiteException ex) {
    // Ignore.
    } finally {
        window.close();
    }
}
Also used : CursorWindow(android.database.CursorWindow) DbStats(android.database.sqlite.SQLiteDebug.DbStats)

Example 3 with DbStats

use of android.database.sqlite.SQLiteDebug.DbStats in project android_frameworks_base by AOSPA.

the class SQLiteConnection method collectDbStats.

/**
     * Collects statistics about database connection memory usage.
     *
     * @param dbStatsList The list to populate.
     */
void collectDbStats(ArrayList<DbStats> dbStatsList) {
    // Get information about the main database.
    int lookaside = nativeGetDbLookaside(mConnectionPtr);
    long pageCount = 0;
    long pageSize = 0;
    try {
        pageCount = executeForLong("PRAGMA page_count;", null, null);
        pageSize = executeForLong("PRAGMA page_size;", null, null);
    } catch (SQLiteException ex) {
    // Ignore.
    }
    dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
    // Get information about attached databases.
    // We ignore the first row in the database list because it corresponds to
    // the main database which we have already described.
    CursorWindow window = new CursorWindow("collectDbStats");
    try {
        executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null);
        for (int i = 1; i < window.getNumRows(); i++) {
            String name = window.getString(i, 1);
            String path = window.getString(i, 2);
            pageCount = 0;
            pageSize = 0;
            try {
                pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
                pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
            } catch (SQLiteException ex) {
            // Ignore.
            }
            String label = "  (attached) " + name;
            if (!path.isEmpty()) {
                label += ": " + path;
            }
            dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
        }
    } catch (SQLiteException ex) {
    // Ignore.
    } finally {
        window.close();
    }
}
Also used : CursorWindow(android.database.CursorWindow) DbStats(android.database.sqlite.SQLiteDebug.DbStats)

Example 4 with DbStats

use of android.database.sqlite.SQLiteDebug.DbStats in project android_frameworks_base by ParanoidAndroid.

the class SQLiteConnection method collectDbStats.

/**
     * Collects statistics about database connection memory usage.
     *
     * @param dbStatsList The list to populate.
     */
void collectDbStats(ArrayList<DbStats> dbStatsList) {
    // Get information about the main database.
    int lookaside = nativeGetDbLookaside(mConnectionPtr);
    long pageCount = 0;
    long pageSize = 0;
    try {
        pageCount = executeForLong("PRAGMA page_count;", null, null);
        pageSize = executeForLong("PRAGMA page_size;", null, null);
    } catch (SQLiteException ex) {
    // Ignore.
    }
    dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
    // Get information about attached databases.
    // We ignore the first row in the database list because it corresponds to
    // the main database which we have already described.
    CursorWindow window = new CursorWindow("collectDbStats");
    try {
        executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null);
        for (int i = 1; i < window.getNumRows(); i++) {
            String name = window.getString(i, 1);
            String path = window.getString(i, 2);
            pageCount = 0;
            pageSize = 0;
            try {
                pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
                pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
            } catch (SQLiteException ex) {
            // Ignore.
            }
            String label = "  (attached) " + name;
            if (!path.isEmpty()) {
                label += ": " + path;
            }
            dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
        }
    } catch (SQLiteException ex) {
    // Ignore.
    } finally {
        window.close();
    }
}
Also used : CursorWindow(android.database.CursorWindow) DbStats(android.database.sqlite.SQLiteDebug.DbStats)

Example 5 with DbStats

use of android.database.sqlite.SQLiteDebug.DbStats in project platform_frameworks_base by android.

the class SQLiteConnection method collectDbStats.

/**
     * Collects statistics about database connection memory usage.
     *
     * @param dbStatsList The list to populate.
     */
void collectDbStats(ArrayList<DbStats> dbStatsList) {
    // Get information about the main database.
    int lookaside = nativeGetDbLookaside(mConnectionPtr);
    long pageCount = 0;
    long pageSize = 0;
    try {
        pageCount = executeForLong("PRAGMA page_count;", null, null);
        pageSize = executeForLong("PRAGMA page_size;", null, null);
    } catch (SQLiteException ex) {
    // Ignore.
    }
    dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
    // Get information about attached databases.
    // We ignore the first row in the database list because it corresponds to
    // the main database which we have already described.
    CursorWindow window = new CursorWindow("collectDbStats");
    try {
        executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null);
        for (int i = 1; i < window.getNumRows(); i++) {
            String name = window.getString(i, 1);
            String path = window.getString(i, 2);
            pageCount = 0;
            pageSize = 0;
            try {
                pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
                pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
            } catch (SQLiteException ex) {
            // Ignore.
            }
            String label = "  (attached) " + name;
            if (!path.isEmpty()) {
                label += ": " + path;
            }
            dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
        }
    } catch (SQLiteException ex) {
    // Ignore.
    } finally {
        window.close();
    }
}
Also used : CursorWindow(android.database.CursorWindow) DbStats(android.database.sqlite.SQLiteDebug.DbStats)

Aggregations

DbStats (android.database.sqlite.SQLiteDebug.DbStats)7 CursorWindow (android.database.CursorWindow)6 MutableBoolean (android.util.MutableBoolean)1 MutableInt (android.util.MutableInt)1 Pair (android.util.Pair)1 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1