static final int WAIT_TICK = 1000;
// Performance probe
- long mStartThreadTime;
long mCurrentThreadTime;
+ long mTotalThreadTime;
private boolean mWaiting;
private volatile boolean mRunning = true;
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 */
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 " +
mConnection.closeConnection();
}
mConnection = null;
+
+ if (mCurrentThreadTime > 0) {
+ long start = mCurrentThreadTime;
+ mCurrentThreadTime = SystemClock.currentThreadTimeMillis();
+ mTotalThreadTime += mCurrentThreadTime - start;
+ }
}
}
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;
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() {