SQLiteDebug.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
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.Config;
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 = Config.LOGV;
31
32    /**
33     * Controls the stack trace reporting of active cursors being
34     * finalized.
35     */
36    public static final boolean DEBUG_ACTIVE_CURSOR_FINALIZATION = Config.LOGV;
37
38    /**
39     * Controls the tracking of time spent holding the database lock.
40     */
41    public static final boolean DEBUG_LOCK_TIME_TRACKING = false;
42
43    /**
44     * Controls the printing of stack traces when tracking the time spent holding the database lock.
45     */
46    public static final boolean DEBUG_LOCK_TIME_TRACKING_STACK_TRACE = false;
47
48    /**
49     * Contains statistics about the active pagers in the current process.
50     *
51     * @see #getPagerStats(PagerStats)
52     */
53    public static class PagerStats {
54        /** The total number of bytes in all pagers in the current process */
55        public long totalBytes;
56        /** The number of bytes in referenced pages in all pagers in the current process */
57        public long referencedBytes;
58        /** The number of bytes in all database files opened in the current process */
59        public long databaseBytes;
60        /** The number of pagers opened in the current process */
61        public int numPagers;
62    }
63
64    /**
65     * Gathers statistics about all pagers in the current process.
66     */
67    public static native void getPagerStats(PagerStats stats);
68
69    /**
70     * Returns the size of the SQLite heap.
71     * @return The size of the SQLite heap in bytes.
72     */
73    public static native long getHeapSize();
74
75    /**
76     * Returns the amount of allocated memory in the SQLite heap.
77     * @return The allocated size in bytes.
78     */
79    public static native long getHeapAllocatedSize();
80
81    /**
82     * Returns the amount of free memory in the SQLite heap.
83     * @return The freed size in bytes.
84     */
85    public static native long getHeapFreeSize();
86
87    /**
88     * Determines the number of dirty belonging to the SQLite
89     * heap segments of this process.  pages[0] returns the number of
90     * shared pages, pages[1] returns the number of private pages
91     */
92    public static native void getHeapDirtyPages(int[] pages);
93
94    private static int sNumActiveCursorsFinalized = 0;
95
96    /**
97     * Returns the number of active cursors that have been finalized. This depends on the GC having
98     * run but is still useful for tests.
99     */
100    public static int getNumActiveCursorsFinalized() {
101        return sNumActiveCursorsFinalized;
102    }
103
104    static synchronized void notifyActiveCursorFinalized() {
105        sNumActiveCursorsFinalized++;
106    }
107}
108