diff options
author | Brad Fitzpatrick <bradfitz@android.com> | 2010-07-27 14:03:23 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@android.com> | 2010-07-27 14:03:23 -0700 |
commit | a1f5352a049cbce5f41176d426fcf3b21d523e26 (patch) | |
tree | 10c853d7668d35e733cfc0589ace7f7dc7bb9702 | |
parent | 2fa1dd9e02d9b5b166ba80c9004703311829e128 (diff) | |
download | experimental-a1f5352a049cbce5f41176d426fcf3b21d523e26.tar.gz |
StrictMode measurement buttons
Change-Id: I84a04ba049e7477f14afc02e97ebcfbba706f62a
-rw-r--r-- | RpcPerformance/res/layout/main.xml | 34 | ||||
-rw-r--r-- | RpcPerformance/src/com/android/rpc_performance/ProviderPerfActivity.java | 37 |
2 files changed, 71 insertions, 0 deletions
diff --git a/RpcPerformance/res/layout/main.xml b/RpcPerformance/res/layout/main.xml index fbbf431..3afed05 100644 --- a/RpcPerformance/res/layout/main.xml +++ b/RpcPerformance/res/layout/main.xml @@ -334,6 +334,40 @@ android:text="Parcel.recycle()" /> </LinearLayout> </TableRow> + + <TableRow> + <LinearLayout android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:orientation="vertical"> + <TextView + android:id="@+id/strictmode_text" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="StrictMode.set:" /> + <Button + android:id="@+id/strictmode_button" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="StrictMode (both)" /> + </LinearLayout> + + <LinearLayout android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:orientation="vertical"> + <TextView + android:id="@+id/binderstrict_text" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="Binder.setStrictMode:" /> + <Button + android:id="@+id/binderstrict_button" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="Binder strictMode (JNI)" /> + </LinearLayout> + + </TableRow> + </TableLayout> </ScrollView> diff --git a/RpcPerformance/src/com/android/rpc_performance/ProviderPerfActivity.java b/RpcPerformance/src/com/android/rpc_performance/ProviderPerfActivity.java index d758800..a797f78 100644 --- a/RpcPerformance/src/com/android/rpc_performance/ProviderPerfActivity.java +++ b/RpcPerformance/src/com/android/rpc_performance/ProviderPerfActivity.java @@ -38,6 +38,7 @@ import android.database.SQLException; import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.net.Uri; +import android.os.Binder; import android.os.Bundle; import android.os.Debug; import android.os.Handler; @@ -46,6 +47,7 @@ import android.os.Parcel; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; +import android.os.StrictMode; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.AndroidException; @@ -209,6 +211,18 @@ public class ProviderPerfActivity extends Activity { final float avgTime = parcelLoop(false); endAsyncOp(R.id.recycle_button, R.id.recycle_text, avgTime); }}); + + setButtonAction(R.id.strictmode_button, new Runnable() { + public void run() { + final float avgTime = strictModeLoop(true); + endAsyncOp(R.id.strictmode_button, R.id.strictmode_text, avgTime); + }}); + + setButtonAction(R.id.binderstrict_button, new Runnable() { + public void run() { + final float avgTime = strictModeLoop(false); + endAsyncOp(R.id.binderstrict_button, R.id.binderstrict_text, avgTime); + }}); } @Override public void onResume() { @@ -541,6 +555,29 @@ public class ProviderPerfActivity extends Activity { return (float) sumNanos / Math.max(1.0f, (float) mIterations) / 1000000.0f; } + private float strictModeLoop(boolean full) { + int oldPolicy = StrictMode.getThreadBlockingPolicy(); + long sumNanos = 0; + for (int i = 0; i < mIterations; i++) { + int policy = ((i & 1) == 1) ? 1 : 2; + if (full) { + long lastTime = System.nanoTime(); + StrictMode.setThreadBlockingPolicy(policy); + sumNanos += System.nanoTime() - lastTime; + } else { + long lastTime = System.nanoTime(); + Binder.setThreadStrictModePolicy(policy); + sumNanos += System.nanoTime() - lastTime; + } + } + if (full) { + StrictMode.setThreadBlockingPolicy(oldPolicy); + } else { + Binder.setThreadStrictModePolicy(oldPolicy); + } + return (float) sumNanos / Math.max(1.0f, (float) mIterations) / 1000000.0f; + } + // Returns average milliseconds. private static final int MODE_READ = 0; private static final int MODE_WRITE = 1; |