From afb9b08dd8db25026f29b4882b885fea13979b70 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Wed, 13 Nov 2019 15:24:40 -0800 Subject: Refactor interactive microbenchmarks Replaces the SystemServer Benchmark activity with one that has several sets of benchmarks grouped into categories. This will make it easier to add more benchmarks that do not logically fit with the categories we already have. This does not remove any of the other benchmark activities, but in a follow up CL, we should remove those since they are covered by the Interactive Microbenchmarks activity. This also does not adjust the non-interactive mode, which should also happen in a followup. Change-Id: I1d079362df0d32642525ede5b41779d76a5735ec --- startop/apps/test/Android.bp | 4 +- startop/apps/test/AndroidManifest.xml | 8 +- .../test/src/CPUIntensiveBenchmarkActivity.java | 2 +- .../src/InitCheckOverheadBenchmarkActivity.java | 2 +- .../src/InteractiveMicrobenchmarkActivity.java | 90 ++++++++++++++++++++++ .../src/NonInteractiveMicrobenchmarkActivity.java | 71 +++++++++++++++++ ...onInteractiveSystemServerBenchmarkActivity.java | 71 ----------------- .../test/src/SystemServerBenchmarkActivity.java | 67 ---------------- startop/apps/test/src/SystemServerBenchmarks.java | 3 - 9 files changed, 169 insertions(+), 149 deletions(-) create mode 100644 startop/apps/test/src/InteractiveMicrobenchmarkActivity.java create mode 100644 startop/apps/test/src/NonInteractiveMicrobenchmarkActivity.java delete mode 100644 startop/apps/test/src/NonInteractiveSystemServerBenchmarkActivity.java delete mode 100644 startop/apps/test/src/SystemServerBenchmarkActivity.java (limited to 'startop/apps') diff --git a/startop/apps/test/Android.bp b/startop/apps/test/Android.bp index 3f20273a8d61..c7c70db60a72 100644 --- a/startop/apps/test/Android.bp +++ b/startop/apps/test/Android.bp @@ -25,8 +25,8 @@ android_app { "src/InitCheckOverheadBenchmarkActivity.java", "src/InitCheckOverheadBenchmarks.java", "src/LayoutInflationActivity.java", - "src/NonInteractiveSystemServerBenchmarkActivity.java", - "src/SystemServerBenchmarkActivity.java", + "src/NonInteractiveMicrobenchmarkActivity.java", + "src/InteractiveMicrobenchmarkActivity.java", "src/SystemServerBenchmarks.java", "src/TextViewInflationActivity.java", ], diff --git a/startop/apps/test/AndroidManifest.xml b/startop/apps/test/AndroidManifest.xml index 235aa0d25e86..adaab61778ed 100644 --- a/startop/apps/test/AndroidManifest.xml +++ b/startop/apps/test/AndroidManifest.xml @@ -97,8 +97,8 @@ @@ -109,8 +109,8 @@ diff --git a/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java b/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java index 2ec5308afe14..db3234a72129 100644 --- a/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java +++ b/startop/apps/test/src/CPUIntensiveBenchmarkActivity.java @@ -18,7 +18,7 @@ package com.android.startop.test; import android.os.Bundle; -public class CPUIntensiveBenchmarkActivity extends SystemServerBenchmarkActivity { +public class CPUIntensiveBenchmarkActivity extends InteractiveMicrobenchmarkActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.system_server_benchmark_page); diff --git a/startop/apps/test/src/InitCheckOverheadBenchmarkActivity.java b/startop/apps/test/src/InitCheckOverheadBenchmarkActivity.java index 3e0e3b113a29..92d8638092d3 100644 --- a/startop/apps/test/src/InitCheckOverheadBenchmarkActivity.java +++ b/startop/apps/test/src/InitCheckOverheadBenchmarkActivity.java @@ -18,7 +18,7 @@ package com.android.startop.test; import android.os.Bundle; -public class InitCheckOverheadBenchmarkActivity extends SystemServerBenchmarkActivity { +public class InitCheckOverheadBenchmarkActivity extends InteractiveMicrobenchmarkActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.system_server_benchmark_page); diff --git a/startop/apps/test/src/InteractiveMicrobenchmarkActivity.java b/startop/apps/test/src/InteractiveMicrobenchmarkActivity.java new file mode 100644 index 000000000000..8ed7f6ae2109 --- /dev/null +++ b/startop/apps/test/src/InteractiveMicrobenchmarkActivity.java @@ -0,0 +1,90 @@ +/* + * 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.app.Activity; +import android.content.Context; +import android.graphics.Typeface; +import android.os.Bundle; +import android.widget.Button; +import android.widget.GridLayout; +import android.widget.TextView; + +public class InteractiveMicrobenchmarkActivity extends Activity implements BenchmarkRunner { + protected GridLayout mBenchmarkList; + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.system_server_benchmark_page); + + mBenchmarkList = findViewById(R.id.benchmark_list); + + addBenchmark("Empty", () -> { + }); + addHeader("Application Benchmarks"); + CPUIntensiveBenchmarks.initializeBenchmarks(this, this); + addHeader("Init Check Overhead Benchmarks"); + InitCheckOverheadBenchmarks.initializeBenchmarks(this, this); + addHeader("System Server Benchmarks"); + SystemServerBenchmarks.initializeBenchmarks(this, this); + } + + /** + * Add a heading for a group of related benchmarks + * + * @param name The name of this group of benchmarks + */ + public void addHeader(CharSequence name) { + Context context = mBenchmarkList.getContext(); + TextView header = new TextView(context); + header.setText(name); + header.setTypeface(header.getTypeface(), Typeface.BOLD); + GridLayout.LayoutParams params = new GridLayout.LayoutParams(); + params.columnSpec = GridLayout.spec(0, 3); + mBenchmarkList.addView(header, params); + } + + /** + * Adds a benchmark to the set to run. + * + * @param name A short name that shows up in the UI or benchmark results + */ + public void addBenchmark(CharSequence name, Runnable thunk) { + Context context = mBenchmarkList.getContext(); + Button button = new Button(context); + TextView mean = new TextView(context); + TextView stdev = new TextView(context); + + button.setText(name); + mean.setText(""); + stdev.setText(""); + + button.setOnClickListener((_button) -> { + mean.setText("Running..."); + stdev.setText(""); + + SystemServerBenchmarks.runBenchmarkInBackground(thunk, (resultMean, resultStdev) -> { + mean.setText(String.format("%.3f", resultMean / 1e6)); + stdev.setText(String.format("%.3f", resultStdev / 1e6)); + }); + }); + + mBenchmarkList.addView(button); + mBenchmarkList.addView(mean); + mBenchmarkList.addView(stdev); + } +} diff --git a/startop/apps/test/src/NonInteractiveMicrobenchmarkActivity.java b/startop/apps/test/src/NonInteractiveMicrobenchmarkActivity.java new file mode 100644 index 000000000000..0162ac6c5d81 --- /dev/null +++ b/startop/apps/test/src/NonInteractiveMicrobenchmarkActivity.java @@ -0,0 +1,71 @@ +/* + * 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 java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.util.ArrayList; + +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 NonInteractiveMicrobenchmarkActivity extends Activity { + ArrayList benchmarkNames = new ArrayList(); + ArrayList benchmarkThunks = new ArrayList(); + + PrintStream out; + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + SystemServerBenchmarks.initializeBenchmarks(this, (name, thunk) -> { + benchmarkNames.add(name); + benchmarkThunks.add(thunk); + }); + + try { + out = new PrintStream(new File(getExternalFilesDir(null), "benchmark.csv")); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + out.println("Name,Mean,Stdev"); + runBenchmarks(0); + } + + void runBenchmarks(int i) { + if (i < benchmarkNames.size()) { + SystemServerBenchmarks.runBenchmarkInBackground(benchmarkThunks.get(i), + (mean, stdev) -> { + out.printf("%s,%.0f,%.0f\n", benchmarkNames.get(i), mean, stdev); + runBenchmarks(i + 1); + }); + } + } +} diff --git a/startop/apps/test/src/NonInteractiveSystemServerBenchmarkActivity.java b/startop/apps/test/src/NonInteractiveSystemServerBenchmarkActivity.java deleted file mode 100644 index a2dc2cf03d69..000000000000 --- a/startop/apps/test/src/NonInteractiveSystemServerBenchmarkActivity.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintStream; -import java.util.ArrayList; - -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 NonInteractiveSystemServerBenchmarkActivity extends Activity { - ArrayList benchmarkNames = new ArrayList(); - ArrayList benchmarkThunks = new ArrayList(); - - PrintStream out; - - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - SystemServerBenchmarks.initializeBenchmarks(this, (name, thunk) -> { - benchmarkNames.add(name); - benchmarkThunks.add(thunk); - }); - - try { - out = new PrintStream(new File(getExternalFilesDir(null), "benchmark.csv")); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - out.println("Name,Mean,Stdev"); - runBenchmarks(0); - } - - void runBenchmarks(int i) { - if (i < benchmarkNames.size()) { - SystemServerBenchmarks.runBenchmarkInBackground(benchmarkThunks.get(i), - (mean, stdev) -> { - out.printf("%s,%.0f,%.0f\n", benchmarkNames.get(i), mean, stdev); - runBenchmarks(i + 1); - }); - } - } -} diff --git a/startop/apps/test/src/SystemServerBenchmarkActivity.java b/startop/apps/test/src/SystemServerBenchmarkActivity.java deleted file mode 100644 index 6be8df3728af..000000000000 --- a/startop/apps/test/src/SystemServerBenchmarkActivity.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.widget.Button; -import android.widget.GridLayout; -import android.widget.TextView; - -public class SystemServerBenchmarkActivity extends Activity implements BenchmarkRunner { - protected GridLayout mBenchmarkList; - - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.system_server_benchmark_page); - - mBenchmarkList = findViewById(R.id.benchmark_list); - - SystemServerBenchmarks.initializeBenchmarks(this, this); - } - - /** - * Adds a benchmark to the set to run. - * - * @param name A short name that shows up in the UI or benchmark results - */ - public void addBenchmark(CharSequence name, Runnable thunk) { - Context context = mBenchmarkList.getContext(); - Button button = new Button(context); - TextView mean = new TextView(context); - TextView stdev = new TextView(context); - - button.setText(name); - mean.setText(""); - stdev.setText(""); - - button.setOnClickListener((_button) -> { - mean.setText("Running..."); - stdev.setText(""); - - SystemServerBenchmarks.runBenchmarkInBackground(thunk, (resultMean, resultStdev) -> { - mean.setText(String.format("%.3f", resultMean / 1e6)); - stdev.setText(String.format("%.3f", resultStdev / 1e6)); - }); - }); - - 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 25b43f4d53f6..8114bc225c23 100644 --- a/startop/apps/test/src/SystemServerBenchmarks.java +++ b/startop/apps/test/src/SystemServerBenchmarks.java @@ -57,9 +57,6 @@ class SystemServerBenchmarks { static void initializeBenchmarks(Activity parent, BenchmarkRunner benchmarks) { final String packageName = parent.getPackageName(); - benchmarks.addBenchmark("Empty", () -> { - }); - PackageManager pm = parent.getPackageManager(); benchmarks.addBenchmark("getInstalledApplications", () -> { pm.getInstalledApplications(PackageManager.MATCH_SYSTEM_ONLY); -- cgit v1.2.3-59-g8ed1b