| 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 java.io.File; |
| 20 |
import java.io.FileNotFoundException; |
| 21 |
import java.io.PrintStream; |
| 22 |
import java.util.ArrayList; |
| 23 |
|
| 24 |
import android.app.Activity; |
| 25 |
import android.app.ActivityManager; |
| 26 |
import android.content.ComponentName; |
| 27 |
import android.content.Context; |
| 28 |
import android.content.Intent; |
| 29 |
import android.content.pm.ApplicationInfo; |
| 30 |
import android.content.pm.PackageManager; |
| 31 |
import android.content.pm.PackageManager.NameNotFoundException; |
| 32 |
import android.os.AsyncTask; |
| 33 |
import android.os.Bundle; |
| 34 |
import android.view.ViewGroup; |
| 35 |
import android.widget.Button; |
| 36 |
import android.widget.GridLayout; |
| 37 |
import android.widget.TextView; |
| 38 |
|
| 39 |
public class NonInteractiveMicrobenchmarkActivity extends Activity { |
| 40 |
ArrayList<CharSequence> benchmarkNames = new ArrayList(); |
| 41 |
ArrayList<Runnable> benchmarkThunks = new ArrayList(); |
| 42 |
|
| 43 |
PrintStream out; |
| 44 |
|
| 45 |
protected void onCreate(Bundle savedInstanceState) { |
| 46 |
super.onCreate(savedInstanceState); |
| 47 |
|
| 48 |
SystemServerBenchmarks.initializeBenchmarks(this, (name, thunk) -> { |
| 49 |
benchmarkNames.add(name); |
| 50 |
benchmarkThunks.add(thunk); |
| 51 |
}); |
| 52 |
|
| 53 |
try { |
| 54 |
out = new PrintStream(new File(getExternalFilesDir(null), "benchmark.csv")); |
| 55 |
} catch (FileNotFoundException e) { |
| 56 |
throw new RuntimeException(e); |
| 57 |
} |
| 58 |
out.println("Name,Mean,Stdev"); |
| 59 |
runBenchmarks(0); |
| 60 |
} |
| 61 |
|
| 62 |
void runBenchmarks(int i) { |
| 63 |
if (i < benchmarkNames.size()) { |
| 64 |
SystemServerBenchmarks.runBenchmarkInBackground(benchmarkThunks.get(i), |
| 65 |
(mean, stdev) -> { |
| 66 |
out.printf("%s,%.0f,%.0f\n", benchmarkNames.get(i), mean, stdev); |
| 67 |
runBenchmarks(i + 1); |
| 68 |
}); |
| 69 |
} |
| 70 |
} |
| 71 |
} |