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

Commit 80a682bc authored by Christopher Tate's avatar Christopher Tate
Browse files

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
parent 500afb87
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -59,6 +59,22 @@
        android:textAppearance="?android:attr/textAppearanceSmall"
        />

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp"
        >
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Limit by: "
            />
        <Spinner android:id="@+id/limitspinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true"
        />
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
@@ -67,6 +83,7 @@
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Test time (ms): "
            android:id="@+id/limitlabel"
            />
        <EditText android:id="@+id/testtime"
            android:layout_width="match_parent"
+27 −3
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ public class FrameworkPerfActivity extends Activity

    Spinner mFgSpinner;
    Spinner mBgSpinner;
    Spinner mLimitSpinner;
    TextView mLimitLabel;
    TextView mTestTime;
    Button mStartButton;
    Button mStopButton;
@@ -58,10 +60,12 @@ public class FrameworkPerfActivity extends Activity
    PowerManager.WakeLock mPartialWakeLock;

    long mMaxRunTime = 5000;
    boolean mLimitIsIterations;
    boolean mStarted;

    final String[] mAvailOpLabels;
    final String[] mAvailOpDescriptions;
    final String[] mLimitLabels = { "Time", "Iterations" };

    int mFgTestIndex = -1;
    int mBgTestIndex = -1;
@@ -169,8 +173,15 @@ public class FrameworkPerfActivity extends Activity
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mBgSpinner.setAdapter(adapter);
        mBgSpinner.setOnItemSelectedListener(this);
        mLimitSpinner = (Spinner) findViewById(R.id.limitspinner);
        adapter = new ArrayAdapter<String>(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();
        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) {
+3 −0
Original line number Diff line number Diff line
@@ -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);
+14 −3
Original line number Diff line number Diff line
@@ -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,10 +354,19 @@ public class TestService extends Service {
                if (!mBackgroundRunning && !mForegroundRunning) {
                    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;
            }
        }