Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1202cf15 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick Committed by Android (Google) Code Review
Browse files

Merge "Measure walltime in ContentResolver and SQLiteDatabase operations logging."

parents dc2df328 d72f718c
Loading
Loading
Loading
Loading
+11 −10
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Config;
import android.util.Config;
import android.util.EventLog;
import android.util.EventLog;
@@ -243,13 +244,13 @@ public abstract class ContentResolver {
            return null;
            return null;
        }
        }
        try {
        try {
            long startTime = System.currentTimeMillis();
            long startTime = SystemClock.uptimeMillis();
            Cursor qCursor = provider.query(uri, projection, selection, selectionArgs, sortOrder);
            Cursor qCursor = provider.query(uri, projection, selection, selectionArgs, sortOrder);
            if (qCursor == null) {
            if (qCursor == null) {
                releaseProvider(provider);
                releaseProvider(provider);
                return null;
                return null;
            }
            }
            long durationMillis = System.currentTimeMillis() - startTime;
            long durationMillis = SystemClock.uptimeMillis() - startTime;
            maybeLogQueryToEventLog(durationMillis, uri, projection, selection, sortOrder);
            maybeLogQueryToEventLog(durationMillis, uri, projection, selection, sortOrder);
            // Wrap the cursor object into CursorWrapperInner object
            // Wrap the cursor object into CursorWrapperInner object
            return new CursorWrapperInner(qCursor, provider);
            return new CursorWrapperInner(qCursor, provider);
@@ -583,9 +584,9 @@ public abstract class ContentResolver {
            throw new IllegalArgumentException("Unknown URL " + url);
            throw new IllegalArgumentException("Unknown URL " + url);
        }
        }
        try {
        try {
            long startTime = System.currentTimeMillis();
            long startTime = SystemClock.uptimeMillis();
            Uri createdRow = provider.insert(url, values);
            Uri createdRow = provider.insert(url, values);
            long durationMillis = System.currentTimeMillis() - startTime;
            long durationMillis = SystemClock.uptimeMillis() - startTime;
            maybeLogUpdateToEventLog(durationMillis, url, "insert", null /* where */);
            maybeLogUpdateToEventLog(durationMillis, url, "insert", null /* where */);
            return createdRow;
            return createdRow;
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -642,9 +643,9 @@ public abstract class ContentResolver {
            throw new IllegalArgumentException("Unknown URL " + url);
            throw new IllegalArgumentException("Unknown URL " + url);
        }
        }
        try {
        try {
            long startTime = System.currentTimeMillis();
            long startTime = SystemClock.uptimeMillis();
            int rowsCreated = provider.bulkInsert(url, values);
            int rowsCreated = provider.bulkInsert(url, values);
            long durationMillis = System.currentTimeMillis() - startTime;
            long durationMillis = SystemClock.uptimeMillis() - startTime;
            maybeLogUpdateToEventLog(durationMillis, url, "bulkinsert", null /* where */);
            maybeLogUpdateToEventLog(durationMillis, url, "bulkinsert", null /* where */);
            return rowsCreated;
            return rowsCreated;
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -671,9 +672,9 @@ public abstract class ContentResolver {
            throw new IllegalArgumentException("Unknown URL " + url);
            throw new IllegalArgumentException("Unknown URL " + url);
        }
        }
        try {
        try {
            long startTime = System.currentTimeMillis();
            long startTime = SystemClock.uptimeMillis();
            int rowsDeleted = provider.delete(url, where, selectionArgs);
            int rowsDeleted = provider.delete(url, where, selectionArgs);
            long durationMillis = System.currentTimeMillis() - startTime;
            long durationMillis = SystemClock.uptimeMillis() - startTime;
            maybeLogUpdateToEventLog(durationMillis, url, "delete", where);
            maybeLogUpdateToEventLog(durationMillis, url, "delete", where);
            return rowsDeleted;
            return rowsDeleted;
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -703,9 +704,9 @@ public abstract class ContentResolver {
            throw new IllegalArgumentException("Unknown URI " + uri);
            throw new IllegalArgumentException("Unknown URI " + uri);
        }
        }
        try {
        try {
            long startTime = System.currentTimeMillis();
            long startTime = SystemClock.uptimeMillis();
            int rowsUpdated = provider.update(uri, values, where, selectionArgs);
            int rowsUpdated = provider.update(uri, values, where, selectionArgs);
            long durationMillis = System.currentTimeMillis() - startTime;
            long durationMillis = SystemClock.uptimeMillis() - startTime;
            maybeLogUpdateToEventLog(durationMillis, uri, "update", where);
            maybeLogUpdateToEventLog(durationMillis, uri, "update", where);
            return rowsUpdated;
            return rowsUpdated;
        } catch (RemoteException e) {
        } catch (RemoteException e) {
+9 −9
Original line number Original line Diff line number Diff line
@@ -202,7 +202,7 @@ public class SQLiteDatabase extends SQLiteClosable {
    private long mLastLockMessageTime = 0L;
    private long mLastLockMessageTime = 0L;


    // always log queries which take 100ms+; shorter queries are sampled accordingly
    // always log queries which take 100ms+; shorter queries are sampled accordingly
    private static final int QUERY_LOG_TIME_IN_NANOS = 100 * 1000000;
    private static final int QUERY_LOG_TIME_IN_MILLIS = 100;
    private static final int QUERY_LOG_SQL_LENGTH = 64;
    private static final int QUERY_LOG_SQL_LENGTH = 64;
    private final Random mRandom = new Random();
    private final Random mRandom = new Random();


@@ -1650,7 +1650,7 @@ public class SQLiteDatabase extends SQLiteClosable {
     * @throws SQLException If the SQL string is invalid for some reason
     * @throws SQLException If the SQL string is invalid for some reason
     */
     */
    public void execSQL(String sql) throws SQLException {
    public void execSQL(String sql) throws SQLException {
        long timeStart = Debug.threadCpuTimeNanos();
        long timeStart = SystemClock.uptimeMillis();
        lock();
        lock();
        try {
        try {
            native_execSQL(sql);
            native_execSQL(sql);
@@ -1676,7 +1676,7 @@ public class SQLiteDatabase extends SQLiteClosable {
        if (bindArgs == null) {
        if (bindArgs == null) {
            throw new IllegalArgumentException("Empty bindArgs");
            throw new IllegalArgumentException("Empty bindArgs");
        }
        }
        long timeStart = Debug.threadCpuTimeNanos();
        long timeStart = SystemClock.uptimeMillis();
        lock();
        lock();
        SQLiteStatement statement = null;
        SQLiteStatement statement = null;
        try {
        try {
@@ -1785,17 +1785,17 @@ public class SQLiteDatabase extends SQLiteClosable {






    /* package */ void logTimeStat(String sql, long beginNanos) {
    /* package */ void logTimeStat(String sql, long beginMillis) {
        // Sample fast queries in proportion to the time taken.
        // Sample fast queries in proportion to the time taken.
        // Quantize the % first, so the logged sampling probability
        // Quantize the % first, so the logged sampling probability
        // exactly equals the actual sampling rate for this query.
        // exactly equals the actual sampling rate for this query.


        int samplePercent;
        int samplePercent;
        long nanos = Debug.threadCpuTimeNanos() - beginNanos;
        long durationMillis = SystemClock.uptimeMillis() - beginMillis;
        if (nanos >= QUERY_LOG_TIME_IN_NANOS) {
        if (durationMillis >= QUERY_LOG_TIME_IN_MILLIS) {
            samplePercent = 100;
            samplePercent = 100;
        } else {
        } else {
            samplePercent = (int) (100 * nanos / QUERY_LOG_TIME_IN_NANOS) + 1;
            samplePercent = (int) (100 * durationMillis / QUERY_LOG_TIME_IN_MILLIS) + 1;
            if (mRandom.nextInt(100) >= samplePercent) return;
            if (mRandom.nextInt(100) >= samplePercent) return;
        }
        }


@@ -1812,8 +1812,8 @@ public class SQLiteDatabase extends SQLiteClosable {
        String blockingPackage = ActivityThread.currentPackageName();
        String blockingPackage = ActivityThread.currentPackageName();
        if (blockingPackage == null) blockingPackage = "";
        if (blockingPackage == null) blockingPackage = "";


        int millis = (int) (nanos / 1000000);
        EventLog.writeEvent(
        EventLog.writeEvent(EVENT_DB_OPERATION, mPath, sql, millis, blockingPackage, samplePercent);
            EVENT_DB_OPERATION, mPath, sql, durationMillis, blockingPackage, samplePercent);
    }
    }


    /**
    /**