Loading apct-tests/perftests/surfaceflinger/AndroidTest.xml +10 −2 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ <option name="hidden-api-checks" value="false"/> <!-- Listener related args for collecting the traces and waiting for the device to stabilize. --> <option name="device-listeners" value="android.device.collectors.PerfettoListener,android.device.collectors.SimpleperfListener" /> <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener,android.device.collectors.SimpleperfListener" /> <!-- Guarantee that user defined RunListeners will be running before any of the default listeners defined in this runner. --> <option name="instrumentation-arg" key="newRunListenerMode" value="true" /> Loading @@ -58,7 +58,15 @@ <option name="instrumentation-arg" key="arguments" value="""" /> <option name="instrumentation-arg" key="events_to_record" value="instructions,cpu-cycles,raw-l3d-cache-refill,sched:sched_waking" /> <option name="instrumentation-arg" key="processes_to_record" value="surfaceflinger" /> <option name="instrumentation-arg" key="symbols_to_report" value=""android::SurfaceFlinger::commit(long, long, long)"" /> <option name="instrumentation-arg" key="symbols_to_report" value=""android::SurfaceFlinger::commit(;android::SurfaceFlinger::composite("" /> <!-- ProcLoadListener related arguments --> <!-- Wait for device last minute threshold to reach 3 with 2 minute timeout before starting the test run --> <option name="instrumentation-arg" key="procload-collector:per_run" value="true" /> <option name="instrumentation-arg" key="proc-loadavg-threshold" value="3" /> <option name="instrumentation-arg" key="proc-loadavg-timeout" value="120000" /> <option name="instrumentation-arg" key="proc-loadavg-interval" value="10000" /> </test> <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> Loading apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerPerfTest.java +169 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.surfaceflinger; import android.graphics.Bitmap; import android.graphics.Color; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; Loading @@ -23,14 +24,19 @@ import android.view.SurfaceControl; import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.filters.LargeTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Random; @LargeTest @RunWith(AndroidJUnit4.class) public class SurfaceFlingerPerfTest { Loading @@ -48,19 +54,175 @@ public class SurfaceFlingerPerfTest { public void setup() { mActivityRule.getScenario().onActivity(activity -> mActivity = activity); } @After public void teardown() { mSurfaceControls.forEach(SurfaceControl::release); mByfferTrackers.forEach(BufferFlinger::freeBuffers); } private ArrayList<BufferFlinger> mByfferTrackers = new ArrayList<>(); private BufferFlinger createBufferTracker(int color) { BufferFlinger bufferTracker = new BufferFlinger(BUFFER_COUNT, color); mByfferTrackers.add(bufferTracker); return bufferTracker; } private ArrayList<SurfaceControl> mSurfaceControls = new ArrayList<>(); private SurfaceControl createSurfaceControl() throws InterruptedException { SurfaceControl sc = mActivity.createChildSurfaceControl(); mSurfaceControls.add(sc); return sc; } @Test public void singleBuffer() throws Exception { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); bufferTracker.addBuffer(t, sc); t.show(sc); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { bufferTracker.addBuffer(t, sc); t.apply(); } } static int getRandomColorComponent() { return new Random().nextInt(155) + 100; } @Test public void submitSingleBuffer() throws Exception { SurfaceControl sc = mActivity.getChildSurfaceControl(); public void multipleBuffers() throws Exception { final int MAX_BUFFERS = 10; SurfaceControl.Transaction t = new SurfaceControl.Transaction(); BufferFlinger bufferflinger = new BufferFlinger(BUFFER_COUNT, Color.GREEN); for (int i = 0; i < MAX_BUFFERS; i++) { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.argb(getRandomColorComponent(), getRandomColorComponent(), getRandomColorComponent(), getRandomColorComponent())); bufferTracker.addBuffer(t, sc); t.setPosition(sc, i * 10, i * 10); t.show(sc); } t.apply(true); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { for (int i = 0; i < MAX_BUFFERS; i++) { mByfferTrackers.get(i).addBuffer(t, mSurfaceControls.get(i)); } t.apply(); } } @Test public void multipleOpaqueBuffers() throws Exception { final int MAX_BUFFERS = 10; SurfaceControl.Transaction t = new SurfaceControl.Transaction(); for (int i = 0; i < MAX_BUFFERS; i++) { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.rgb(getRandomColorComponent(), getRandomColorComponent(), getRandomColorComponent())); bufferTracker.addBuffer(t, sc); t.setOpaque(sc, true); t.setPosition(sc, i * 10, i * 10); t.show(sc); } t.apply(true); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { for (int i = 0; i < MAX_BUFFERS; i++) { mByfferTrackers.get(i).addBuffer(t, mSurfaceControls.get(i)); } t.apply(); } } @Test public void geometryChanges() throws Exception { final int MAX_POSITION = 10; final float MAX_SCALE = 2.0f; SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); bufferTracker.addBuffer(t, sc); t.show(sc).apply(true); int step = 0; BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { step = ++step % MAX_POSITION; t.setPosition(sc, step, step); float scale = ((step * MAX_SCALE) / MAX_POSITION) + 0.5f; t.setScale(sc, scale, scale); t.apply(); } } @Test public void geometryWithBufferChanges() throws Exception { final int MAX_POSITION = 10; SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); bufferTracker.addBuffer(t, sc); t.show(sc).apply(true); int step = 0; BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { step = ++step % MAX_POSITION; t.setPosition(sc, step, step); float scale = ((step * 2.0f) / MAX_POSITION) + 0.5f; t.setScale(sc, scale, scale); bufferTracker.addBuffer(t, sc); t.apply(); } } @Test public void addRemoveLayers() throws Exception { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { bufferflinger.addBuffer(t, sc); SurfaceControl childSurfaceControl = new SurfaceControl.Builder() .setName("childLayer").setBLASTLayer().build(); bufferTracker.addBuffer(t, childSurfaceControl); t.reparent(childSurfaceControl, sc); t.apply(); t.remove(childSurfaceControl).apply(); } bufferflinger.freeBuffers(); } @Test public void displayScreenshot() throws Exception { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { Bitmap screenshot = InstrumentationRegistry.getInstrumentation().getUiAutomation().takeScreenshot(); screenshot.recycle(); } } @Test public void layerScreenshot() throws Exception { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { Bitmap screenshot = InstrumentationRegistry.getInstrumentation().getUiAutomation().takeScreenshot( mActivity.getWindow()); screenshot.recycle(); } } } apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerTestActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ public class SurfaceFlingerTestActivity extends Activity { setContentView(mTestSurfaceView); } public SurfaceControl getChildSurfaceControl() throws InterruptedException { public SurfaceControl createChildSurfaceControl() throws InterruptedException { return mTestSurfaceView.getChildSurfaceControlHelper(); } Loading Loading
apct-tests/perftests/surfaceflinger/AndroidTest.xml +10 −2 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ <option name="hidden-api-checks" value="false"/> <!-- Listener related args for collecting the traces and waiting for the device to stabilize. --> <option name="device-listeners" value="android.device.collectors.PerfettoListener,android.device.collectors.SimpleperfListener" /> <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener,android.device.collectors.SimpleperfListener" /> <!-- Guarantee that user defined RunListeners will be running before any of the default listeners defined in this runner. --> <option name="instrumentation-arg" key="newRunListenerMode" value="true" /> Loading @@ -58,7 +58,15 @@ <option name="instrumentation-arg" key="arguments" value="""" /> <option name="instrumentation-arg" key="events_to_record" value="instructions,cpu-cycles,raw-l3d-cache-refill,sched:sched_waking" /> <option name="instrumentation-arg" key="processes_to_record" value="surfaceflinger" /> <option name="instrumentation-arg" key="symbols_to_report" value=""android::SurfaceFlinger::commit(long, long, long)"" /> <option name="instrumentation-arg" key="symbols_to_report" value=""android::SurfaceFlinger::commit(;android::SurfaceFlinger::composite("" /> <!-- ProcLoadListener related arguments --> <!-- Wait for device last minute threshold to reach 3 with 2 minute timeout before starting the test run --> <option name="instrumentation-arg" key="procload-collector:per_run" value="true" /> <option name="instrumentation-arg" key="proc-loadavg-threshold" value="3" /> <option name="instrumentation-arg" key="proc-loadavg-timeout" value="120000" /> <option name="instrumentation-arg" key="proc-loadavg-interval" value="10000" /> </test> <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> Loading
apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerPerfTest.java +169 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.surfaceflinger; import android.graphics.Bitmap; import android.graphics.Color; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; Loading @@ -23,14 +24,19 @@ import android.view.SurfaceControl; import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.filters.LargeTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Random; @LargeTest @RunWith(AndroidJUnit4.class) public class SurfaceFlingerPerfTest { Loading @@ -48,19 +54,175 @@ public class SurfaceFlingerPerfTest { public void setup() { mActivityRule.getScenario().onActivity(activity -> mActivity = activity); } @After public void teardown() { mSurfaceControls.forEach(SurfaceControl::release); mByfferTrackers.forEach(BufferFlinger::freeBuffers); } private ArrayList<BufferFlinger> mByfferTrackers = new ArrayList<>(); private BufferFlinger createBufferTracker(int color) { BufferFlinger bufferTracker = new BufferFlinger(BUFFER_COUNT, color); mByfferTrackers.add(bufferTracker); return bufferTracker; } private ArrayList<SurfaceControl> mSurfaceControls = new ArrayList<>(); private SurfaceControl createSurfaceControl() throws InterruptedException { SurfaceControl sc = mActivity.createChildSurfaceControl(); mSurfaceControls.add(sc); return sc; } @Test public void singleBuffer() throws Exception { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); bufferTracker.addBuffer(t, sc); t.show(sc); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { bufferTracker.addBuffer(t, sc); t.apply(); } } static int getRandomColorComponent() { return new Random().nextInt(155) + 100; } @Test public void submitSingleBuffer() throws Exception { SurfaceControl sc = mActivity.getChildSurfaceControl(); public void multipleBuffers() throws Exception { final int MAX_BUFFERS = 10; SurfaceControl.Transaction t = new SurfaceControl.Transaction(); BufferFlinger bufferflinger = new BufferFlinger(BUFFER_COUNT, Color.GREEN); for (int i = 0; i < MAX_BUFFERS; i++) { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.argb(getRandomColorComponent(), getRandomColorComponent(), getRandomColorComponent(), getRandomColorComponent())); bufferTracker.addBuffer(t, sc); t.setPosition(sc, i * 10, i * 10); t.show(sc); } t.apply(true); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { for (int i = 0; i < MAX_BUFFERS; i++) { mByfferTrackers.get(i).addBuffer(t, mSurfaceControls.get(i)); } t.apply(); } } @Test public void multipleOpaqueBuffers() throws Exception { final int MAX_BUFFERS = 10; SurfaceControl.Transaction t = new SurfaceControl.Transaction(); for (int i = 0; i < MAX_BUFFERS; i++) { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.rgb(getRandomColorComponent(), getRandomColorComponent(), getRandomColorComponent())); bufferTracker.addBuffer(t, sc); t.setOpaque(sc, true); t.setPosition(sc, i * 10, i * 10); t.show(sc); } t.apply(true); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { for (int i = 0; i < MAX_BUFFERS; i++) { mByfferTrackers.get(i).addBuffer(t, mSurfaceControls.get(i)); } t.apply(); } } @Test public void geometryChanges() throws Exception { final int MAX_POSITION = 10; final float MAX_SCALE = 2.0f; SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); bufferTracker.addBuffer(t, sc); t.show(sc).apply(true); int step = 0; BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { step = ++step % MAX_POSITION; t.setPosition(sc, step, step); float scale = ((step * MAX_SCALE) / MAX_POSITION) + 0.5f; t.setScale(sc, scale, scale); t.apply(); } } @Test public void geometryWithBufferChanges() throws Exception { final int MAX_POSITION = 10; SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); bufferTracker.addBuffer(t, sc); t.show(sc).apply(true); int step = 0; BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { step = ++step % MAX_POSITION; t.setPosition(sc, step, step); float scale = ((step * 2.0f) / MAX_POSITION) + 0.5f; t.setScale(sc, scale, scale); bufferTracker.addBuffer(t, sc); t.apply(); } } @Test public void addRemoveLayers() throws Exception { SurfaceControl sc = createSurfaceControl(); BufferFlinger bufferTracker = createBufferTracker(Color.GREEN); SurfaceControl.Transaction t = new SurfaceControl.Transaction(); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { bufferflinger.addBuffer(t, sc); SurfaceControl childSurfaceControl = new SurfaceControl.Builder() .setName("childLayer").setBLASTLayer().build(); bufferTracker.addBuffer(t, childSurfaceControl); t.reparent(childSurfaceControl, sc); t.apply(); t.remove(childSurfaceControl).apply(); } bufferflinger.freeBuffers(); } @Test public void displayScreenshot() throws Exception { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { Bitmap screenshot = InstrumentationRegistry.getInstrumentation().getUiAutomation().takeScreenshot(); screenshot.recycle(); } } @Test public void layerScreenshot() throws Exception { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { Bitmap screenshot = InstrumentationRegistry.getInstrumentation().getUiAutomation().takeScreenshot( mActivity.getWindow()); screenshot.recycle(); } } }
apct-tests/perftests/surfaceflinger/src/android/surfaceflinger/SurfaceFlingerTestActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ public class SurfaceFlingerTestActivity extends Activity { setContentView(mTestSurfaceView); } public SurfaceControl getChildSurfaceControl() throws InterruptedException { public SurfaceControl createChildSurfaceControl() throws InterruptedException { return mTestSurfaceView.getChildSurfaceControlHelper(); } Loading