diff options
author | David Sehr <sehr@google.com> | 2019-09-18 17:52:12 -0700 |
---|---|---|
committer | David Sehr <sehr@google.com> | 2019-09-20 15:32:50 +0000 |
commit | decc2b716d043259453d352a3122663ec18079d8 (patch) | |
tree | b875d5a7dd9050b4ccbb6a4ab984b6ae0968ef3c /startop | |
parent | 4c4650cb1bf0bfbef562ba75f052f3dbd7761fc0 (diff) |
Add a threaded CPU-intensive benchmark to test
In order to understand how simpleperf reports percentages from a whole
system, craft a benchmark set that runs a CPU-intensive thread a number
of times.
Bug: none
Test: run the app
Change-Id: I7c8748f9b5da89be20775a5af60b223d4673023b
Diffstat (limited to 'startop')
-rw-r--r-- | startop/apps/test/Android.bp | 1 | ||||
-rw-r--r-- | startop/apps/test/src/CPUIntensive.java | 67 | ||||
-rw-r--r-- | startop/apps/test/src/SystemServerBenchmarkActivity.java | 20 |
3 files changed, 84 insertions, 4 deletions
diff --git a/startop/apps/test/Android.bp b/startop/apps/test/Android.bp index db1d305070d9..a8063209b56f 100644 --- a/startop/apps/test/Android.bp +++ b/startop/apps/test/Android.bp @@ -17,6 +17,7 @@ android_app { name: "startop_test_app", srcs: [ + "src/CPUIntensive.java", "src/EmptyActivity.java", "src/LayoutInflationActivity.java", "src/ComplexLayoutInflationActivity.java", diff --git a/startop/apps/test/src/CPUIntensive.java b/startop/apps/test/src/CPUIntensive.java new file mode 100644 index 000000000000..a411e8ce8ce0 --- /dev/null +++ b/startop/apps/test/src/CPUIntensive.java @@ -0,0 +1,67 @@ +/* + * 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. + */ + +/** + * A threaded CPU intensive class for use in benchmarks. + */ + +package com.android.startop.test; + +final class CPUIntensive { + public static final int THREAD_COUNT = 8; + public static final int ARRAY_SIZE = 30000; + public static int[][] array = new int[THREAD_COUNT][ARRAY_SIZE]; + + static class WorkerThread extends Thread { + int mThreadNumber; + WorkerThread(int number) { + mThreadNumber = number; + } + public void run() { + final int arrayLength = array[mThreadNumber].length; + for (int i = 0; i < arrayLength; ++i) { + array[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; + } + } + } + }; + + public static void doSomeWork(int threadCount) { + WorkerThread[] threads = new WorkerThread[threadCount]; + // Create the threads. + for (int i = 0; i < threadCount; ++i) { + threads[i] = new WorkerThread(i); + } + // Start the threads. + for (int i = 0; i < threadCount; ++i) { + threads[i].start(); + } + // Join the threads. + for (int i = 0; i < threadCount; ++i) { + try { + threads[i].join(); + } catch (Exception ex) { + } + } + } +} + diff --git a/startop/apps/test/src/SystemServerBenchmarkActivity.java b/startop/apps/test/src/SystemServerBenchmarkActivity.java index ed3cbe9e3e30..c8d9fde0bdaf 100644 --- a/startop/apps/test/src/SystemServerBenchmarkActivity.java +++ b/startop/apps/test/src/SystemServerBenchmarkActivity.java @@ -26,15 +26,11 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.AsyncTask; import android.os.Bundle; -import android.os.Trace; -import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.GridLayout; import android.widget.TextView; -import java.util.Arrays; class Benchmark { // Time limit to run benchmarks in seconds @@ -107,6 +103,22 @@ public class SystemServerBenchmarkActivity extends Activity { new Benchmark(benchmarkList, "Empty", () -> { }); + new Benchmark(benchmarkList, "CPU Intensive (1 thread)", () -> { + CPUIntensive.doSomeWork(1); + }); + + new Benchmark(benchmarkList, "CPU Intensive (2 thread)", () -> { + CPUIntensive.doSomeWork(2); + }); + + new Benchmark(benchmarkList, "CPU Intensive (4 thread)", () -> { + CPUIntensive.doSomeWork(4); + }); + + new Benchmark(benchmarkList, "CPU Intensive (8 thread)", () -> { + CPUIntensive.doSomeWork(8); + }); + PackageManager pm = getPackageManager(); new Benchmark(benchmarkList, "getInstalledApplications", () -> { pm.getInstalledApplications(PackageManager.MATCH_SYSTEM_ONLY); |