Skip to content

Commit 2a293b6

Browse files
author
Jeff Brown
committed
Clean up SQLite debugging code.
Deleted a bunch of dead / useless code. Raised number of logged operations in dumpsys dbinfo to 20. Change-Id: I88344ff57a978f200c1f0172141d91e430caa1a9
1 parent 6534c0e commit 2a293b6

File tree

5 files changed

+18
-240
lines changed

5 files changed

+18
-240
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ private class ApplicationThread extends ApplicationThreadNative {
486486
private static final String HEAP_COLUMN = "%13s %8s %8s %8s %8s %8s %8s";
487487
private static final String ONE_COUNT_COLUMN = "%21s %8d";
488488
private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d";
489-
private static final String TWO_COUNT_COLUMNS_DB = "%21s %8d %21s %8d";
490489
private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s";
491490

492491
// Formatting for checkin service - update version if row format changes
@@ -867,7 +866,6 @@ private Debug.MemoryInfo dumpMemInfo(PrintWriter pw, boolean checkin, boolean al
867866
int binderProxyObjectCount = Debug.getBinderProxyObjectCount();
868867
int binderDeathObjectCount = Debug.getBinderDeathObjectCount();
869868
long openSslSocketCount = Debug.countInstancesOfClass(OpenSSLSocketImpl.class);
870-
long sqliteAllocated = SQLiteDebug.getHeapAllocatedSize() / 1024;
871869
SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo();
872870

873871
// For checkin, we print one long comma-separated list of values
@@ -935,9 +933,9 @@ private Debug.MemoryInfo dumpMemInfo(PrintWriter pw, boolean checkin, boolean al
935933
pw.print(openSslSocketCount); pw.print(',');
936934

937935
// SQL
938-
pw.print(sqliteAllocated); pw.print(',');
939936
pw.print(stats.memoryUsed / 1024); pw.print(',');
940-
pw.print(stats.pageCacheOverflo / 1024); pw.print(',');
937+
pw.print(stats.memoryUsed / 1024); pw.print(',');
938+
pw.print(stats.pageCacheOverflow / 1024); pw.print(',');
941939
pw.print(stats.largestMemAlloc / 1024);
942940
for (int i = 0; i < stats.dbStats.size(); i++) {
943941
DbStats dbStats = stats.dbStats.get(i);
@@ -1003,10 +1001,9 @@ private Debug.MemoryInfo dumpMemInfo(PrintWriter pw, boolean checkin, boolean al
10031001
// SQLite mem info
10041002
pw.println(" ");
10051003
pw.println(" SQL");
1006-
printRow(pw, TWO_COUNT_COLUMNS_DB, "heap:", sqliteAllocated, "MEMORY_USED:",
1007-
stats.memoryUsed / 1024);
1008-
printRow(pw, TWO_COUNT_COLUMNS_DB, "PAGECACHE_OVERFLOW:",
1009-
stats.pageCacheOverflo / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024);
1004+
printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024);
1005+
printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:",
1006+
stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024);
10101007
pw.println(" ");
10111008
int N = stats.dbStats.size();
10121009
if (N > 0) {

core/java/android/database/sqlite/SQLiteConnection.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
*/
8585
public final class SQLiteConnection {
8686
private static final String TAG = "SQLiteConnection";
87+
private static final boolean DEBUG = false;
8788

8889
private static final String[] EMPTY_STRING_ARRAY = new String[0];
8990
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
@@ -668,11 +669,12 @@ private void releasePreparedStatement(PreparedStatement statement) {
668669
// When remove() is called, the cache will invoke its entryRemoved() callback,
669670
// which will in turn call finalizePreparedStatement() to finalize and
670671
// recycle the statement.
671-
if (SQLiteDebug.DEBUG_SQL_CACHE) {
672-
Log.v(TAG, "Could not reset prepared statement due to an exception. "
672+
if (DEBUG) {
673+
Log.d(TAG, "Could not reset prepared statement due to an exception. "
673674
+ "Removing it from the cache. SQL: "
674675
+ trimSqlForDisplay(statement.mSql), ex);
675676
}
677+
676678
mPreparedStatementCache.remove(statement.mSql);
677679
}
678680
} else {
@@ -995,7 +997,7 @@ public void dump(Printer printer) {
995997
}
996998

997999
private static final class OperationLog {
998-
private static final int MAX_RECENT_OPERATIONS = 10;
1000+
private static final int MAX_RECENT_OPERATIONS = 20;
9991001
private static final int COOKIE_GENERATION_SHIFT = 8;
10001002
private static final int COOKIE_INDEX_MASK = 0xff;
10011003

core/java/android/database/sqlite/SQLiteCursor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ protected void finalize() {
269269
mStackTrace);
270270
}
271271
close();
272-
SQLiteDebug.notifyActiveCursorFinalized();
273272
}
274273
} finally {
275274
super.finalize();

core/java/android/database/sqlite/SQLiteDebug.java

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,6 @@ public final class SQLiteDebug {
4848
public static final boolean DEBUG_SQL_TIME =
4949
Log.isLoggable("SQLiteTime", Log.VERBOSE);
5050

51-
/**
52-
* Controls the printing of compiled-sql-statement cache stats.
53-
*/
54-
public static final boolean DEBUG_SQL_CACHE =
55-
Log.isLoggable("SQLiteCompiledSql", Log.VERBOSE);
56-
57-
/**
58-
* Controls the stack trace reporting of active cursors being
59-
* finalized.
60-
*/
61-
public static final boolean DEBUG_ACTIVE_CURSOR_FINALIZATION =
62-
Log.isLoggable("SQLiteCursorClosing", Log.VERBOSE);
63-
64-
/**
65-
* Controls the tracking of time spent holding the database lock.
66-
*/
67-
public static final boolean DEBUG_LOCK_TIME_TRACKING =
68-
Log.isLoggable("SQLiteLockTime", Log.VERBOSE);
69-
70-
/**
71-
* Controls the printing of stack traces when tracking the time spent holding the database lock.
72-
*/
73-
public static final boolean DEBUG_LOCK_TIME_TRACKING_STACK_TRACE =
74-
Log.isLoggable("SQLiteLockStackTrace", Log.VERBOSE);
75-
7651
/**
7752
* True to enable database performance testing instrumentation.
7853
* @hide
@@ -101,27 +76,6 @@ public static final boolean shouldLogSlowQuery(long elapsedTimeMillis) {
10176
* @see #getPagerStats(PagerStats)
10277
*/
10378
public static class PagerStats {
104-
/** The total number of bytes in all pagers in the current process
105-
* @deprecated not used any longer
106-
*/
107-
@Deprecated
108-
public long totalBytes;
109-
/** The number of bytes in referenced pages in all pagers in the current process
110-
* @deprecated not used any longer
111-
* */
112-
@Deprecated
113-
public long referencedBytes;
114-
/** The number of bytes in all database files opened in the current process
115-
* @deprecated not used any longer
116-
*/
117-
@Deprecated
118-
public long databaseBytes;
119-
/** The number of pagers opened in the current process
120-
* @deprecated not used any longer
121-
*/
122-
@Deprecated
123-
public int numPagers;
124-
12579
/** the current amount of memory checked out by sqlite using sqlite3_malloc().
12680
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
12781
*/
@@ -134,7 +88,7 @@ public static class PagerStats {
13488
* that overflowed because no space was left in the page cache.
13589
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
13690
*/
137-
public int pageCacheOverflo;
91+
public int pageCacheOverflow;
13892

13993
/** records the largest memory allocation request handed to sqlite3.
14094
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
@@ -207,43 +161,4 @@ public static void dump(Printer printer, String[] args) {
207161
* Gathers statistics about all pagers in the current process.
208162
*/
209163
public static native void getPagerStats(PagerStats stats);
210-
211-
/**
212-
* Returns the size of the SQLite heap.
213-
* @return The size of the SQLite heap in bytes.
214-
*/
215-
public static native long getHeapSize();
216-
217-
/**
218-
* Returns the amount of allocated memory in the SQLite heap.
219-
* @return The allocated size in bytes.
220-
*/
221-
public static native long getHeapAllocatedSize();
222-
223-
/**
224-
* Returns the amount of free memory in the SQLite heap.
225-
* @return The freed size in bytes.
226-
*/
227-
public static native long getHeapFreeSize();
228-
229-
/**
230-
* Determines the number of dirty belonging to the SQLite
231-
* heap segments of this process. pages[0] returns the number of
232-
* shared pages, pages[1] returns the number of private pages
233-
*/
234-
public static native void getHeapDirtyPages(int[] pages);
235-
236-
private static int sNumActiveCursorsFinalized = 0;
237-
238-
/**
239-
* Returns the number of active cursors that have been finalized. This depends on the GC having
240-
* run but is still useful for tests.
241-
*/
242-
public static int getNumActiveCursorsFinalized() {
243-
return sNumActiveCursorsFinalized;
244-
}
245-
246-
static synchronized void notifyActiveCursorFinalized() {
247-
sNumActiveCursorsFinalized++;
248-
}
249164
}

core/jni/android_database_SQLiteDebug.cpp

Lines changed: 7 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@
2626

2727
#include <sqlite3.h>
2828

29-
// From mem_mspace.c in libsqlite
30-
extern "C" mspace sqlite3_get_mspace();
31-
3229
namespace android {
3330

3431
static jfieldID gMemoryUsedField;
35-
static jfieldID gPageCacheOverfloField;
32+
static jfieldID gPageCacheOverflowField;
3633
static jfieldID gLargestMemAllocField;
3734

3835

@@ -41,146 +38,18 @@ static jfieldID gLargestMemAllocField;
4138
static void getPagerStats(JNIEnv *env, jobject clazz, jobject statsObj)
4239
{
4340
int memoryUsed;
44-
int pageCacheOverflo;
41+
int pageCacheOverflow;
4542
int largestMemAlloc;
4643
int unused;
4744

4845
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0);
4946
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0);
50-
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflo, &unused, 0);
47+
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0);
5148
env->SetIntField(statsObj, gMemoryUsedField, memoryUsed);
52-
env->SetIntField(statsObj, gPageCacheOverfloField, pageCacheOverflo);
49+
env->SetIntField(statsObj, gPageCacheOverflowField, pageCacheOverflow);
5350
env->SetIntField(statsObj, gLargestMemAllocField, largestMemAlloc);
5451
}
5552

56-
static jlong getHeapSize(JNIEnv *env, jobject clazz)
57-
{
58-
#if !NO_MALLINFO
59-
struct mallinfo info = mspace_mallinfo(sqlite3_get_mspace());
60-
struct mallinfo info = dlmallinfo();
61-
return (jlong) info.usmblks;
62-
#elif USE_MSPACE
63-
mspace space = sqlite3_get_mspace();
64-
if (space != 0) {
65-
return mspace_footprint(space);
66-
} else {
67-
return 0;
68-
}
69-
#else
70-
return 0;
71-
#endif
72-
}
73-
74-
static jlong getHeapAllocatedSize(JNIEnv *env, jobject clazz)
75-
{
76-
#if !NO_MALLINFO
77-
struct mallinfo info = mspace_mallinfo(sqlite3_get_mspace());
78-
return (jlong) info.uordblks;
79-
#else
80-
return sqlite3_memory_used();
81-
#endif
82-
}
83-
84-
static jlong getHeapFreeSize(JNIEnv *env, jobject clazz)
85-
{
86-
#if !NO_MALLINFO
87-
struct mallinfo info = mspace_mallinfo(sqlite3_get_mspace());
88-
return (jlong) info.fordblks;
89-
#else
90-
return getHeapSize(env, clazz) - sqlite3_memory_used();
91-
#endif
92-
}
93-
94-
static int read_mapinfo(FILE *fp,
95-
int *sharedPages, int *privatePages)
96-
{
97-
char line[1024];
98-
int len;
99-
int skip;
100-
101-
unsigned start = 0, size = 0, resident = 0;
102-
unsigned shared_clean = 0, shared_dirty = 0;
103-
unsigned private_clean = 0, private_dirty = 0;
104-
unsigned referenced = 0;
105-
106-
int isAnon = 0;
107-
int isHeap = 0;
108-
109-
again:
110-
skip = 0;
111-
112-
if(fgets(line, 1024, fp) == 0) return 0;
113-
114-
len = strlen(line);
115-
if (len < 1) return 0;
116-
line[--len] = 0;
117-
118-
/* ignore guard pages */
119-
if (line[18] == '-') skip = 1;
120-
121-
start = strtoul(line, 0, 16);
122-
123-
if (len > 50 && !strncmp(line + 49, "/tmp/sqlite-heap", strlen("/tmp/sqlite-heap"))) {
124-
isHeap = 1;
125-
}
126-
127-
if (fgets(line, 1024, fp) == 0) return 0;
128-
if (sscanf(line, "Size: %d kB", &size) != 1) return 0;
129-
if (fgets(line, 1024, fp) == 0) return 0;
130-
if (sscanf(line, "Rss: %d kB", &resident) != 1) return 0;
131-
if (fgets(line, 1024, fp) == 0) return 0;
132-
if (sscanf(line, "Shared_Clean: %d kB", &shared_clean) != 1) return 0;
133-
if (fgets(line, 1024, fp) == 0) return 0;
134-
if (sscanf(line, "Shared_Dirty: %d kB", &shared_dirty) != 1) return 0;
135-
if (fgets(line, 1024, fp) == 0) return 0;
136-
if (sscanf(line, "Private_Clean: %d kB", &private_clean) != 1) return 0;
137-
if (fgets(line, 1024, fp) == 0) return 0;
138-
if (sscanf(line, "Private_Dirty: %d kB", &private_dirty) != 1) return 0;
139-
if (fgets(line, 1024, fp) == 0) return 0;
140-
if (sscanf(line, "Referenced: %d kB", &referenced) != 1) return 0;
141-
142-
if (skip) {
143-
goto again;
144-
}
145-
146-
if (isHeap) {
147-
*sharedPages += shared_dirty;
148-
*privatePages += private_dirty;
149-
}
150-
return 1;
151-
}
152-
153-
static void load_maps(int pid, int *sharedPages, int *privatePages)
154-
{
155-
char tmp[128];
156-
FILE *fp;
157-
158-
sprintf(tmp, "/proc/%d/smaps", pid);
159-
fp = fopen(tmp, "r");
160-
if (fp == 0) return;
161-
162-
while (read_mapinfo(fp, sharedPages, privatePages) != 0) {
163-
// Do nothing
164-
}
165-
fclose(fp);
166-
}
167-
168-
static void getHeapDirtyPages(JNIEnv *env, jobject clazz, jintArray pages)
169-
{
170-
int _pages[2];
171-
172-
_pages[0] = 0;
173-
_pages[1] = 0;
174-
175-
load_maps(getpid(), &_pages[0], &_pages[1]);
176-
177-
// Convert from kbytes to 4K pages
178-
_pages[0] /= 4;
179-
_pages[1] /= 4;
180-
181-
env->SetIntArrayRegion(pages, 0, 2, _pages);
182-
}
183-
18453
/*
18554
* JNI registration.
18655
*/
@@ -189,10 +58,6 @@ static JNINativeMethod gMethods[] =
18958
{
19059
{ "getPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V",
19160
(void*) getPagerStats },
192-
{ "getHeapSize", "()J", (void*) getHeapSize },
193-
{ "getHeapAllocatedSize", "()J", (void*) getHeapAllocatedSize },
194-
{ "getHeapFreeSize", "()J", (void*) getHeapFreeSize },
195-
{ "getHeapDirtyPages", "([I)V", (void*) getHeapDirtyPages },
19661
};
19762

19863
int register_android_database_SQLiteDebug(JNIEnv *env)
@@ -217,9 +82,9 @@ int register_android_database_SQLiteDebug(JNIEnv *env)
21782
return -1;
21883
}
21984

220-
gPageCacheOverfloField = env->GetFieldID(clazz, "pageCacheOverflo", "I");
221-
if (gPageCacheOverfloField == NULL) {
222-
ALOGE("Can't find pageCacheOverflo");
85+
gPageCacheOverflowField = env->GetFieldID(clazz, "pageCacheOverflow", "I");
86+
if (gPageCacheOverflowField == NULL) {
87+
ALOGE("Can't find pageCacheOverflow");
22388
return -1;
22489
}
22590

0 commit comments

Comments
 (0)