| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.startop.test; |
| 18 |
|
| 19 |
import android.app.Activity; |
| 20 |
import android.content.Context; |
| 21 |
import android.graphics.Typeface; |
| 22 |
import android.os.Bundle; |
| 23 |
import android.widget.Button; |
| 24 |
import android.widget.GridLayout; |
| 25 |
import android.widget.TextView; |
| 26 |
|
| 27 |
public class InteractiveMicrobenchmarkActivity extends Activity implements BenchmarkRunner { |
| 28 |
protected GridLayout mBenchmarkList; |
| 29 |
|
| 30 |
protected void onCreate(Bundle savedInstanceState) { |
| 31 |
super.onCreate(savedInstanceState); |
| 32 |
setContentView(R.layout.system_server_benchmark_page); |
| 33 |
|
| 34 |
mBenchmarkList = findViewById(R.id.benchmark_list); |
| 35 |
|
| 36 |
addBenchmark("Empty", () -> { |
| 37 |
}); |
| 38 |
addHeader("Application Benchmarks"); |
| 39 |
ApplicationBenchmarks.initializeBenchmarks(this, this); |
| 40 |
addHeader("CPU Intensive Benchmarks"); |
| 41 |
CPUIntensiveBenchmarks.initializeBenchmarks(this, this); |
| 42 |
addHeader("Init Check Overhead Benchmarks"); |
| 43 |
InitCheckOverheadBenchmarks.initializeBenchmarks(this, this); |
| 44 |
addHeader("System Server Benchmarks"); |
| 45 |
SystemServerBenchmarks.initializeBenchmarks(this, this); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public void addHeader(CharSequence name) { |
| 54 |
Context context = mBenchmarkList.getContext(); |
| 55 |
TextView header = new TextView(context); |
| 56 |
header.setText(name); |
| 57 |
header.setTypeface(header.getTypeface(), Typeface.BOLD); |
| 58 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(); |
| 59 |
params.columnSpec = GridLayout.spec(0, 3); |
| 60 |
mBenchmarkList.addView(header, params); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public void addBenchmark(CharSequence name, Runnable thunk) { |
| 69 |
Context context = mBenchmarkList.getContext(); |
| 70 |
Button button = new Button(context); |
| 71 |
TextView mean = new TextView(context); |
| 72 |
TextView stdev = new TextView(context); |
| 73 |
|
| 74 |
button.setText(name); |
| 75 |
mean.setText(""); |
| 76 |
stdev.setText(""); |
| 77 |
|
| 78 |
button.setOnClickListener((_button) -> { |
| 79 |
mean.setText("Running..."); |
| 80 |
stdev.setText(""); |
| 81 |
|
| 82 |
SystemServerBenchmarks.runBenchmarkInBackground(thunk, (resultMean, resultStdev) -> { |
| 83 |
mean.setText(String.format("%.3f", resultMean / 1e6)); |
| 84 |
stdev.setText(String.format("%.3f", resultStdev / 1e6)); |
| 85 |
}); |
| 86 |
}); |
| 87 |
|
| 88 |
mBenchmarkList.addView(button); |
| 89 |
mBenchmarkList.addView(mean); |
| 90 |
mBenchmarkList.addView(stdev); |
| 91 |
} |
| 92 |
} |