From 80a682bc3d1bdf1e756b799bbcd919678b319ee3 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Fri, 18 Nov 2011 17:14:14 -0800 Subject: Add iteration-limited mode to FrameworkPerf You can run tests for exactly N iterations regardless of duration now, in addition to the previous time-limited behavior. (Clean cherry-pick to break a dependency on a previous patch that needs work before being committed.) Change-Id: I2e6cf511bbe968a6f95391567658722e87dfa1fe --- tests/FrameworkPerf/res/layout/main.xml | 17 ++++++++++++ .../frameworkperf/FrameworkPerfActivity.java | 30 +++++++++++++++++++--- .../src/com/android/frameworkperf/TestArgs.java | 3 +++ .../src/com/android/frameworkperf/TestService.java | 17 +++++++++--- 4 files changed, 61 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/FrameworkPerf/res/layout/main.xml b/tests/FrameworkPerf/res/layout/main.xml index 7812648..e00ad92 100644 --- a/tests/FrameworkPerf/res/layout/main.xml +++ b/tests/FrameworkPerf/res/layout/main.xml @@ -66,7 +66,24 @@ > + + + + + (this, + android.R.layout.simple_spinner_item, mLimitLabels); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mLimitSpinner.setAdapter(adapter); + mLimitSpinner.setOnItemSelectedListener(this); mTestTime = (TextView)findViewById(R.id.testtime); + mLimitLabel = (TextView)findViewById(R.id.limitlabel); mStartButton = (Button)findViewById(R.id.start); mStartButton.setOnClickListener(new View.OnClickListener() { @@ -196,16 +207,23 @@ public class FrameworkPerfActivity extends Activity @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - if (parent == mFgSpinner || parent == mBgSpinner) { + if (parent == mFgSpinner || parent == mBgSpinner || parent == mLimitSpinner) { TestService.Op op = TestService.mAvailOps[position]; if (parent == mFgSpinner) { mFgTestIndex = position; mFgTest = op; ((TextView)findViewById(R.id.fgtext)).setText(mAvailOpDescriptions[position]); - } else { + } else if (parent == mBgSpinner) { mBgTestIndex = position; mBgTest = op; ((TextView)findViewById(R.id.bgtext)).setText(mAvailOpDescriptions[position]); + } else if (parent == mLimitSpinner) { + mLimitIsIterations = (position != 0); + if (mLimitIsIterations) { + mLimitLabel.setText("Iterations: "); + } else { + mLimitLabel.setText("Test time (ms): "); + } } } } @@ -234,7 +252,11 @@ public class FrameworkPerfActivity extends Activity return; } TestArgs args = new TestArgs(); - args.maxTime = mMaxRunTime; + if (mLimitIsIterations) { + args.maxOps = mMaxRunTime; + } else { + args.maxTime = mMaxRunTime; + } if (mFgTestIndex == 0 && mBgTestIndex == 0) { args.combOp = mCurOpIndex; } else if (mFgTestIndex != 0 && mBgTestIndex != 0) { @@ -376,6 +398,7 @@ public class FrameworkPerfActivity extends Activity mTestTime.setEnabled(false); mFgSpinner.setEnabled(false); mBgSpinner.setEnabled(false); + mLimitSpinner.setEnabled(false); updateWakeLock(); startService(new Intent(this, SchedulerService.class)); mCurOpIndex = 0; @@ -397,6 +420,7 @@ public class FrameworkPerfActivity extends Activity mTestTime.setEnabled(true); mFgSpinner.setEnabled(true); mBgSpinner.setEnabled(true); + mLimitSpinner.setEnabled(true); updateWakeLock(); stopService(new Intent(this, SchedulerService.class)); synchronized (mResults) { diff --git a/tests/FrameworkPerf/src/com/android/frameworkperf/TestArgs.java b/tests/FrameworkPerf/src/com/android/frameworkperf/TestArgs.java index f2f7c56..2fe38aa 100644 --- a/tests/FrameworkPerf/src/com/android/frameworkperf/TestArgs.java +++ b/tests/FrameworkPerf/src/com/android/frameworkperf/TestArgs.java @@ -21,6 +21,7 @@ import android.os.Parcelable; public class TestArgs implements Parcelable { long maxTime; + long maxOps = -1; int combOp = -1; int fgOp = -1; int bgOp = -1; @@ -30,6 +31,7 @@ public class TestArgs implements Parcelable { public TestArgs(Parcel source) { maxTime = source.readLong(); + maxOps = source.readLong(); combOp = source.readInt(); fgOp = source.readInt(); bgOp = source.readInt(); @@ -43,6 +45,7 @@ public class TestArgs implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeLong(maxTime); + dest.writeLong(maxOps); dest.writeInt(combOp); dest.writeInt(fgOp); dest.writeInt(bgOp); diff --git a/tests/FrameworkPerf/src/com/android/frameworkperf/TestService.java b/tests/FrameworkPerf/src/com/android/frameworkperf/TestService.java index 8cf1ac2..a8c43e9 100644 --- a/tests/FrameworkPerf/src/com/android/frameworkperf/TestService.java +++ b/tests/FrameworkPerf/src/com/android/frameworkperf/TestService.java @@ -224,6 +224,7 @@ public class TestService extends Service { public class TestRunner { Handler mHandler; long mMaxRunTime; + long mMaxOps; Op mForegroundOp; Op mBackgroundOp; Runnable mDoneCallback; @@ -277,6 +278,7 @@ public class TestService extends Service { public void run(Handler handler, TestArgs args, Runnable doneCallback) { mHandler = handler; mMaxRunTime = args.maxTime; + mMaxOps = args.maxOps; if (args.combOp >= 0) { mForegroundOp = mOpPairs[args.combOp]; mBackgroundOp = mOpPairs[args.combOp+1]; @@ -352,9 +354,18 @@ public class TestService extends Service { if (!mBackgroundRunning && !mForegroundRunning) { return false; } - long now = SystemClock.uptimeMillis(); - if (now > (mStartTime+mMaxRunTime)) { - return false; + if (mMaxOps > 0) { + // iteration-limited case + if (mForegroundOps >= mMaxOps) { + return false; + } + mForegroundOps++; + } else { + // time-limited case + long now = SystemClock.uptimeMillis(); + if (now > (mStartTime+mMaxRunTime)) { + return false; + } } return true; } -- cgit v1.1