diff options
author | The Android Automerger <android-build@android.com> | 2011-11-02 20:58:00 -0700 |
---|---|---|
committer | The Android Automerger <android-build@android.com> | 2011-11-02 20:58:00 -0700 |
commit | 50b193c82d0458a1c225f3042f84618fe3408482 (patch) | |
tree | 823bfd4427767eb376c956e2d524c46ed6810e85 | |
parent | f15af4b0887eba6f04e6fef6b819d11f43d9da45 (diff) | |
download | base-50b193c82d0458a1c225f3042f84618fe3408482.tar.gz |
Revert "Merge "Improve the slow query instrumentation." into ics-mr0"
This reverts commit 2d280f754e32e556407df05d977cfabdfff1c070, reversing
changes made to 2cc1c5d067736f221554be593c2ba2c96390f847.
-rw-r--r-- | core/java/android/database/CursorWindow.java | 18 | ||||
-rw-r--r-- | core/java/android/database/sqlite/SQLiteDatabase.java | 28 | ||||
-rw-r--r-- | core/java/android/database/sqlite/SQLiteDebug.java | 24 | ||||
-rw-r--r-- | core/java/android/database/sqlite/SQLiteQuery.java | 20 | ||||
-rw-r--r-- | core/java/android/os/Build.java | 7 | ||||
-rw-r--r-- | core/jni/android_database_CursorWindow.cpp | 7 | ||||
-rw-r--r-- | libs/binder/CursorWindow.cpp | 2 |
7 files changed, 30 insertions, 76 deletions
diff --git a/core/java/android/database/CursorWindow.java b/core/java/android/database/CursorWindow.java index a1be121aaf9d..380236b49948 100644 --- a/core/java/android/database/CursorWindow.java +++ b/core/java/android/database/CursorWindow.java @@ -55,7 +55,6 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { public int mWindowPtr; private int mStartPos; - private final String mName; private final CloseGuard mCloseGuard = CloseGuard.get(); @@ -86,8 +85,6 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { private static native boolean nativePutDouble(int windowPtr, double value, int row, int column); private static native boolean nativePutNull(int windowPtr, int row, int column); - private static native String nativeGetName(int windowPtr); - /** * Creates a new empty cursor window and gives it a name. * <p> @@ -103,7 +100,6 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { */ public CursorWindow(String name, boolean localWindow) { mStartPos = 0; - mName = name; mWindowPtr = nativeCreate(name, sCursorWindowSize, localWindow); if (mWindowPtr == 0) { throw new CursorWindowAllocationException("Cursor window allocation of " + @@ -134,7 +130,6 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { throw new CursorWindowAllocationException("Cursor window could not be " + "created from binder."); } - mName = nativeGetName(mWindowPtr); mCloseGuard.open("close"); } @@ -162,14 +157,6 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { } /** - * Gets the name of this cursor window. - * @hide - */ - public String getName() { - return mName; - } - - /** * Closes the cursor window and frees its underlying resources when all other * remaining references have been released. */ @@ -791,9 +778,4 @@ public class CursorWindow extends SQLiteClosable implements Parcelable { String s = (buff.length() > 980) ? buff.substring(0, 980) : buff.toString(); return "# Open Cursors=" + total + s; } - - @Override - public String toString() { - return getName() + " {" + Integer.toHexString(mWindowPtr) + "}"; - } } diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index f990be60809d..00d7ce80a6fa 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -306,6 +306,10 @@ public class SQLiteDatabase extends SQLiteClosable { /** Used to find out where this object was created in case it never got closed. */ private final Throwable mStackTrace; + // System property that enables logging of slow queries. Specify the threshold in ms. + private static final String LOG_SLOW_QUERIES_PROPERTY = "db.log.slow_query_threshold"; + private final int mSlowQueryThreshold; + /** stores the list of statement ids that need to be finalized by sqlite */ private final ArrayList<Integer> mClosedStatementIds = new ArrayList<Integer>(); @@ -1555,6 +1559,11 @@ public class SQLiteDatabase extends SQLiteClosable { String editTable) { verifyDbIsOpen(); BlockGuard.getThreadPolicy().onReadFromDisk(); + long timeStart = 0; + + if (false || mSlowQueryThreshold != -1) { + timeStart = System.currentTimeMillis(); + } SQLiteDatabase db = getDbConnection(sql); SQLiteCursorDriver driver = new SQLiteDirectCursorDriver(db, sql, editTable); @@ -1565,6 +1574,24 @@ public class SQLiteDatabase extends SQLiteClosable { cursorFactory != null ? cursorFactory : mFactory, selectionArgs); } finally { + if (false || mSlowQueryThreshold != -1) { + + // Force query execution + int count = -1; + if (cursor != null) { + count = cursor.getCount(); + } + + long duration = System.currentTimeMillis() - timeStart; + + if (false || duration >= mSlowQueryThreshold) { + Log.v(SQLiteCursor.TAG, + "query (" + duration + " ms): " + driver.toString() + ", args are " + + (selectionArgs != null + ? TextUtils.join(",", selectionArgs) + : "<null>") + ", count is " + count); + } + } releaseDbConnection(db); } return cursor; @@ -1940,6 +1967,7 @@ public class SQLiteDatabase extends SQLiteClosable { setMaxSqlCacheSize(DEFAULT_SQL_CACHE_SIZE); mFlags = flags; mPath = path; + mSlowQueryThreshold = SystemProperties.getInt(LOG_SLOW_QUERIES_PROPERTY, -1); mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace(); mFactory = factory; mPrograms = new WeakHashMap<SQLiteClosable,Object>(); diff --git a/core/java/android/database/sqlite/SQLiteDebug.java b/core/java/android/database/sqlite/SQLiteDebug.java index cc057e016fe3..9496079178e6 100644 --- a/core/java/android/database/sqlite/SQLiteDebug.java +++ b/core/java/android/database/sqlite/SQLiteDebug.java @@ -18,8 +18,6 @@ package android.database.sqlite; import java.util.ArrayList; -import android.os.Build; -import android.os.SystemProperties; import android.util.Log; /** @@ -67,28 +65,6 @@ public final class SQLiteDebug { Log.isLoggable("SQLiteLockStackTrace", Log.VERBOSE); /** - * True to enable database performance testing instrumentation. - * @hide - */ - public static final boolean DEBUG_LOG_SLOW_QUERIES = Build.IS_DEBUGGABLE; - - /** - * Determines whether a query should be logged. - * - * Reads the "db.log.slow_query_threshold" system property, which can be changed - * by the user at any time. If the value is zero, then all queries will - * be considered slow. If the value does not exist, then no queries will - * be considered slow. - * - * This value can be changed dynamically while the system is running. - * @hide - */ - public static final boolean shouldLogSlowQuery(long elapsedTimeMillis) { - int slowQueryMillis = SystemProperties.getInt("db.log.slow_query_threshold", -1); - return slowQueryMillis >= 0 && elapsedTimeMillis > slowQueryMillis; - } - - /** * Contains statistics about the active pagers in the current process. * * @see #getPagerStats(PagerStats) diff --git a/core/java/android/database/sqlite/SQLiteQuery.java b/core/java/android/database/sqlite/SQLiteQuery.java index faf6cba10679..7db0914140b2 100644 --- a/core/java/android/database/sqlite/SQLiteQuery.java +++ b/core/java/android/database/sqlite/SQLiteQuery.java @@ -18,7 +18,6 @@ package android.database.sqlite; import android.database.CursorWindow; import android.os.SystemClock; -import android.text.TextUtils; import android.util.Log; /** @@ -33,7 +32,6 @@ public class SQLiteQuery extends SQLiteProgram { private static native int nativeFillWindow(int databasePtr, int statementPtr, int windowPtr, int startPos, int offsetParam); - private static native int nativeColumnCount(int statementPtr); private static native String nativeColumnName(int statementPtr, int columnIndex); @@ -82,24 +80,8 @@ public class SQLiteQuery extends SQLiteProgram { acquireReference(); try { window.acquireReference(); - int startPos = window.getStartPosition(); int numRows = nativeFillWindow(nHandle, nStatement, window.mWindowPtr, - startPos, mOffsetIndex); - if (SQLiteDebug.DEBUG_LOG_SLOW_QUERIES) { - long elapsed = SystemClock.uptimeMillis() - timeStart; - if (SQLiteDebug.shouldLogSlowQuery(elapsed)) { - Log.d(TAG, "fillWindow took " + elapsed - + " ms: window=\"" + window - + "\", startPos=" + startPos - + ", offset=" + mOffsetIndex - + ", filledRows=" + window.getNumRows() - + ", countedRows=" + numRows - + ", query=\"" + mSql + "\"" - + ", args=[" + (mBindArgs != null ? - TextUtils.join(", ", mBindArgs.values()) : "") - + "]"); - } - } + window.getStartPosition(), mOffsetIndex); mDatabase.logTimeStat(mSql, timeStart); return numRows; } catch (IllegalStateException e){ diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java index 17a882de1a8c..5faab3603986 100644 --- a/core/java/android/os/Build.java +++ b/core/java/android/os/Build.java @@ -326,13 +326,6 @@ public class Build { public static final String HOST = getString("ro.build.host"); /** - * Returns true if we are running a debug build such as "user-debug" or "eng". - * @hide - */ - public static final boolean IS_DEBUGGABLE = - SystemProperties.getInt("ro.debuggable", 0) == 1; - - /** * Returns the version string for the radio firmware. May return * null (if, for instance, the radio is not currently on). */ diff --git a/core/jni/android_database_CursorWindow.cpp b/core/jni/android_database_CursorWindow.cpp index 9725c9ff6768..722aeea68296 100644 --- a/core/jni/android_database_CursorWindow.cpp +++ b/core/jni/android_database_CursorWindow.cpp @@ -104,11 +104,6 @@ static void nativeDispose(JNIEnv* env, jclass clazz, jint windowPtr) { } } -static jstring nativeGetName(JNIEnv* env, jclass clazz, jint windowPtr) { - CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); - return env->NewStringUTF(window->name().string()); -} - static void nativeWriteToParcel(JNIEnv * env, jclass clazz, jint windowPtr, jobject parcelObj) { CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); @@ -490,8 +485,6 @@ static JNINativeMethod sMethods[] = (void*)nativeDispose }, { "nativeWriteToParcel", "(ILandroid/os/Parcel;)V", (void*)nativeWriteToParcel }, - { "nativeGetName", "(I)Ljava/lang/String;", - (void*)nativeGetName }, { "nativeClear", "(I)V", (void*)nativeClear }, { "nativeGetNumRows", "(I)I", diff --git a/libs/binder/CursorWindow.cpp b/libs/binder/CursorWindow.cpp index 60681c420715..1b85a71ca8ff 100644 --- a/libs/binder/CursorWindow.cpp +++ b/libs/binder/CursorWindow.cpp @@ -211,7 +211,7 @@ uint32_t CursorWindow::alloc(size_t size, bool aligned) { uint32_t offset = mHeader->freeOffset + padding; uint32_t nextFreeOffset = offset + size; if (nextFreeOffset > mSize) { - LOGW("Window is full: requested allocation %d bytes, " + LOGE("Window is full: requested allocation %d bytes, " "free space %d bytes, window size %d bytes", size, freeSpace(), mSize); return 0; |