summaryrefslogtreecommitdiff
path: root/startop/apps
diff options
context:
space:
mode:
authorDavid Sehr <sehr@google.com>2019-10-22 15:04:08 -0700
committerDavid Sehr <sehr@google.com>2019-10-23 10:08:25 -0700
commitac51da9c4eea381c947af4ed60648d886069484d (patch)
treeae5771b0b78cad17d4abdeeec7c94baa24491ca1 /startop/apps
parentf5b33dff5ea86d6b62b5a2bbbbda5d9d04c66477 (diff)
Separate CPU intensive test from system server
Separate into two activities, as they are unrelated. Bug: none Test: run the applications Change-Id: I390c1351d5e9c3ecdd0b863b7aceac03e735ff58
Diffstat (limited to 'startop/apps')
-rw-r--r--startop/apps/test/Android.bp3
-rw-r--r--startop/apps/test/AndroidManifest.xml12
-rw-r--r--startop/apps/test/src/CPUIntensiveBenchmarkActivity.java30
-rw-r--r--startop/apps/test/src/CPUIntensiveBenchmarks.java (renamed from startop/apps/test/src/CPUIntensive.java)42
-rw-r--r--startop/apps/test/src/SystemServerBenchmarkActivity.java20
-rw-r--r--startop/apps/test/src/SystemServerBenchmarks.java16
6 files changed, 82 insertions, 41 deletions
diff --git a/startop/apps/test/Android.bp b/startop/apps/test/Android.bp
index 2ff26b8a5cde..5de7fd2fb0a0 100644
--- a/startop/apps/test/Android.bp
+++ b/startop/apps/test/Android.bp
@@ -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",
diff --git a/startop/apps/test/AndroidManifest.xml b/startop/apps/test/AndroidManifest.xml
index ebe2584c2d32..b08072e00584 100644
--- a/startop/apps/test/AndroidManifest.xml
+++ b/startop/apps/test/AndroidManifest.xml
@@ -37,6 +37,18 @@
</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"
android:exported="true" >
diff --git a/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java b/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java
new file mode 100644
index 000000000000..2ec5308afe14
--- /dev/null
+++ b/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java
@@ -0,0 +1,30 @@
+/*
+ * 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);
+ }
+}
diff --git a/startop/apps/test/src/CPUIntensive.java b/startop/apps/test/src/CPUIntensiveBenchmarks.java
index a411e8ce8ce0..19d0b6372c1b 100644
--- a/startop/apps/test/src/CPUIntensive.java
+++ b/startop/apps/test/src/CPUIntensiveBenchmarks.java
@@ -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);
+ });
+ }
+}
diff --git a/startop/apps/test/src/SystemServerBenchmarkActivity.java b/startop/apps/test/src/SystemServerBenchmarkActivity.java
index 75ea69b81e02..6be8df3728af 100644
--- a/startop/apps/test/src/SystemServerBenchmarkActivity.java
+++ b/startop/apps/test/src/SystemServerBenchmarkActivity.java
@@ -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);
}
}
diff --git a/startop/apps/test/src/SystemServerBenchmarks.java b/startop/apps/test/src/SystemServerBenchmarks.java
index 5918503c87ea..25b43f4d53f6 100644
--- a/startop/apps/test/src/SystemServerBenchmarks.java
+++ b/startop/apps/test/src/SystemServerBenchmarks.java
@@ -60,22 +60,6 @@ class SystemServerBenchmarks {
benchmarks.addBenchmark("Empty", () -> {
});
- benchmarks.addBenchmark("CPU Intensive (1 thread)", () -> {
- CPUIntensive.doSomeWork(1);
- });
-
- benchmarks.addBenchmark("CPU Intensive (2 thread)", () -> {
- CPUIntensive.doSomeWork(2);
- });
-
- benchmarks.addBenchmark("CPU Intensive (4 thread)", () -> {
- CPUIntensive.doSomeWork(4);
- });
-
- benchmarks.addBenchmark("CPU Intensive (8 thread)", () -> {
- CPUIntensive.doSomeWork(8);
- });
-
PackageManager pm = parent.getPackageManager();
benchmarks.addBenchmark("getInstalledApplications", () -> {
pm.getInstalledApplications(PackageManager.MATCH_SYSTEM_ONLY);