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

Commit 61cd26fb authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Updated SimpleperfHelper API usage in SurfaceFlingerPerfTest and...

Merge "Updated SimpleperfHelper API usage in SurfaceFlingerPerfTest and MessageQueuePerfTest" into main
parents ab969bb7 c0cf960d
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@

    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
        <option name="pull-pattern-keys" value="perfetto_file_path" />
        <option name="pull-pattern-keys" value="simpleperf_profiling_file_path"/>
        <option name="pull-pattern-keys" value="simpleperf_report_file_path"/>
        <option name="collect-on-run-ended-only" value="false"/>
    </metrics_collector>

    <!-- Needed for storing the perfetto files in external storage-->
@@ -54,7 +57,7 @@
        <option name="package" value="com.android.perftests.core" />
        <option name="hidden-api-checks" value="false"/>

        <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener" />
        <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener,android.device.collectors.SimpleperfListener" />
        <!-- 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" />
@@ -69,15 +72,11 @@
        <option name="instrumentation-arg" key="newRunListenerMode" value="true" />

        <!-- Listener related args for collecting the traces and waiting for the device to stabilize. -->
        <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.SimpleperfListener" />

        <option name="instrumentation-arg" key="profiling-iterations" value="525" />
        <option name="instrumentation-arg" key="profiling-iterations" value="1" />

        <!-- SimpleperfListener related arguments -->
        <option name="instrumentation-arg" key="record" value="false"/>
        <option name="instrumentation-arg" key="report" value="true" />
        <option name="instrumentation-arg" key="arguments" value="-g" />
        <option name="instrumentation-arg" key="events_to_record" value="cpu-cycles" />
        <option name="instrumentation-arg" key="processes_to_record" value="com.android.perftests.core" />
        <option name="instrumentation-arg" key="simpleperf-collector:events_to_record" value="cpu-cycles" />
        <option name="instrumentation-arg" key="simpleperf-collector:processes_to_record" value="com.android.perftests.core" />
    </test>
</configuration>
+0 −41
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.helpers.SimpleperfHelper;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -41,9 +39,6 @@ import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
@@ -58,53 +53,17 @@ public class MessageQueuePerfTest {
    private static final int TOTAL_MESSAGE_COUNT = PER_THREAD_MESSAGE_COUNT * THREAD_COUNT;
    private static final int DEFAULT_MESSAGE_WHAT = 2;

    private SimpleperfHelper mSimpleperfHelper = new SimpleperfHelper();
    private boolean mEnableSimpleperf = true;

    @Rule public TestName mTestName = new TestName();

    /** Start simpleperf sampling. */
    public void startSimpleperf(String subcommand, String arguments) {
        if (!mSimpleperfHelper.startCollecting(subcommand, arguments)) {
            Log.e(TAG, "Simpleperf did not start successfully.");
        }
    }

    /** Stop simpleperf sampling and dump the collected file into the given path. */
    private void stopSimpleperf(Path path) {
        if (!mSimpleperfHelper.stopCollecting(path.toString())) {
            Log.e(TAG, "Failed to collect the simpleperf output.");
        }
    }

    @Before
    public void setUp() {
        mHandlerThread = new HandlerThread("MessageQueuePerfTest");
        mHandlerThread.start();

        Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
        if (arguments != null && arguments.getString("no-simpleperf") != null) {
            mEnableSimpleperf = false;
        }

        if (mEnableSimpleperf) {
            String args =
                    "-o /data/local/tmp/perf.data -g -e cpu-cycles -p "
                            + mSimpleperfHelper.getPID("com.android.perftests.core");
            startSimpleperf("record", args);
        }
    }

    @After
    public void tearDown() {
        mHandlerThread.quitSafely();

        if (mEnableSimpleperf) {
            final File outputDir = InstrumentationRegistry.getContext().getExternalFilesDir(null);
            final Path outputPath =
                    new File(outputDir, mTestName.getMethodName() + ".perf.data").toPath();
            stopSimpleperf(outputPath);
        }
    }

    static class EnqueueThread extends Thread {
+6 −6
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import org.junit.runner.RunWith;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@LargeTest
@@ -79,7 +80,10 @@ public class SurfaceFlingerPerfTest {
    private static String sImmersiveModeConfirmationValue;
    /** Start simpleperf sampling. */
    public void startSimpleperf(String subcommand, String arguments) {
        if (!mSimpleperfHelper.startCollecting(subcommand, arguments)) {
        List<String> commandArgsList = new ArrayList<>();
        commandArgsList.add(subcommand);
        commandArgsList.add(arguments);
        if (!mSimpleperfHelper.startCollecting(commandArgsList)) {
            Log.e(TAG, "Simpleperf did not start successfully.");
        }
    }
@@ -166,11 +170,7 @@ public class SurfaceFlingerPerfTest {

    @After
    public void teardown() {
        try {
            mSimpleperfHelper.stopSimpleperf();
        } catch (IOException e) {
            Log.e(TAG, "Failed to stop simpleperf", e);
        }
        mSimpleperfHelper.stopCollecting("/sdcard/test_results/perf.data");
        mSurfaceControls.forEach(SurfaceControl::release);
        mBufferTrackers.forEach(BufferFlinger::freeBuffers);
    }