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

Commit 624002b0 authored by Vasu Nori's avatar Vasu Nori
Browse files

print certain rows from downloads.db when bugreports are taken

when downloads fail/get stuck, we need to look at the database state
for those downloads. and when the users report such problems, it is
a royal pain not to have that info and most users don't seem to bother
sending database dumps because it is a bit of work.

so lets just dump info about downloads that failed or
downloads from GSF (OTAs, for example)

helps debugging. there is STOP ship comment to not dump data once
HC is released.

Change-Id: Id1254982fd82b4c55f1816a2491f00966840f024
parent 3644bf11
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -870,6 +870,12 @@ public final class ActivityThread {
                            (dbStats.dbSize > 0) ? String.valueOf(dbStats.dbSize) : " ",
                            (dbStats.lookaside > 0) ? String.valueOf(dbStats.lookaside) : " ",
                            dbStats.cache, dbStats.dbName);
                    if (dbStats.dataDump != null) {
                        int size = dbStats.dataDump.size();
                        for (int dumpIndex = 0; dumpIndex < size; dumpIndex++) {
                            printRow(pw, "%s", dbStats.dataDump.get(dumpIndex));
                        }
                    }
                }
            }

+40 −2
Original line number Diff line number Diff line
@@ -2507,7 +2507,7 @@ public class SQLiteDatabase extends SQLiteClosable {
                    if (pageCount > 0) {
                        dbStatsList.add(new DbStats(dbName, pageCount, db.getPageSize(),
                                lookasideUsed, db.getCacheHitNum(), db.getCacheMissNum(),
                                db.getCachesize()));
                                db.getCachesize(), getDataDump(db)));
                    }
                }
                // if there are pooled connections, return the cache stats for them also.
@@ -2518,7 +2518,7 @@ public class SQLiteDatabase extends SQLiteClosable {
                    for (SQLiteDatabase pDb : connPool.getConnectionList()) {
                        dbStatsList.add(new DbStats("(pooled # " + pDb.mConnectionNum + ") "
                                + lastnode, 0, 0, 0, pDb.getCacheHitNum(),
                                pDb.getCacheMissNum(), pDb.getCachesize()));
                                pDb.getCacheMissNum(), pDb.getCachesize(), null));
                    }
                }
            } catch (SQLiteException e) {
@@ -2529,6 +2529,44 @@ public class SQLiteDatabase extends SQLiteClosable {
        return dbStatsList;
    }

    private static ArrayList<String> getDataDump(SQLiteDatabase db) {
        // create database dump of certain data from certain databases for debugging purposes
        if (db.getPath().equalsIgnoreCase(
                "/data/data/com.android.providers.downloads/databases/downloads.db")) {
            String sql =
                    "select * from downloads " +
                    " where notificationpackage = 'com.google.android.gsf'" + 
                    " or status >= 400";
            Cursor cursor = db.rawQuery(sql, null);
            try {
                int count = cursor.getCount();
                if (count == 0) {
                    return null;
                }
                ArrayList<String> buff = new ArrayList<String>();
                buff.add("  Data from downloads.db");
                int columnCount = cursor.getColumnCount();
                for (int i =0; i < count && cursor.moveToNext(); i++) {
                    buff.add("    Row#" + i + "");
                    for (int j = 0; j < columnCount; j++) {
                        String colName = cursor.getColumnName(j);
                        String value = cursor.getString(j);
                        buff.add("      " + colName + " = " + value);
                    }
                }
                for (String s : buff)  Log.i("vnoritag", s);
                return buff;
            } catch (SQLiteException e) {
                Log.w(TAG, "exception in executing the sql: " + sql, e);
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }
        return null;
    }

    /**
     * Returns list of full pathnames of all attached databases including the main database
     * by executing 'pragma database_list' on the database.
+10 −6
Original line number Diff line number Diff line
@@ -121,27 +121,31 @@ public final class SQLiteDebug {
     */
    public static class DbStats {
        /** name of the database */
        public String dbName;
        public final String dbName;

        /** the page size for the database */
        public long pageSize;
        public final long pageSize;

        /** the database size */
        public long dbSize;
        public final long dbSize;

        /** documented here http://www.sqlite.org/c3ref/c_dbstatus_lookaside_used.html */
        public int lookaside;
        public final int lookaside;

        /** statement cache stats: hits/misses/cachesize */
        public String cache;
        public final String cache;

        /** database dump of 'useful info for debugging only */
        public final ArrayList<String> dataDump;

        public DbStats(String dbName, long pageCount, long pageSize, int lookaside,
            int hits, int misses, int cachesize) {
            int hits, int misses, int cachesize, ArrayList<String> data) {
            this.dbName = dbName;
            this.pageSize = pageSize / 1024;
            dbSize = (pageCount * pageSize) / 1024;
            this.lookaside = lookaside;
            this.cache = hits + "/" + misses + "/" + cachesize;
            this.dataDump = data;
        }
    }