SQLiteDebug.java revision 3ef94e25b4c896ecaa85aa2c12b8863ecdf98df0
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.database.sqlite; 18 19import android.util.Log; 20 21/** 22 * Provides debugging info about all SQLite databases running in the current process. 23 * 24 * {@hide} 25 */ 26public final class SQLiteDebug { 27 /** 28 * Controls the printing of SQL statements as they are executed. 29 */ 30 public static final boolean DEBUG_SQL_STATEMENTS = 31 Log.isLoggable("SQLiteStatements", Log.VERBOSE); 32 33 /** 34 * Controls the printing of wall-clock time taken to execute SQL statements 35 * as they are executed. 36 */ 37 public static final boolean DEBUG_SQL_TIME = 38 Log.isLoggable("SQLiteTime", Log.VERBOSE); 39 40 /** 41 * Controls the printing of compiled-sql-statement cache stats. 42 */ 43 public static final boolean DEBUG_SQL_CACHE = 44 Log.isLoggable("SQLiteCompiledSql", Log.VERBOSE); 45 46 /** 47 * Controls the stack trace reporting of active cursors being 48 * finalized. 49 */ 50 public static final boolean DEBUG_ACTIVE_CURSOR_FINALIZATION = 51 Log.isLoggable("SQLiteCursorClosing", Log.VERBOSE); 52 53 /** 54 * Controls the tracking of time spent holding the database lock. 55 */ 56 public static final boolean DEBUG_LOCK_TIME_TRACKING = 57 Log.isLoggable("SQLiteLockTime", Log.VERBOSE); 58 59 /** 60 * Controls the printing of stack traces when tracking the time spent holding the database lock. 61 */ 62 public static final boolean DEBUG_LOCK_TIME_TRACKING_STACK_TRACE = 63 Log.isLoggable("SQLiteLockStackTrace", Log.VERBOSE); 64 65 /** 66 * Contains statistics about the active pagers in the current process. 67 * 68 * @see #getPagerStats(PagerStats) 69 */ 70 public static class PagerStats { 71 /** The total number of bytes in all pagers in the current process */ 72 public long totalBytes; 73 /** The number of bytes in referenced pages in all pagers in the current process */ 74 public long referencedBytes; 75 /** The number of bytes in all database files opened in the current process */ 76 public long databaseBytes; 77 /** The number of pagers opened in the current process */ 78 public int numPagers; 79 } 80 81 /** 82 * Gathers statistics about all pagers in the current process. 83 */ 84 public static native void getPagerStats(PagerStats stats); 85 86 /** 87 * Returns the size of the SQLite heap. 88 * @return The size of the SQLite heap in bytes. 89 */ 90 public static native long getHeapSize(); 91 92 /** 93 * Returns the amount of allocated memory in the SQLite heap. 94 * @return The allocated size in bytes. 95 */ 96 public static native long getHeapAllocatedSize(); 97 98 /** 99 * Returns the amount of free memory in the SQLite heap. 100 * @return The freed size in bytes. 101 */ 102 public static native long getHeapFreeSize(); 103 104 /** 105 * Determines the number of dirty belonging to the SQLite 106 * heap segments of this process. pages[0] returns the number of 107 * shared pages, pages[1] returns the number of private pages 108 */ 109 public static native void getHeapDirtyPages(int[] pages); 110 111 private static int sNumActiveCursorsFinalized = 0; 112 113 /** 114 * Returns the number of active cursors that have been finalized. This depends on the GC having 115 * run but is still useful for tests. 116 */ 117 public static int getNumActiveCursorsFinalized() { 118 return sNumActiveCursorsFinalized; 119 } 120 121 static synchronized void notifyActiveCursorFinalized() { 122 sNumActiveCursorsFinalized++; 123 } 124} 125