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

Commit ac51da9c authored by David Sehr's avatar David Sehr
Browse files

Separate CPU intensive test from system server

Separate into two activities, as they are unrelated.

Bug: none
Test: run the applications
Change-Id: I390c1351d5e9c3ecdd0b863b7aceac03e735ff58
parent f5b33dff
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,7 +18,8 @@ android_app {
    name: "startop_test_app",
    srcs: [
        "src/ComplexLayoutInflationActivity.java",
        "src/CPUIntensive.java",
        "src/CPUIntensiveBenchmarkActivity.java",
        "src/CPUIntensiveBenchmarks.java",
        "src/EmptyActivity.java",
        "src/FrameLayoutInflationActivity.java",
        "src/LayoutInflationActivity.java",
+12 −0
Original line number Diff line number Diff line
@@ -36,6 +36,18 @@
            </intent-filter>
        </activity>

        <activity
            android:label="CPU Intensive Benchmark Test"
            android:name=".CPUIntensiveBenchmarkActivity"
            android:exported="true" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:label="Empty Activity Layout Test"
            android:name=".EmptyActivity"
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.startop.test;

import android.os.Bundle;

public class CPUIntensiveBenchmarkActivity extends SystemServerBenchmarkActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.system_server_benchmark_page);

        mBenchmarkList = findViewById(R.id.benchmark_list);

        CPUIntensiveBenchmarks.initializeBenchmarks(this, this);
    }
}
+32 −10
Original line number Diff line number Diff line
@@ -20,10 +20,11 @@

package com.android.startop.test;

final class CPUIntensive {
    public static final int THREAD_COUNT = 8;
import android.app.Activity;

public class CPUIntensiveBenchmarks {
    public static final int ARRAY_SIZE = 30000;
    public static int[][] array = new int[THREAD_COUNT][ARRAY_SIZE];
    public static int[][] mArray;

    static class WorkerThread extends Thread {
        int mThreadNumber;
@@ -31,21 +32,22 @@ final class CPUIntensive {
            mThreadNumber = number;
        }
        public void run() {
            final int arrayLength = array[mThreadNumber].length;
            final int arrayLength = mArray[mThreadNumber].length;
            for (int i = 0; i < arrayLength; ++i) {
                array[mThreadNumber][i] = i * i;
                mArray[mThreadNumber][i] = i * i;
            }
            for (int i = 0; i < arrayLength; ++i) {
                for (int j = 0; j < arrayLength; ++j) {
                    int swap = array[mThreadNumber][j];
                    array[mThreadNumber][j] = array[mThreadNumber][(j + i) % arrayLength];
                    array[mThreadNumber][(j + i) % arrayLength] = swap;
                    int swap = mArray[mThreadNumber][j];
                    mArray[mThreadNumber][j] = mArray[mThreadNumber][(j + i) % arrayLength];
                    mArray[mThreadNumber][(j + i) % arrayLength] = swap;
                }
            }
        }
    };

    public static void doSomeWork(int threadCount) {
    static void doSomeWork(int threadCount) {
        mArray = new int[threadCount][ARRAY_SIZE];
        WorkerThread[] threads = new WorkerThread[threadCount];
        // Create the threads.
        for (int i = 0; i < threadCount; ++i) {
@@ -63,5 +65,25 @@ final class CPUIntensive {
            }
        }
    }
}

    // Time limit to run benchmarks in seconds
    public static final int TIME_LIMIT = 5;

    static void initializeBenchmarks(Activity parent, BenchmarkRunner benchmarks) {
        benchmarks.addBenchmark("Use 1 thread", () -> {
            doSomeWork(1);
        });
        benchmarks.addBenchmark("Use 2 threads", () -> {
            doSomeWork(2);
        });
        benchmarks.addBenchmark("Use 4 threads", () -> {
            doSomeWork(4);
        });
        benchmarks.addBenchmark("Use 8 threads", () -> {
            doSomeWork(8);
        });
        benchmarks.addBenchmark("Use 16 threads", () -> {
            doSomeWork(16);
        });
    }
}
+6 −14
Original line number Diff line number Diff line
@@ -17,28 +17,20 @@
package com.android.startop.test;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.TextView;

public class SystemServerBenchmarkActivity extends Activity implements BenchmarkRunner {
    private GridLayout benchmarkList;
    protected GridLayout mBenchmarkList;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.system_server_benchmark_page);

        benchmarkList = findViewById(R.id.benchmark_list);
        mBenchmarkList = findViewById(R.id.benchmark_list);

        SystemServerBenchmarks.initializeBenchmarks(this, this);
    }
@@ -49,7 +41,7 @@ public class SystemServerBenchmarkActivity extends Activity implements Benchmark
     * @param name A short name that shows up in the UI or benchmark results
     */
    public void addBenchmark(CharSequence name, Runnable thunk) {
        Context context = benchmarkList.getContext();
        Context context = mBenchmarkList.getContext();
        Button button = new Button(context);
        TextView mean = new TextView(context);
        TextView stdev = new TextView(context);
@@ -68,8 +60,8 @@ public class SystemServerBenchmarkActivity extends Activity implements Benchmark
            });
        });

        benchmarkList.addView(button);
        benchmarkList.addView(mean);
        benchmarkList.addView(stdev);
        mBenchmarkList.addView(button);
        mBenchmarkList.addView(mean);
        mBenchmarkList.addView(stdev);
    }
}
Loading