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
This commit is contained in:
David Sehr
2019-09-18 17:52:12 -07:00
parent 4c4650cb1b
commit decc2b716d
3 changed files with 84 additions and 4 deletions

View File

@@ -17,6 +17,7 @@
android_app {
name: "startop_test_app",
srcs: [
"src/CPUIntensive.java",
"src/EmptyActivity.java",
"src/LayoutInflationActivity.java",
"src/ComplexLayoutInflationActivity.java",

View File

@@ -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) {
}
}
}
}

View File

@@ -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);