• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.database.sqlite;
18 
19 import android.util.Config;
20 import android.util.Log;
21 
22 /**
23  * Provides debugging info about all SQLite databases running in the current process.
24  *
25  * {@hide}
26  */
27 public final class SQLiteDebug {
28     /**
29      * Controls the printing of SQL statements as they are executed.
30      */
31     public static final boolean DEBUG_SQL_STATEMENTS =
32             Log.isLoggable("SQLiteStatements", Log.VERBOSE);
33 
34     /**
35      * Controls the stack trace reporting of active cursors being
36      * finalized.
37      */
38     public static final boolean DEBUG_ACTIVE_CURSOR_FINALIZATION =
39             Log.isLoggable("SQLiteCursorClosing", Log.VERBOSE);
40 
41     /**
42      * Controls the tracking of time spent holding the database lock.
43      */
44     public static final boolean DEBUG_LOCK_TIME_TRACKING =
45             Log.isLoggable("SQLiteLockTime", Log.VERBOSE);
46 
47     /**
48      * Controls the printing of stack traces when tracking the time spent holding the database lock.
49      */
50     public static final boolean DEBUG_LOCK_TIME_TRACKING_STACK_TRACE =
51             Log.isLoggable("SQLiteLockStackTrace", Log.VERBOSE);
52 
53     /**
54      * Contains statistics about the active pagers in the current process.
55      *
56      * @see #getPagerStats(PagerStats)
57      */
58     public static class PagerStats {
59         /** The total number of bytes in all pagers in the current process */
60         public long totalBytes;
61         /** The number of bytes in referenced pages in all pagers in the current process */
62         public long referencedBytes;
63         /** The number of bytes in all database files opened in the current process */
64         public long databaseBytes;
65         /** The number of pagers opened in the current process */
66         public int numPagers;
67     }
68 
69     /**
70      * Gathers statistics about all pagers in the current process.
71      */
getPagerStats(PagerStats stats)72     public static native void getPagerStats(PagerStats stats);
73 
74     /**
75      * Returns the size of the SQLite heap.
76      * @return The size of the SQLite heap in bytes.
77      */
getHeapSize()78     public static native long getHeapSize();
79 
80     /**
81      * Returns the amount of allocated memory in the SQLite heap.
82      * @return The allocated size in bytes.
83      */
getHeapAllocatedSize()84     public static native long getHeapAllocatedSize();
85 
86     /**
87      * Returns the amount of free memory in the SQLite heap.
88      * @return The freed size in bytes.
89      */
getHeapFreeSize()90     public static native long getHeapFreeSize();
91 
92     /**
93      * Determines the number of dirty belonging to the SQLite
94      * heap segments of this process.  pages[0] returns the number of
95      * shared pages, pages[1] returns the number of private pages
96      */
getHeapDirtyPages(int[] pages)97     public static native void getHeapDirtyPages(int[] pages);
98 
99     private static int sNumActiveCursorsFinalized = 0;
100 
101     /**
102      * Returns the number of active cursors that have been finalized. This depends on the GC having
103      * run but is still useful for tests.
104      */
getNumActiveCursorsFinalized()105     public static int getNumActiveCursorsFinalized() {
106         return sNumActiveCursorsFinalized;
107     }
108 
notifyActiveCursorFinalized()109     static synchronized void notifyActiveCursorFinalized() {
110         sNumActiveCursorsFinalized++;
111     }
112 }
113