blob: 0162ac6c5d81798b3b682adbfb5a65b863e7c5bc [file] [log] [blame]
Eric Holkc62b0832019-10-11 14:55:39 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.startop.test;
18
19import java.io.File;
20import java.io.FileNotFoundException;
21import java.io.PrintStream;
22import java.util.ArrayList;
23
24import android.app.Activity;
25import android.app.ActivityManager;
26import android.content.ComponentName;
27import android.content.Context;
28import android.content.Intent;
29import android.content.pm.ApplicationInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
32import android.os.AsyncTask;
33import android.os.Bundle;
34import android.view.ViewGroup;
35import android.widget.Button;
36import android.widget.GridLayout;
37import android.widget.TextView;
38
Eric Holkafb9b082019-11-13 15:24:40 -080039public class NonInteractiveMicrobenchmarkActivity extends Activity {
Eric Holkc62b0832019-10-11 14:55:39 -070040 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}