Skip to content

Commit 5db81e1

Browse files
author
The Android Automerger
committed
Revert "Merge "Improve the slow query instrumentation." into ics-mr0"
This reverts commit 2d280f7, reversing changes made to 2cc1c5d.
1 parent 8063b84 commit 5db81e1

File tree

7 files changed

+30
-76
lines changed

7 files changed

+30
-76
lines changed

core/java/android/database/CursorWindow.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class CursorWindow extends SQLiteClosable implements Parcelable {
5555
public int mWindowPtr;
5656

5757
private int mStartPos;
58-
private final String mName;
5958

6059
private final CloseGuard mCloseGuard = CloseGuard.get();
6160

@@ -86,8 +85,6 @@ private static native void nativeCopyStringToBuffer(int windowPtr, int row, int
8685
private static native boolean nativePutDouble(int windowPtr, double value, int row, int column);
8786
private static native boolean nativePutNull(int windowPtr, int row, int column);
8887

89-
private static native String nativeGetName(int windowPtr);
90-
9188
/**
9289
* Creates a new empty cursor window and gives it a name.
9390
* <p>
@@ -103,7 +100,6 @@ private static native void nativeCopyStringToBuffer(int windowPtr, int row, int
103100
*/
104101
public CursorWindow(String name, boolean localWindow) {
105102
mStartPos = 0;
106-
mName = name;
107103
mWindowPtr = nativeCreate(name, sCursorWindowSize, localWindow);
108104
if (mWindowPtr == 0) {
109105
throw new CursorWindowAllocationException("Cursor window allocation of " +
@@ -134,7 +130,6 @@ private CursorWindow(Parcel source) {
134130
throw new CursorWindowAllocationException("Cursor window could not be "
135131
+ "created from binder.");
136132
}
137-
mName = nativeGetName(mWindowPtr);
138133
mCloseGuard.open("close");
139134
}
140135

@@ -161,14 +156,6 @@ private void dispose() {
161156
}
162157
}
163158

164-
/**
165-
* Gets the name of this cursor window.
166-
* @hide
167-
*/
168-
public String getName() {
169-
return mName;
170-
}
171-
172159
/**
173160
* Closes the cursor window and frees its underlying resources when all other
174161
* remaining references have been released.
@@ -791,9 +778,4 @@ private String printStats() {
791778
String s = (buff.length() > 980) ? buff.substring(0, 980) : buff.toString();
792779
return "# Open Cursors=" + total + s;
793780
}
794-
795-
@Override
796-
public String toString() {
797-
return getName() + " {" + Integer.toHexString(mWindowPtr) + "}";
798-
}
799781
}

core/java/android/database/sqlite/SQLiteDatabase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ synchronized void setLastSqlStatement(String sql) {
306306
/** Used to find out where this object was created in case it never got closed. */
307307
private final Throwable mStackTrace;
308308

309+
// System property that enables logging of slow queries. Specify the threshold in ms.
310+
private static final String LOG_SLOW_QUERIES_PROPERTY = "db.log.slow_query_threshold";
311+
private final int mSlowQueryThreshold;
312+
309313
/** stores the list of statement ids that need to be finalized by sqlite */
310314
private final ArrayList<Integer> mClosedStatementIds = new ArrayList<Integer>();
311315

@@ -1555,6 +1559,11 @@ public Cursor rawQueryWithFactory(
15551559
String editTable) {
15561560
verifyDbIsOpen();
15571561
BlockGuard.getThreadPolicy().onReadFromDisk();
1562+
long timeStart = 0;
1563+
1564+
if (false || mSlowQueryThreshold != -1) {
1565+
timeStart = System.currentTimeMillis();
1566+
}
15581567

15591568
SQLiteDatabase db = getDbConnection(sql);
15601569
SQLiteCursorDriver driver = new SQLiteDirectCursorDriver(db, sql, editTable);
@@ -1565,6 +1574,24 @@ public Cursor rawQueryWithFactory(
15651574
cursorFactory != null ? cursorFactory : mFactory,
15661575
selectionArgs);
15671576
} finally {
1577+
if (false || mSlowQueryThreshold != -1) {
1578+
1579+
// Force query execution
1580+
int count = -1;
1581+
if (cursor != null) {
1582+
count = cursor.getCount();
1583+
}
1584+
1585+
long duration = System.currentTimeMillis() - timeStart;
1586+
1587+
if (false || duration >= mSlowQueryThreshold) {
1588+
Log.v(SQLiteCursor.TAG,
1589+
"query (" + duration + " ms): " + driver.toString() + ", args are "
1590+
+ (selectionArgs != null
1591+
? TextUtils.join(",", selectionArgs)
1592+
: "<null>") + ", count is " + count);
1593+
}
1594+
}
15681595
releaseDbConnection(db);
15691596
}
15701597
return cursor;
@@ -1940,6 +1967,7 @@ private SQLiteDatabase(String path, CursorFactory factory, int flags,
19401967
setMaxSqlCacheSize(DEFAULT_SQL_CACHE_SIZE);
19411968
mFlags = flags;
19421969
mPath = path;
1970+
mSlowQueryThreshold = SystemProperties.getInt(LOG_SLOW_QUERIES_PROPERTY, -1);
19431971
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
19441972
mFactory = factory;
19451973
mPrograms = new WeakHashMap<SQLiteClosable,Object>();

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import java.util.ArrayList;
2020

21-
import android.os.Build;
22-
import android.os.SystemProperties;
2321
import android.util.Log;
2422

2523
/**
@@ -66,28 +64,6 @@ public final class SQLiteDebug {
6664
public static final boolean DEBUG_LOCK_TIME_TRACKING_STACK_TRACE =
6765
Log.isLoggable("SQLiteLockStackTrace", Log.VERBOSE);
6866

69-
/**
70-
* True to enable database performance testing instrumentation.
71-
* @hide
72-
*/
73-
public static final boolean DEBUG_LOG_SLOW_QUERIES = Build.IS_DEBUGGABLE;
74-
75-
/**
76-
* Determines whether a query should be logged.
77-
*
78-
* Reads the "db.log.slow_query_threshold" system property, which can be changed
79-
* by the user at any time. If the value is zero, then all queries will
80-
* be considered slow. If the value does not exist, then no queries will
81-
* be considered slow.
82-
*
83-
* This value can be changed dynamically while the system is running.
84-
* @hide
85-
*/
86-
public static final boolean shouldLogSlowQuery(long elapsedTimeMillis) {
87-
int slowQueryMillis = SystemProperties.getInt("db.log.slow_query_threshold", -1);
88-
return slowQueryMillis >= 0 && elapsedTimeMillis > slowQueryMillis;
89-
}
90-
9167
/**
9268
* Contains statistics about the active pagers in the current process.
9369
*

core/java/android/database/sqlite/SQLiteQuery.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import android.database.CursorWindow;
2020
import android.os.SystemClock;
21-
import android.text.TextUtils;
2221
import android.util.Log;
2322

2423
/**
@@ -33,7 +32,6 @@ public class SQLiteQuery extends SQLiteProgram {
3332

3433
private static native int nativeFillWindow(int databasePtr, int statementPtr, int windowPtr,
3534
int startPos, int offsetParam);
36-
3735
private static native int nativeColumnCount(int statementPtr);
3836
private static native String nativeColumnName(int statementPtr, int columnIndex);
3937

@@ -82,24 +80,8 @@ private static native int nativeFillWindow(int databasePtr, int statementPtr, in
8280
acquireReference();
8381
try {
8482
window.acquireReference();
85-
int startPos = window.getStartPosition();
8683
int numRows = nativeFillWindow(nHandle, nStatement, window.mWindowPtr,
87-
startPos, mOffsetIndex);
88-
if (SQLiteDebug.DEBUG_LOG_SLOW_QUERIES) {
89-
long elapsed = SystemClock.uptimeMillis() - timeStart;
90-
if (SQLiteDebug.shouldLogSlowQuery(elapsed)) {
91-
Log.d(TAG, "fillWindow took " + elapsed
92-
+ " ms: window=\"" + window
93-
+ "\", startPos=" + startPos
94-
+ ", offset=" + mOffsetIndex
95-
+ ", filledRows=" + window.getNumRows()
96-
+ ", countedRows=" + numRows
97-
+ ", query=\"" + mSql + "\""
98-
+ ", args=[" + (mBindArgs != null ?
99-
TextUtils.join(", ", mBindArgs.values()) : "")
100-
+ "]");
101-
}
102-
}
84+
window.getStartPosition(), mOffsetIndex);
10385
mDatabase.logTimeStat(mSql, timeStart);
10486
return numRows;
10587
} catch (IllegalStateException e){

core/java/android/os/Build.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,6 @@ public static class VERSION_CODES {
325325
public static final String USER = getString("ro.build.user");
326326
public static final String HOST = getString("ro.build.host");
327327

328-
/**
329-
* Returns true if we are running a debug build such as "user-debug" or "eng".
330-
* @hide
331-
*/
332-
public static final boolean IS_DEBUGGABLE =
333-
SystemProperties.getInt("ro.debuggable", 0) == 1;
334-
335328
/**
336329
* Returns the version string for the radio firmware. May return
337330
* null (if, for instance, the radio is not currently on).

core/jni/android_database_CursorWindow.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ static void nativeDispose(JNIEnv* env, jclass clazz, jint windowPtr) {
104104
}
105105
}
106106

107-
static jstring nativeGetName(JNIEnv* env, jclass clazz, jint windowPtr) {
108-
CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
109-
return env->NewStringUTF(window->name().string());
110-
}
111-
112107
static void nativeWriteToParcel(JNIEnv * env, jclass clazz, jint windowPtr,
113108
jobject parcelObj) {
114109
CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
@@ -490,8 +485,6 @@ static JNINativeMethod sMethods[] =
490485
(void*)nativeDispose },
491486
{ "nativeWriteToParcel", "(ILandroid/os/Parcel;)V",
492487
(void*)nativeWriteToParcel },
493-
{ "nativeGetName", "(I)Ljava/lang/String;",
494-
(void*)nativeGetName },
495488
{ "nativeClear", "(I)V",
496489
(void*)nativeClear },
497490
{ "nativeGetNumRows", "(I)I",

libs/binder/CursorWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ uint32_t CursorWindow::alloc(size_t size, bool aligned) {
211211
uint32_t offset = mHeader->freeOffset + padding;
212212
uint32_t nextFreeOffset = offset + size;
213213
if (nextFreeOffset > mSize) {
214-
LOGW("Window is full: requested allocation %d bytes, "
214+
LOGE("Window is full: requested allocation %d bytes, "
215215
"free space %d bytes, window size %d bytes",
216216
size, freeSpace(), mSize);
217217
return 0;

0 commit comments

Comments
 (0)