diff options
author | Grace Kloba <klobag@google.com> | 2009-07-02 15:30:34 -0700 |
---|---|---|
committer | Grace Kloba <klobag@google.com> | 2009-07-02 15:30:34 -0700 |
commit | 340a1b21de7d5f650b15fab2bcda355ae9776f90 (patch) | |
tree | b3426b72b7f235e4149533b63f83ebb40ab1b200 /core/java/android/net | |
parent | 8529fc3a15ebf21441976d1ea1cb623acbd14c40 (diff) | |
download | frameworks_base-340a1b21de7d5f650b15fab2bcda355ae9776f90.zip frameworks_base-340a1b21de7d5f650b15fab2bcda355ae9776f90.tar.gz frameworks_base-340a1b21de7d5f650b15fab2bcda355ae9776f90.tar.bz2 |
Fix the performance collection in the http thread. A connection can be reused. Change the thread time collection based on per request.
Diffstat (limited to 'core/java/android/net')
-rw-r--r-- | core/java/android/net/http/ConnectionThread.java | 28 | ||||
-rw-r--r-- | core/java/android/net/http/RequestQueue.java | 12 |
2 files changed, 29 insertions, 11 deletions
diff --git a/core/java/android/net/http/ConnectionThread.java b/core/java/android/net/http/ConnectionThread.java index 8e759e2..1d0db2b 100644 --- a/core/java/android/net/http/ConnectionThread.java +++ b/core/java/android/net/http/ConnectionThread.java @@ -32,8 +32,8 @@ class ConnectionThread extends Thread { static final int WAIT_TICK = 1000; // Performance probe - long mStartThreadTime; long mCurrentThreadTime; + long mTotalThreadTime; private boolean mWaiting; private volatile boolean mRunning = true; @@ -71,10 +71,18 @@ class ConnectionThread extends Thread { android.os.Process.setThreadPriority( android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE); - mStartThreadTime = -1; - mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); + // these are used to get performance data. When it is not in the timing, + // mCurrentThreadTime is 0. When it starts timing, mCurrentThreadTime is + // first set to -1, it will be set to the current thread time when the + // next request starts. + mCurrentThreadTime = 0; + mTotalThreadTime = 0; while (mRunning) { + if (mCurrentThreadTime == -1) { + mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); + } + Request request; /* Get a request to process */ @@ -86,14 +94,14 @@ class ConnectionThread extends Thread { if (HttpLog.LOGV) HttpLog.v("ConnectionThread: Waiting for work"); mWaiting = true; try { - if (mStartThreadTime != -1) { - mCurrentThreadTime = SystemClock - .currentThreadTimeMillis(); - } mRequestFeeder.wait(); } catch (InterruptedException e) { } mWaiting = false; + if (mCurrentThreadTime != 0) { + mCurrentThreadTime = SystemClock + .currentThreadTimeMillis(); + } } } else { if (HttpLog.LOGV) HttpLog.v("ConnectionThread: new request " + @@ -123,6 +131,12 @@ class ConnectionThread extends Thread { mConnection.closeConnection(); } mConnection = null; + + if (mCurrentThreadTime > 0) { + long start = mCurrentThreadTime; + mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); + mTotalThreadTime += mCurrentThreadTime - start; + } } } diff --git a/core/java/android/net/http/RequestQueue.java b/core/java/android/net/http/RequestQueue.java index 54a1cce..4d3e7c3 100644 --- a/core/java/android/net/http/RequestQueue.java +++ b/core/java/android/net/http/RequestQueue.java @@ -279,7 +279,9 @@ public class RequestQueue implements RequestFeeder { public void startTiming() { for (int i = 0; i < mConnectionCount; i++) { - mThreads[i].mStartThreadTime = mThreads[i].mCurrentThreadTime; + ConnectionThread rt = mThreads[i]; + rt.mCurrentThreadTime = -1; + rt.mTotalThreadTime = 0; } mTotalRequest = 0; mTotalConnection = 0; @@ -289,12 +291,14 @@ public class RequestQueue implements RequestFeeder { int totalTime = 0; for (int i = 0; i < mConnectionCount; i++) { ConnectionThread rt = mThreads[i]; - totalTime += (rt.mCurrentThreadTime - rt.mStartThreadTime); - rt.mStartThreadTime = -1; + if (rt.mCurrentThreadTime != -1) { + totalTime += rt.mTotalThreadTime; + } + rt.mCurrentThreadTime = 0; } Log.d("Http", "Http thread used " + totalTime + " ms " + " for " + mTotalRequest + " requests and " + mTotalConnection - + " connections"); + + " new connections"); } void logState() { |