├── .github └── workflows │ └── android.yml ├── .gitignore ├── LICENSE ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── android │ │ └── benchmark │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── android │ │ │ └── benchmark │ │ │ ├── api │ │ │ ├── JankBenchAPI.java │ │ │ └── JankBenchService.java │ │ │ ├── app │ │ │ ├── BenchmarkDashboardFragment.java │ │ │ ├── BenchmarkListAdapter.java │ │ │ ├── HomeActivity.java │ │ │ ├── PerfTimeline.java │ │ │ ├── RunLocalBenchmarksActivity.java │ │ │ └── UiResultsFragment.java │ │ │ ├── config │ │ │ └── Constants.java │ │ │ ├── models │ │ │ ├── Entry.java │ │ │ └── Result.java │ │ │ ├── registry │ │ │ ├── BenchmarkCategory.java │ │ │ ├── BenchmarkGroup.java │ │ │ └── BenchmarkRegistry.java │ │ │ ├── results │ │ │ ├── GlobalResultsStore.java │ │ │ └── UiBenchmarkResult.java │ │ │ ├── synthetic │ │ │ ├── MemoryActivity.java │ │ │ └── TestInterface.java │ │ │ ├── ui │ │ │ ├── BitmapUploadActivity.java │ │ │ ├── EditTextInputActivity.java │ │ │ ├── FullScreenOverdrawActivity.java │ │ │ ├── ImageListViewScrollActivity.java │ │ │ ├── ListActivityBase.java │ │ │ ├── ListViewScrollActivity.java │ │ │ ├── ShadowGridActivity.java │ │ │ ├── TextScrollActivity.java │ │ │ ├── Utils.java │ │ │ └── automation │ │ │ │ ├── Automator.java │ │ │ │ ├── CollectorThread.java │ │ │ │ ├── FrameTimingStats.java │ │ │ │ └── Interaction.java │ │ │ └── utils │ │ │ └── CatFile.java │ ├── jni │ │ ├── Android.bp.converted │ │ ├── Application.mk │ │ ├── Bench.cpp │ │ ├── Bench.h │ │ ├── WorkerPool.cpp │ │ ├── WorkerPool.h │ │ └── test.cpp │ └── res │ │ ├── drawable │ │ ├── ic_play.png │ │ ├── img1.jpg │ │ ├── img2.jpg │ │ ├── img3.jpg │ │ └── img4.jpg │ │ ├── layout │ │ ├── activity_bitmap_upload.xml │ │ ├── activity_home.xml │ │ ├── activity_list_fragment.xml │ │ ├── activity_memory.xml │ │ ├── activity_running_list.xml │ │ ├── benchmark_list_group_row.xml │ │ ├── benchmark_list_item.xml │ │ ├── card_row.xml │ │ ├── content_main.xml │ │ ├── fragment_dashboard.xml │ │ ├── fragment_ui_results_detail.xml │ │ ├── image_scroll_list_item.xml │ │ ├── results_list_item.xml │ │ └── running_benchmark_list_item.xml │ │ ├── menu │ │ ├── menu_main.xml │ │ └── menu_memory.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ ├── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── benchmark.xml │ └── test │ └── java │ └── com │ └── android │ └── benchmark │ ├── ExampleUnitTest.java │ └── api │ └── JankBenchServiceTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── scripts ├── adbutil.py ├── collect.py ├── devices.py ├── external │ ├── __init__.py │ └── statistics.py ├── itr_collect.py └── runall.py └── settings.gradle /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: set up JDK 1.8 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 1.8 16 | - name: Assemble with Gradle 17 | run: ./gradlew assemble 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | /app/release 16 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | defaultConfig { 7 | applicationId "com.android.benchmark" 8 | minSdkVersion 24 9 | targetSdkVersion 29 10 | versionCode 6 11 | versionName "2.2" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | compileOptions { 21 | sourceCompatibility JavaVersion.VERSION_1_8 22 | targetCompatibility JavaVersion.VERSION_1_8 23 | } 24 | } 25 | 26 | repositories { 27 | maven { url 'https://jitpack.io' } 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(dir: 'libs', include: ['*.jar']) 32 | implementation 'androidx.appcompat:appcompat:1.1.0' 33 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 34 | implementation 'com.google.android.material:material:1.0.0' 35 | testImplementation 'junit:junit:4.12' 36 | 37 | implementation 'androidx.cardview:cardview:1.0.0' 38 | implementation 'androidx.recyclerview:recyclerview:1.0.0' 39 | implementation 'androidx.leanback:leanback:1.0.0' 40 | implementation 'org.apache.commons:commons-math3:3.6' 41 | implementation 'com.squareup.retrofit2:retrofit:2.1.0' 42 | implementation 'com.squareup.retrofit2:converter-gson:2.1.0' 43 | 44 | def libsuVersion = '2.5.1' 45 | implementation "com.github.topjohnwu.libsu:core:${libsuVersion}" 46 | implementation "com.github.topjohnwu.libsu:io:${libsuVersion}" 47 | implementation "com.github.topjohnwu.libsu:busybox:${libsuVersion}" 48 | } 49 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/android/benchmark/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | /* 18 | * Copyright (C) 2015 The Android Open Source Project 19 | * 20 | * Licensed under the Apache License, Version 2.0 (the "License"); 21 | * you may not use this file except in compliance with the License. 22 | * You may obtain a copy of the License at 23 | * 24 | * http://www.apache.org/licenses/LICENSE-2.0 25 | * Unless required by applicable law or agreed to in writing, software 26 | * distributed under the License is distributed on an "AS IS" BASIS, 27 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 | * See the License for the specific language governing permissions and limitations under the 29 | * License. 30 | * 31 | */ 32 | 33 | package com.android.benchmark; 34 | 35 | import android.app.Application; 36 | import android.test.ApplicationTestCase; 37 | 38 | /** 39 | * Testing Fundamentals 40 | */ 41 | public class ApplicationTest extends ApplicationTestCase { 42 | public ApplicationTest() { 43 | super(Application.class); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | 47 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/api/JankBenchAPI.java: -------------------------------------------------------------------------------- 1 | package com.android.benchmark.api; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteOpenHelper; 6 | import android.os.Build; 7 | import android.view.FrameMetrics; 8 | 9 | import com.android.benchmark.config.Constants; 10 | import com.android.benchmark.models.Entry; 11 | import com.android.benchmark.models.Result; 12 | import com.android.benchmark.results.GlobalResultsStore; 13 | import com.android.benchmark.results.UiBenchmarkResult; 14 | import com.topjohnwu.superuser.Shell; 15 | 16 | import java.io.IOException; 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import retrofit2.Call; 23 | import retrofit2.Response; 24 | import retrofit2.Retrofit; 25 | import retrofit2.converter.gson.GsonConverterFactory; 26 | 27 | public class JankBenchAPI { 28 | public static boolean uploadResults(Context context, String baseUrl) { 29 | boolean success= false; 30 | Entry entry = createEntry(context); 31 | 32 | try { 33 | success = upload(entry, baseUrl); 34 | } catch (IOException e) { 35 | e.printStackTrace(); 36 | } 37 | 38 | return success; 39 | } 40 | 41 | private static boolean upload(Entry entry, String url) throws IOException { 42 | Retrofit retrofit = new Retrofit.Builder() 43 | .baseUrl(url) 44 | .addConverterFactory(GsonConverterFactory.create()) 45 | .build(); 46 | 47 | JankBenchService resource = retrofit.create(JankBenchService.class); 48 | 49 | Call call = resource.uploadEntry(entry); 50 | Response response = call.execute(); 51 | 52 | return response.isSuccessful(); 53 | } 54 | 55 | private static Entry createEntry(Context context) { 56 | int lastRunId = GlobalResultsStore.getInstance(context).getLastRunId(); 57 | SQLiteDatabase db = GlobalResultsStore.getInstance(context).getReadableDatabase(); 58 | int lastRunRefreshRate; 59 | try { 60 | lastRunRefreshRate = GlobalResultsStore.getInstance(context).loadRefreshRate(lastRunId, db); 61 | } finally { 62 | db.close(); 63 | } 64 | HashMap resultsMap = GlobalResultsStore.getInstance(context).loadDetailedAggregatedResults(lastRunId); 65 | 66 | Entry entry = new Entry(); 67 | 68 | entry.setRunId(lastRunId); 69 | entry.setBenchmarkVersion(Constants.BENCHMARK_VERSION); 70 | entry.setDeviceName(Build.DEVICE); 71 | entry.setDeviceModel(Build.MODEL); 72 | entry.setDeviceProduct(Build.PRODUCT); 73 | entry.setDeviceBoard(Build.BOARD); 74 | entry.setDeviceManufacturer(Build.MANUFACTURER); 75 | entry.setDeviceBrand(Build.BRAND); 76 | entry.setDeviceHardware(Build.HARDWARE); 77 | entry.setAndroidVersion(Build.VERSION.RELEASE); 78 | entry.setBuildType(Build.TYPE); 79 | entry.setBuildTime(String.valueOf(Build.TIME)); 80 | entry.setFingerprint(Build.FINGERPRINT); 81 | entry.setRefreshRate(lastRunRefreshRate); 82 | 83 | String kernel_version = getKernelVersion(); 84 | entry.setKernelVersion(kernel_version); 85 | 86 | List results = new ArrayList<>(); 87 | 88 | for (Map.Entry resultEntry : resultsMap.entrySet()) { 89 | String testName = resultEntry.getKey(); 90 | UiBenchmarkResult uiResult = resultEntry.getValue(); 91 | 92 | Result result = new Result(); 93 | result.setTestName(testName); 94 | result.setScore(uiResult.getScore()); 95 | result.setJankPenalty(uiResult.getJankPenalty()); 96 | result.setConsistencyBonus(uiResult.getConsistencyBonus()); 97 | result.setJankPct(100 * uiResult.getNumJankFrames() / (double) uiResult.getTotalFrameCount()); 98 | result.setBadFramePct(100 * uiResult.getNumBadFrames() / (double) uiResult.getTotalFrameCount()); 99 | result.setTotalFrames(uiResult.getTotalFrameCount()); 100 | result.setMsAvg(uiResult.getAverage(FrameMetrics.TOTAL_DURATION)); 101 | result.setMs10thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 10)); 102 | result.setMs20thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 20)); 103 | result.setMs30thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 30)); 104 | result.setMs40thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 40)); 105 | result.setMs50thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 50)); 106 | result.setMs60thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 60)); 107 | result.setMs70thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 70)); 108 | result.setMs80thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 80)); 109 | result.setMs90thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 90)); 110 | result.setMs95thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 95)); 111 | result.setMs99thPctl(uiResult.getPercentile(FrameMetrics.TOTAL_DURATION, 99)); 112 | 113 | results.add(result); 114 | } 115 | 116 | entry.setResults(results); 117 | 118 | return entry; 119 | } 120 | 121 | private static String getKernelVersion() { 122 | List unameOutput = Shell.sh("uname -a").exec().getOut(); 123 | String kernel_version = unameOutput.size() == 0 ? null : unameOutput.get(0); 124 | return kernel_version; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/api/JankBenchService.java: -------------------------------------------------------------------------------- 1 | package com.android.benchmark.api; 2 | 3 | import com.android.benchmark.models.Entry; 4 | 5 | import retrofit2.Call; 6 | import retrofit2.http.Body; 7 | import retrofit2.http.POST; 8 | 9 | public interface JankBenchService { 10 | @POST("v1/results") 11 | Call uploadEntry(@Body Entry entry); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/app/BenchmarkDashboardFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.app; 18 | 19 | import androidx.fragment.app.Fragment; 20 | import android.os.Bundle; 21 | import android.view.LayoutInflater; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | 25 | import com.android.benchmark.R; 26 | 27 | /** 28 | * Fragment for the Benchmark dashboard 29 | */ 30 | public class BenchmarkDashboardFragment extends Fragment { 31 | 32 | public BenchmarkDashboardFragment() { 33 | } 34 | 35 | @Override 36 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 37 | Bundle savedInstanceState) { 38 | return inflater.inflate(R.layout.fragment_dashboard, container, false); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/app/BenchmarkListAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.app; 18 | 19 | import android.graphics.Typeface; 20 | import android.view.LayoutInflater; 21 | import android.view.View; 22 | import android.view.ViewGroup; 23 | import android.widget.BaseExpandableListAdapter; 24 | import android.widget.CheckBox; 25 | import android.widget.TextView; 26 | 27 | import com.android.benchmark.registry.BenchmarkGroup; 28 | import com.android.benchmark.registry.BenchmarkRegistry; 29 | import com.android.benchmark.R; 30 | 31 | /** 32 | * 33 | */ 34 | public class BenchmarkListAdapter extends BaseExpandableListAdapter { 35 | 36 | private final LayoutInflater mInflater; 37 | private final BenchmarkRegistry mRegistry; 38 | 39 | BenchmarkListAdapter(LayoutInflater inflater, 40 | BenchmarkRegistry registry) { 41 | mInflater = inflater; 42 | mRegistry = registry; 43 | } 44 | 45 | @Override 46 | public int getGroupCount() { 47 | return mRegistry.getGroupCount(); 48 | } 49 | 50 | @Override 51 | public int getChildrenCount(int groupPosition) { 52 | return mRegistry.getBenchmarkCount(groupPosition); 53 | } 54 | 55 | @Override 56 | public Object getGroup(int groupPosition) { 57 | return mRegistry.getBenchmarkGroup(groupPosition); 58 | } 59 | 60 | @Override 61 | public Object getChild(int groupPosition, int childPosition) { 62 | BenchmarkGroup benchmarkGroup = mRegistry.getBenchmarkGroup(groupPosition); 63 | 64 | if (benchmarkGroup != null) { 65 | return benchmarkGroup.getBenchmarks()[childPosition]; 66 | } 67 | 68 | return null; 69 | } 70 | 71 | @Override 72 | public long getGroupId(int groupPosition) { 73 | return groupPosition; 74 | } 75 | 76 | @Override 77 | public long getChildId(int groupPosition, int childPosition) { 78 | return childPosition; 79 | } 80 | 81 | @Override 82 | public boolean hasStableIds() { 83 | return false; 84 | } 85 | 86 | @Override 87 | public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 88 | BenchmarkGroup group = (BenchmarkGroup) getGroup(groupPosition); 89 | if (convertView == null) { 90 | convertView = mInflater.inflate(R.layout.benchmark_list_group_row, null); 91 | } 92 | 93 | TextView title = (TextView) convertView.findViewById(R.id.group_name); 94 | title.setTypeface(null, Typeface.BOLD); 95 | title.setText(group.getTitle()); 96 | return convertView; 97 | } 98 | 99 | @Override 100 | public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 101 | View convertView, ViewGroup parent) { 102 | BenchmarkGroup.Benchmark benchmark = 103 | (BenchmarkGroup.Benchmark) getChild(groupPosition, childPosition); 104 | if (convertView == null) { 105 | convertView = mInflater.inflate(R.layout.benchmark_list_item, null); 106 | } 107 | 108 | TextView name = (TextView) convertView.findViewById(R.id.benchmark_name); 109 | name.setText(benchmark.getName()); 110 | CheckBox enabledBox = (CheckBox) convertView.findViewById(R.id.benchmark_enable_checkbox); 111 | enabledBox.setOnClickListener(benchmark); 112 | enabledBox.setChecked(benchmark.isEnabled()); 113 | 114 | return convertView; 115 | } 116 | 117 | @Override 118 | public boolean isChildSelectable(int groupPosition, int childPosition) { 119 | return true; 120 | } 121 | 122 | public int getChildrenHeight() { 123 | // TODO 124 | return 1024; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/app/HomeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.app; 18 | 19 | import android.content.Intent; 20 | import android.net.Uri; 21 | import android.os.AsyncTask; 22 | import android.os.Build; 23 | import android.os.Bundle; 24 | import android.util.Log; 25 | import android.view.LayoutInflater; 26 | import android.view.Menu; 27 | import android.view.MenuItem; 28 | import android.view.View; 29 | import android.view.ViewGroup; 30 | import android.widget.Button; 31 | import android.widget.ExpandableListView; 32 | import android.widget.Toast; 33 | 34 | import androidx.appcompat.app.AppCompatActivity; 35 | import androidx.appcompat.widget.Toolbar; 36 | 37 | import com.android.benchmark.R; 38 | import com.android.benchmark.api.JankBenchAPI; 39 | import com.android.benchmark.config.Constants; 40 | import com.android.benchmark.registry.BenchmarkRegistry; 41 | import com.android.benchmark.results.GlobalResultsStore; 42 | 43 | import com.google.android.material.floatingactionbutton.FloatingActionButton; 44 | import com.topjohnwu.superuser.Shell; 45 | 46 | import java.io.IOException; 47 | import java.util.LinkedList; 48 | import java.util.Queue; 49 | 50 | public class HomeActivity extends AppCompatActivity implements Button.OnClickListener { 51 | 52 | static { 53 | /* Shell.Config methods shall be called before any shell is created 54 | * This is the why in this example we call it in a static block 55 | * The followings are some examples, check Javadoc for more details */ 56 | Shell.Config.setFlags(Shell.FLAG_REDIRECT_STDERR); 57 | Shell.Config.setTimeout(10); 58 | } 59 | 60 | private FloatingActionButton mStartButton; 61 | private BenchmarkRegistry mRegistry; 62 | private Queue mRunnableBenchmarks; 63 | 64 | @Override 65 | protected void onCreate(Bundle savedInstanceState) { 66 | super.onCreate(savedInstanceState); 67 | setContentView(R.layout.activity_home); 68 | 69 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 70 | setSupportActionBar(toolbar); 71 | 72 | mStartButton = (FloatingActionButton) findViewById(R.id.start_button); 73 | mStartButton.setActivated(true); 74 | mStartButton.setOnClickListener(this); 75 | 76 | mRegistry = new BenchmarkRegistry(this); 77 | 78 | mRunnableBenchmarks = new LinkedList<>(); 79 | 80 | ExpandableListView listView = (ExpandableListView) findViewById(R.id.test_list); 81 | BenchmarkListAdapter adapter = 82 | new BenchmarkListAdapter(LayoutInflater.from(this), mRegistry); 83 | listView.setAdapter(adapter); 84 | 85 | adapter.notifyDataSetChanged(); 86 | ViewGroup.LayoutParams layoutParams = listView.getLayoutParams(); 87 | layoutParams.height = 2048; 88 | listView.setLayoutParams(layoutParams); 89 | listView.requestLayout(); 90 | System.out.println(System.getProperties().stringPropertyNames()); 91 | } 92 | 93 | @Override 94 | public boolean onCreateOptionsMenu(Menu menu) { 95 | // Inflate the menu; this adds items to the action bar if it is present. 96 | getMenuInflater().inflate(R.menu.menu_main, menu); 97 | return true; 98 | } 99 | 100 | @Override 101 | public boolean onOptionsItemSelected(MenuItem item) { 102 | // Handle action bar item clicks here. The action bar will 103 | // automatically handle clicks on the Home/Up button, so long 104 | // as you specify a parent activity in AndroidManifest.xml. 105 | int id = item.getItemId(); 106 | 107 | //noinspection SimplifiableIfStatement 108 | if (id == R.id.action_settings) { 109 | new AsyncTask() { 110 | @Override 111 | protected Void doInBackground(Void... voids) { 112 | try { 113 | HomeActivity.this.runOnUiThread(new Runnable() { 114 | @Override 115 | public void run() { 116 | Toast.makeText(HomeActivity.this, "Exporting...", Toast.LENGTH_LONG).show(); 117 | } 118 | }); 119 | GlobalResultsStore.getInstance(HomeActivity.this).exportToCsv(); 120 | } catch (IOException e) { 121 | e.printStackTrace(); 122 | } 123 | return null; 124 | } 125 | 126 | @Override 127 | protected void onPostExecute(Void aVoid) { 128 | HomeActivity.this.runOnUiThread(new Runnable() { 129 | @Override 130 | public void run() { 131 | Toast.makeText(HomeActivity.this, "Done", Toast.LENGTH_LONG).show(); 132 | } 133 | }); 134 | } 135 | }.execute(); 136 | 137 | return true; 138 | } else if (id == R.id.action_upload) { 139 | 140 | new AsyncTask() { 141 | boolean success; 142 | 143 | @Override 144 | protected Void doInBackground(Void... voids) { 145 | HomeActivity.this.runOnUiThread(new Runnable() { 146 | @Override 147 | public void run() { 148 | Toast.makeText(HomeActivity.this, "Uploading results...", Toast.LENGTH_LONG).show(); 149 | } 150 | }); 151 | 152 | success = JankBenchAPI.uploadResults(HomeActivity.this, Constants.BASE_URL); 153 | 154 | return null; 155 | } 156 | 157 | @Override 158 | protected void onPostExecute(Void aVoid) { 159 | HomeActivity.this.runOnUiThread(new Runnable() { 160 | @Override 161 | public void run() { 162 | Toast.makeText(HomeActivity.this, success ? "Upload succeeded" : "Upload failed", Toast.LENGTH_LONG).show(); 163 | } 164 | }); 165 | } 166 | }.execute(); 167 | 168 | return true; 169 | } else if (id == R.id.action_view_results) { 170 | Uri webpage = Uri.parse("https://jankbenchx.vercel.app"); 171 | Intent intent = new Intent(Intent.ACTION_VIEW, webpage); 172 | if (intent.resolveActivity(getPackageManager()) != null) { 173 | startActivity(intent); 174 | } 175 | } 176 | 177 | 178 | return super.onOptionsItemSelected(item); 179 | } 180 | 181 | @Override 182 | public void onClick(View v) { 183 | final int groupCount = mRegistry.getGroupCount(); 184 | for (int i = 0; i < groupCount; i++) { 185 | 186 | Intent intent = mRegistry.getBenchmarkGroup(i).getIntent(); 187 | if (intent != null) { 188 | mRunnableBenchmarks.add(intent); 189 | } 190 | } 191 | 192 | handleNextBenchmark(); 193 | } 194 | 195 | @Override 196 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 197 | super.onActivityResult(requestCode, resultCode, data); 198 | } 199 | 200 | private void handleNextBenchmark() { 201 | Intent nextIntent = mRunnableBenchmarks.peek(); 202 | startActivityForResult(nextIntent, 0); 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/app/PerfTimeline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.app; 18 | 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.graphics.*; 22 | import android.text.TextPaint; 23 | import android.util.AttributeSet; 24 | import android.view.View; 25 | 26 | import com.android.benchmark.R; 27 | 28 | 29 | /** 30 | * TODO: document your custom view class. 31 | */ 32 | public class PerfTimeline extends View { 33 | private String mExampleString; // TODO: use a default from R.string... 34 | private int mExampleColor = Color.RED; // TODO: use a default from R.color... 35 | private float mExampleDimension = 300; // TODO: use a default from R.dimen... 36 | 37 | private TextPaint mTextPaint; 38 | private float mTextWidth; 39 | private float mTextHeight; 40 | 41 | private Paint mPaintBaseLow; 42 | private Paint mPaintBaseHigh; 43 | private Paint mPaintValue; 44 | 45 | 46 | public float[] mLinesLow; 47 | public float[] mLinesHigh; 48 | public float[] mLinesValue; 49 | 50 | public PerfTimeline(Context context) { 51 | super(context); 52 | init(null, 0); 53 | } 54 | 55 | public PerfTimeline(Context context, AttributeSet attrs) { 56 | super(context, attrs); 57 | init(attrs, 0); 58 | } 59 | 60 | public PerfTimeline(Context context, AttributeSet attrs, int defStyle) { 61 | super(context, attrs, defStyle); 62 | init(attrs, defStyle); 63 | } 64 | 65 | private void init(AttributeSet attrs, int defStyle) { 66 | // Load attributes 67 | final TypedArray a = getContext().obtainStyledAttributes( 68 | attrs, R.styleable.PerfTimeline, defStyle, 0); 69 | 70 | mExampleString = "xx";//a.getString(R.styleable.PerfTimeline_exampleString, "xx"); 71 | mExampleColor = a.getColor(R.styleable.PerfTimeline_exampleColor, mExampleColor); 72 | // Use getDimensionPixelSize or getDimensionPixelOffset when dealing with 73 | // values that should fall on pixel boundaries. 74 | mExampleDimension = a.getDimension( 75 | R.styleable.PerfTimeline_exampleDimension, 76 | mExampleDimension); 77 | 78 | a.recycle(); 79 | 80 | // Set up a default TextPaint object 81 | mTextPaint = new TextPaint(); 82 | mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); 83 | mTextPaint.setTextAlign(Paint.Align.LEFT); 84 | 85 | // Update TextPaint and text measurements from attributes 86 | invalidateTextPaintAndMeasurements(); 87 | 88 | mPaintBaseLow = new Paint(Paint.ANTI_ALIAS_FLAG); 89 | mPaintBaseLow.setStyle(Paint.Style.FILL); 90 | mPaintBaseLow.setColor(0xff000000); 91 | 92 | mPaintBaseHigh = new Paint(Paint.ANTI_ALIAS_FLAG); 93 | mPaintBaseHigh.setStyle(Paint.Style.FILL); 94 | mPaintBaseHigh.setColor(0x7f7f7f7f); 95 | 96 | mPaintValue = new Paint(Paint.ANTI_ALIAS_FLAG); 97 | mPaintValue.setStyle(Paint.Style.FILL); 98 | mPaintValue.setColor(0x7fff0000); 99 | 100 | } 101 | 102 | private void invalidateTextPaintAndMeasurements() { 103 | mTextPaint.setTextSize(mExampleDimension); 104 | mTextPaint.setColor(mExampleColor); 105 | mTextWidth = mTextPaint.measureText(mExampleString); 106 | 107 | Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics(); 108 | mTextHeight = fontMetrics.bottom; 109 | } 110 | 111 | @Override 112 | protected void onDraw(Canvas canvas) { 113 | super.onDraw(canvas); 114 | 115 | // TODO: consider storing these as member variables to reduce 116 | // allocations per draw cycle. 117 | int paddingLeft = getPaddingLeft(); 118 | int paddingTop = getPaddingTop(); 119 | int paddingRight = getPaddingRight(); 120 | int paddingBottom = getPaddingBottom(); 121 | 122 | int contentWidth = getWidth() - paddingLeft - paddingRight; 123 | int contentHeight = getHeight() - paddingTop - paddingBottom; 124 | 125 | // Draw the text. 126 | //canvas.drawText(mExampleString, 127 | // paddingLeft + (contentWidth - mTextWidth) / 2, 128 | // paddingTop + (contentHeight + mTextHeight) / 2, 129 | // mTextPaint); 130 | 131 | 132 | 133 | 134 | // Draw the shadow 135 | //RectF rf = new RectF(10.f, 10.f, 100.f, 100.f); 136 | //canvas.drawOval(rf, mShadowPaint); 137 | 138 | if (mLinesLow != null) { 139 | canvas.drawLines(mLinesLow, mPaintBaseLow); 140 | } 141 | if (mLinesHigh != null) { 142 | canvas.drawLines(mLinesHigh, mPaintBaseHigh); 143 | } 144 | if (mLinesValue != null) { 145 | canvas.drawLines(mLinesValue, mPaintValue); 146 | } 147 | 148 | 149 | /* 150 | // Draw the pie slices 151 | for (int i = 0; i < mData.size(); ++i) { 152 | Item it = mData.get(i); 153 | mPiePaint.setShader(it.mShader); 154 | canvas.drawArc(mBounds, 155 | 360 - it.mEndAngle, 156 | it.mEndAngle - it.mStartAngle, 157 | true, mPiePaint); 158 | } 159 | */ 160 | // Draw the pointer 161 | //canvas.drawLine(mTextX, mPointerY, mPointerX, mPointerY, mTextPaint); 162 | //canvas.drawCircle(mPointerX, mPointerY, mPointerSize, mTextPaint); 163 | } 164 | 165 | /** 166 | * Gets the example string attribute value. 167 | * 168 | * @return The example string attribute value. 169 | */ 170 | public String getExampleString() { 171 | return mExampleString; 172 | } 173 | 174 | /** 175 | * Sets the view's example string attribute value. In the example view, this string 176 | * is the text to draw. 177 | * 178 | * @param exampleString The example string attribute value to use. 179 | */ 180 | public void setExampleString(String exampleString) { 181 | mExampleString = exampleString; 182 | invalidateTextPaintAndMeasurements(); 183 | } 184 | 185 | /** 186 | * Gets the example color attribute value. 187 | * 188 | * @return The example color attribute value. 189 | */ 190 | public int getExampleColor() { 191 | return mExampleColor; 192 | } 193 | 194 | /** 195 | * Sets the view's example color attribute value. In the example view, this color 196 | * is the font color. 197 | * 198 | * @param exampleColor The example color attribute value to use. 199 | */ 200 | public void setExampleColor(int exampleColor) { 201 | mExampleColor = exampleColor; 202 | invalidateTextPaintAndMeasurements(); 203 | } 204 | 205 | /** 206 | * Gets the example dimension attribute value. 207 | * 208 | * @return The example dimension attribute value. 209 | */ 210 | public float getExampleDimension() { 211 | return mExampleDimension; 212 | } 213 | 214 | /** 215 | * Sets the view's example dimension attribute value. In the example view, this dimension 216 | * is the font size. 217 | * 218 | * @param exampleDimension The example dimension attribute value to use. 219 | */ 220 | public void setExampleDimension(float exampleDimension) { 221 | mExampleDimension = exampleDimension; 222 | invalidateTextPaintAndMeasurements(); 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/app/UiResultsFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.app; 18 | 19 | import android.annotation.TargetApi; 20 | import android.os.AsyncTask; 21 | import android.os.Bundle; 22 | import androidx.annotation.Nullable; 23 | import androidx.fragment.app.ListFragment; 24 | import android.util.Log; 25 | import android.view.FrameMetrics; 26 | import android.widget.SimpleAdapter; 27 | 28 | import com.android.benchmark.R; 29 | import com.android.benchmark.registry.BenchmarkGroup; 30 | import com.android.benchmark.registry.BenchmarkRegistry; 31 | import com.android.benchmark.results.GlobalResultsStore; 32 | import com.android.benchmark.results.UiBenchmarkResult; 33 | 34 | import org.apache.commons.math3.stat.descriptive.SummaryStatistics; 35 | 36 | import java.io.FileWriter; 37 | import java.io.IOException; 38 | import java.net.URI; 39 | import java.text.DecimalFormat; 40 | import java.util.ArrayList; 41 | import java.util.HashMap; 42 | import java.util.Map; 43 | 44 | @TargetApi(24) 45 | public class UiResultsFragment extends ListFragment { 46 | private static final String TAG = "UiResultsFragment"; 47 | private static final int NUM_FIELDS = 20; 48 | 49 | private ArrayList mResults = new ArrayList<>(); 50 | 51 | private AsyncTask>> mLoadScoresTask = 52 | new AsyncTask>>() { 53 | @Override 54 | protected ArrayList> doInBackground(Void... voids) { 55 | String[] data; 56 | if (mResults.size() == 0 || mResults.get(0) == null) { 57 | data = new String[] { 58 | "No metrics reported", "" 59 | }; 60 | } else { 61 | data = new String[NUM_FIELDS * (1 + mResults.size()) + 2]; 62 | SummaryStatistics stats = new SummaryStatistics(); 63 | int totalFrameCount = 0; 64 | double totalAvgFrameDuration = 0; 65 | double total99FrameDuration = 0; 66 | double total95FrameDuration = 0; 67 | double total90FrameDuration = 0; 68 | double totalLongestFrame = 0; 69 | double totalShortestFrame = 0; 70 | 71 | for (int i = 0; i < mResults.size(); i++) { 72 | int start = (i * NUM_FIELDS) + + NUM_FIELDS; 73 | data[(start++)] = "Iteration"; 74 | data[(start++)] = "" + i; 75 | data[(start++)] = "Total Frames"; 76 | int currentFrameCount = mResults.get(i).getTotalFrameCount(); 77 | totalFrameCount += currentFrameCount; 78 | data[(start++)] = Integer.toString(currentFrameCount); 79 | data[(start++)] = "Average frame duration:"; 80 | double currentAvgFrameDuration = mResults.get(i).getAverage(FrameMetrics.TOTAL_DURATION); 81 | totalAvgFrameDuration += currentAvgFrameDuration; 82 | data[(start++)] = String.format("%.2f", currentAvgFrameDuration); 83 | data[(start++)] = "Frame duration 99th:"; 84 | double current99FrameDuration = mResults.get(i).getPercentile(FrameMetrics.TOTAL_DURATION, 99); 85 | total99FrameDuration += current99FrameDuration; 86 | data[(start++)] = String.format("%.2f", current99FrameDuration); 87 | data[(start++)] = "Frame duration 95th:"; 88 | double current95FrameDuration = mResults.get(i).getPercentile(FrameMetrics.TOTAL_DURATION, 95); 89 | total95FrameDuration += current95FrameDuration; 90 | data[(start++)] = String.format("%.2f", current95FrameDuration); 91 | data[(start++)] = "Frame duration 90th:"; 92 | double current90FrameDuration = mResults.get(i).getPercentile(FrameMetrics.TOTAL_DURATION, 90); 93 | total90FrameDuration += current90FrameDuration; 94 | data[(start++)] = String.format("%.2f", current90FrameDuration); 95 | data[(start++)] = "Longest frame:"; 96 | double longestFrame = mResults.get(i).getMaximum(FrameMetrics.TOTAL_DURATION); 97 | if (totalLongestFrame == 0 || longestFrame > totalLongestFrame) { 98 | totalLongestFrame = longestFrame; 99 | } 100 | data[(start++)] = String.format("%.2f", longestFrame); 101 | data[(start++)] = "Shortest frame:"; 102 | double shortestFrame = mResults.get(i).getMinimum(FrameMetrics.TOTAL_DURATION); 103 | if (totalShortestFrame == 0 || totalShortestFrame > shortestFrame) { 104 | totalShortestFrame = shortestFrame; 105 | } 106 | data[(start++)] = String.format("%.2f", shortestFrame); 107 | data[(start++)] = "Score:"; 108 | double score = mResults.get(i).getScore(); 109 | stats.addValue(score); 110 | data[(start++)] = String.format("%.2f", score); 111 | data[(start++)] = "=============="; 112 | data[(start++)] = "============================"; 113 | }; 114 | 115 | int start = 0; 116 | data[0] = "Overall: "; 117 | data[1] = ""; 118 | data[(start++)] = "Total Frames"; 119 | data[(start++)] = Integer.toString(totalFrameCount); 120 | data[(start++)] = "Average frame duration:"; 121 | data[(start++)] = String.format("%.2f", totalAvgFrameDuration / mResults.size()); 122 | data[(start++)] = "Frame duration 99th:"; 123 | data[(start++)] = String.format("%.2f", total99FrameDuration / mResults.size()); 124 | data[(start++)] = "Frame duration 95th:"; 125 | data[(start++)] = String.format("%.2f", total95FrameDuration / mResults.size()); 126 | data[(start++)] = "Frame duration 90th:"; 127 | data[(start++)] = String.format("%.2f", total90FrameDuration / mResults.size()); 128 | data[(start++)] = "Longest frame:"; 129 | data[(start++)] = String.format("%.2f", totalLongestFrame); 130 | data[(start++)] = "Shortest frame:"; 131 | data[(start++)] = String.format("%.2f", totalShortestFrame); 132 | data[(start++)] = "Score:"; 133 | data[(start++)] = String.format("%.2f", stats.getGeometricMean()); 134 | data[(start++)] = "=============="; 135 | data[(start++)] = "============================"; 136 | } 137 | 138 | ArrayList> dataMap = new ArrayList<>(); 139 | for (int i = 0; i < data.length - 1; i += 2) { 140 | HashMap map = new HashMap<>(); 141 | map.put("name", data[i]); 142 | map.put("value", data[i + 1]); 143 | dataMap.add(map); 144 | } 145 | 146 | return dataMap; 147 | } 148 | 149 | @Override 150 | protected void onPostExecute(ArrayList> dataMap) { 151 | setListAdapter(new SimpleAdapter(getActivity(), dataMap, R.layout.results_list_item, 152 | new String[] {"name", "value"}, new int[] { R.id.result_name, R.id.result_value })); 153 | setListShown(true); 154 | } 155 | }; 156 | 157 | @Override 158 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 159 | super.onActivityCreated(savedInstanceState); 160 | setListShown(false); 161 | mLoadScoresTask.execute(); 162 | } 163 | 164 | public void setRunInfo(String name, int runId) { 165 | mResults = GlobalResultsStore.getInstance(getActivity()).loadTestResults(name, runId); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/config/Constants.java: -------------------------------------------------------------------------------- 1 | package com.android.benchmark.config; 2 | 3 | public class Constants { 4 | private Constants() {} 5 | 6 | public static final String BASE_URL = "https://jankbenchx.vercel.app/api/"; 7 | public static final String BENCHMARK_VERSION = "0.1"; 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/models/Entry.java: -------------------------------------------------------------------------------- 1 | package com.android.benchmark.models; 2 | 3 | import java.util.List; 4 | import com.google.gson.annotations.Expose; 5 | import com.google.gson.annotations.SerializedName; 6 | 7 | public class Entry { 8 | 9 | @SerializedName("run_id") 10 | @Expose 11 | private Integer runId; 12 | @SerializedName("benchmark_version") 13 | @Expose 14 | private String benchmarkVersion; 15 | @SerializedName("device_name") 16 | @Expose 17 | private String device_name; 18 | @SerializedName("device_model") 19 | @Expose 20 | private String deviceModel; 21 | @SerializedName("device_product") 22 | @Expose 23 | private String deviceProduct; 24 | @SerializedName("device_board") 25 | @Expose 26 | private String deviceBoard; 27 | @SerializedName("device_manufacturer") 28 | @Expose 29 | private String deviceManufacturer; 30 | @SerializedName("device_brand") 31 | @Expose 32 | private String deviceBrand; 33 | @SerializedName("device_hardware") 34 | @Expose 35 | private String deviceHardware; 36 | @SerializedName("android_version") 37 | @Expose 38 | private String androidVersion; 39 | @SerializedName("build_type") 40 | @Expose 41 | private String buildType; 42 | @SerializedName("build_time") 43 | @Expose 44 | private String buildTime; 45 | @SerializedName("fingerprint") 46 | @Expose 47 | private String fingerprint; 48 | @SerializedName("kernel_version") 49 | @Expose 50 | private String kernelVersion; 51 | @SerializedName("results") 52 | @Expose 53 | private List results = null; 54 | @SerializedName("refresh_rate") 55 | @Expose 56 | private Integer refreshRate; 57 | 58 | public Integer getRunId() { 59 | return runId; 60 | } 61 | 62 | public void setRunId(Integer runId) { 63 | this.runId = runId; 64 | } 65 | 66 | public String getBenchmarkVersion() { 67 | return benchmarkVersion; 68 | } 69 | 70 | public void setBenchmarkVersion(String benchmarkVersion) { 71 | this.benchmarkVersion = benchmarkVersion; 72 | } 73 | 74 | public String getDeviceName() { 75 | return device_name; 76 | } 77 | 78 | public void setDeviceName(String device_name) { 79 | this.device_name = device_name; 80 | } 81 | 82 | public String getDeviceModel() { 83 | return deviceModel; 84 | } 85 | 86 | public void setDeviceModel(String deviceModel) { 87 | this.deviceModel = deviceModel; 88 | } 89 | 90 | public String getDeviceProduct() { 91 | return deviceProduct; 92 | } 93 | 94 | public void setDeviceProduct(String deviceProduct) { 95 | this.deviceProduct = deviceProduct; 96 | } 97 | 98 | public String getDeviceBoard() { 99 | return deviceBoard; 100 | } 101 | 102 | public void setDeviceBoard(String deviceBoard) { 103 | this.deviceBoard = deviceBoard; 104 | } 105 | 106 | public String getDeviceManufacturer() { 107 | return deviceManufacturer; 108 | } 109 | 110 | public void setDeviceManufacturer(String deviceManufacturer) { 111 | this.deviceManufacturer = deviceManufacturer; 112 | } 113 | 114 | public String getDeviceBrand() { 115 | return deviceBrand; 116 | } 117 | 118 | public void setDeviceBrand(String deviceBrand) { 119 | this.deviceBrand = deviceBrand; 120 | } 121 | 122 | public String getDeviceHardware() { 123 | return deviceHardware; 124 | } 125 | 126 | public void setDeviceHardware(String deviceHardware) { 127 | this.deviceHardware = deviceHardware; 128 | } 129 | 130 | public String getAndroidVersion() { 131 | return androidVersion; 132 | } 133 | 134 | public void setAndroidVersion(String androidVersion) { 135 | this.androidVersion = androidVersion; 136 | } 137 | 138 | public String getBuildType() { 139 | return buildType; 140 | } 141 | 142 | public void setBuildType(String buildType) { 143 | this.buildType = buildType; 144 | } 145 | 146 | public String getBuildTime() { 147 | return buildTime; 148 | } 149 | 150 | public void setBuildTime(String buildTime) { 151 | this.buildTime = buildTime; 152 | } 153 | 154 | public String getFingerprint() { 155 | return fingerprint; 156 | } 157 | 158 | public void setFingerprint(String fingerprint) { 159 | this.fingerprint = fingerprint; 160 | } 161 | 162 | public String getKernelVersion() { 163 | return kernelVersion; 164 | } 165 | 166 | public void setKernelVersion(String kernelVersion) { 167 | this.kernelVersion = kernelVersion; 168 | } 169 | 170 | public List getResults() { 171 | return results; 172 | } 173 | 174 | public void setResults(List results) { 175 | this.results = results; 176 | } 177 | 178 | public int getRefreshRate() { 179 | return refreshRate; 180 | } 181 | 182 | public void setRefreshRate(int refreshRate) { 183 | this.refreshRate = refreshRate; 184 | } 185 | } -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/models/Result.java: -------------------------------------------------------------------------------- 1 | package com.android.benchmark.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | public class Result { 7 | 8 | @SerializedName("test_name") 9 | @Expose 10 | private String testName; 11 | @SerializedName("score") 12 | @Expose 13 | private Integer score; 14 | @SerializedName("jank_penalty") 15 | @Expose 16 | private Integer jankPenalty; 17 | @SerializedName("consistency_bonus") 18 | @Expose 19 | private Integer consistencyBonus; 20 | @SerializedName("jank_pct") 21 | @Expose 22 | private Double jankPct; 23 | @SerializedName("bad_frame_pct") 24 | @Expose 25 | private Double badFramePct; 26 | @SerializedName("total_frames") 27 | @Expose 28 | private Integer totalFrames; 29 | @SerializedName("ms_avg") 30 | @Expose 31 | private Double msAvg; 32 | @SerializedName("ms_10th_pctl") 33 | @Expose 34 | private Double ms10thPctl; 35 | @SerializedName("ms_20th_pctl") 36 | @Expose 37 | private Double ms20thPctl; 38 | @SerializedName("ms_30th_pctl") 39 | @Expose 40 | private Double ms30thPctl; 41 | @SerializedName("ms_40th_pctl") 42 | @Expose 43 | private Double ms40thPctl; 44 | @SerializedName("ms_50th_pctl") 45 | @Expose 46 | private Double ms50thPctl; 47 | @SerializedName("ms_60th_pctl") 48 | @Expose 49 | private Double ms60thPctl; 50 | @SerializedName("ms_70th_pctl") 51 | @Expose 52 | private Double ms70thPctl; 53 | @SerializedName("ms_80th_pctl") 54 | @Expose 55 | private Double ms80thPctl; 56 | @SerializedName("ms_90th_pctl") 57 | @Expose 58 | private Double ms90thPctl; 59 | @SerializedName("ms_95th_pctl") 60 | @Expose 61 | private Double ms95thPctl; 62 | @SerializedName("ms_99th_pctl") 63 | @Expose 64 | private Double ms99thPctl; 65 | 66 | public String getTestName() { 67 | return testName; 68 | } 69 | 70 | public void setTestName(String testName) { 71 | this.testName = testName; 72 | } 73 | 74 | public Integer getScore() { 75 | return score; 76 | } 77 | 78 | public void setScore(Integer score) { 79 | this.score = score; 80 | } 81 | 82 | public Integer getJankPenalty() { 83 | return jankPenalty; 84 | } 85 | 86 | public void setJankPenalty(Integer jankPenalty) { 87 | this.jankPenalty = jankPenalty; 88 | } 89 | 90 | public Integer getConsistencyBonus() { 91 | return consistencyBonus; 92 | } 93 | 94 | public void setConsistencyBonus(Integer consistencyBonus) { 95 | this.consistencyBonus = consistencyBonus; 96 | } 97 | 98 | public Double getJankPct() { 99 | return jankPct; 100 | } 101 | 102 | public void setJankPct(Double jankPct) { 103 | this.jankPct = jankPct; 104 | } 105 | 106 | public Double getBadFramePct() { 107 | return badFramePct; 108 | } 109 | 110 | public void setBadFramePct(Double badFramePct) { 111 | this.badFramePct = badFramePct; 112 | } 113 | 114 | public Integer getTotalFrames() { 115 | return totalFrames; 116 | } 117 | 118 | public void setTotalFrames(Integer totalFrames) { 119 | this.totalFrames = totalFrames; 120 | } 121 | 122 | public Double getMsAvg() { 123 | return msAvg; 124 | } 125 | 126 | public void setMsAvg(Double msAvg) { 127 | this.msAvg = msAvg; 128 | } 129 | 130 | public Double getMs10thPctl() { 131 | return ms10thPctl; 132 | } 133 | 134 | public void setMs10thPctl(Double ms10thPctl) { 135 | this.ms10thPctl = ms10thPctl; 136 | } 137 | 138 | public Double getMs20thPctl() { 139 | return ms20thPctl; 140 | } 141 | 142 | public void setMs20thPctl(Double ms20thPctl) { 143 | this.ms20thPctl = ms20thPctl; 144 | } 145 | 146 | public Double getMs30thPctl() { 147 | return ms30thPctl; 148 | } 149 | 150 | public void setMs30thPctl(Double ms30thPctl) { 151 | this.ms30thPctl = ms30thPctl; 152 | } 153 | 154 | public Double getMs40thPctl() { 155 | return ms40thPctl; 156 | } 157 | 158 | public void setMs40thPctl(Double ms40thPctl) { 159 | this.ms40thPctl = ms40thPctl; 160 | } 161 | 162 | public Double getMs50thPctl() { 163 | return ms50thPctl; 164 | } 165 | 166 | public void setMs50thPctl(Double ms50thPctl) { 167 | this.ms50thPctl = ms50thPctl; 168 | } 169 | 170 | public Double getMs60thPctl() { 171 | return ms60thPctl; 172 | } 173 | 174 | public void setMs60thPctl(Double ms60thPctl) { 175 | this.ms60thPctl = ms60thPctl; 176 | } 177 | 178 | public Double getMs70thPctl() { 179 | return ms70thPctl; 180 | } 181 | 182 | public void setMs70thPctl(Double ms70thPctl) { 183 | this.ms70thPctl = ms70thPctl; 184 | } 185 | 186 | public Double getMs80thPctl() { 187 | return ms80thPctl; 188 | } 189 | 190 | public void setMs80thPctl(Double ms80thPctl) { 191 | this.ms80thPctl = ms80thPctl; 192 | } 193 | 194 | public Double getMs90thPctl() { 195 | return ms90thPctl; 196 | } 197 | 198 | public void setMs90thPctl(Double ms90thPctl) { 199 | this.ms90thPctl = ms90thPctl; 200 | } 201 | 202 | public Double getMs95thPctl() { 203 | return ms95thPctl; 204 | } 205 | 206 | public void setMs95thPctl(Double ms95thPctl) { 207 | this.ms95thPctl = ms95thPctl; 208 | } 209 | 210 | public Double getMs99thPctl() { 211 | return ms99thPctl; 212 | } 213 | 214 | public void setMs99thPctl(Double ms99thPctl) { 215 | this.ms99thPctl = ms99thPctl; 216 | } 217 | 218 | } -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/registry/BenchmarkCategory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.registry; 18 | 19 | import androidx.annotation.IntDef; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | 24 | /** 25 | * Represents the category of a particular benchmark. 26 | */ 27 | @Retention(RetentionPolicy.SOURCE) 28 | @IntDef({BenchmarkCategory.GENERIC, BenchmarkCategory.UI, BenchmarkCategory.COMPUTE}) 29 | @interface BenchmarkCategory { 30 | int GENERIC = 0; 31 | int UI = 1; 32 | int COMPUTE = 2; 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/registry/BenchmarkGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.registry; 18 | 19 | import android.content.ComponentName; 20 | import android.content.Intent; 21 | import android.view.View; 22 | import android.widget.CheckBox; 23 | 24 | /** 25 | * Logical grouping of benchmarks 26 | */ 27 | public class BenchmarkGroup { 28 | public static final String BENCHMARK_EXTRA_ENABLED_TESTS = 29 | "com.android.benchmark.EXTRA_ENABLED_BENCHMARK_IDS"; 30 | 31 | public static final String BENCHMARK_EXTRA_RUN_COUNT = 32 | "com.android.benchmark.EXTRA_RUN_COUNT"; 33 | public static final String BENCHMARK_EXTRA_FINISH = "com.android.benchmark.FINISH_WHEN_DONE"; 34 | 35 | public static class Benchmark implements CheckBox.OnClickListener { 36 | /** The name of this individual benchmark test */ 37 | private final String mName; 38 | 39 | /** The category of this individual benchmark test */ 40 | private final @BenchmarkCategory int mCategory; 41 | 42 | /** Human-readable description of the benchmark */ 43 | private final String mDescription; 44 | 45 | private final int mId; 46 | 47 | private boolean mEnabled; 48 | 49 | Benchmark(int id, String name, @BenchmarkCategory int category, String description) { 50 | mId = id; 51 | mName = name; 52 | mCategory = category; 53 | mDescription = description; 54 | mEnabled = true; 55 | } 56 | 57 | public boolean isEnabled() { return mEnabled; } 58 | 59 | public void setEnabled(boolean enabled) { mEnabled = enabled; } 60 | 61 | public int getId() { return mId; } 62 | 63 | public String getDescription() { return mDescription; } 64 | 65 | public @BenchmarkCategory int getCategory() { return mCategory; } 66 | 67 | public String getName() { return mName; } 68 | 69 | @Override 70 | public void onClick(View view) { 71 | setEnabled(((CheckBox)view).isChecked()); 72 | } 73 | } 74 | 75 | /** 76 | * Component for this benchmark group. 77 | */ 78 | private final ComponentName mComponentName; 79 | 80 | /** 81 | * Benchmark title, showed in the {@link android.widget.ListView} 82 | */ 83 | private final String mTitle; 84 | 85 | /** 86 | * List of all benchmarks exported by this group 87 | */ 88 | private final Benchmark[] mBenchmarks; 89 | 90 | /** 91 | * The intent to launch the benchmark 92 | */ 93 | private final Intent mIntent; 94 | 95 | /** Human-readable description of the benchmark group */ 96 | private final String mDescription; 97 | 98 | BenchmarkGroup(ComponentName componentName, String title, 99 | String description, Benchmark[] benchmarks, Intent intent) { 100 | mComponentName = componentName; 101 | mTitle = title; 102 | mBenchmarks = benchmarks; 103 | mDescription = description; 104 | mIntent = intent; 105 | } 106 | 107 | public Intent getIntent() { 108 | int[] enabledBenchmarksIds = getEnabledBenchmarksIds(); 109 | if (enabledBenchmarksIds.length != 0) { 110 | mIntent.putExtra(BENCHMARK_EXTRA_ENABLED_TESTS, enabledBenchmarksIds); 111 | return mIntent; 112 | } 113 | 114 | return null; 115 | } 116 | 117 | public ComponentName getComponentName() { 118 | return mComponentName; 119 | } 120 | 121 | public String getTitle() { 122 | return mTitle; 123 | } 124 | 125 | public Benchmark[] getBenchmarks() { 126 | return mBenchmarks; 127 | } 128 | 129 | public String getDescription() { 130 | return mDescription; 131 | } 132 | 133 | private int[] getEnabledBenchmarksIds() { 134 | int enabledBenchmarkCount = 0; 135 | for (int i = 0; i < mBenchmarks.length; i++) { 136 | if (mBenchmarks[i].isEnabled()) { 137 | enabledBenchmarkCount++; 138 | } 139 | } 140 | 141 | int writeIndex = 0; 142 | int[] enabledBenchmarks = new int[enabledBenchmarkCount]; 143 | for (int i = 0; i < mBenchmarks.length; i++) { 144 | if (mBenchmarks[i].isEnabled()) { 145 | enabledBenchmarks[writeIndex++] = mBenchmarks[i].getId(); 146 | } 147 | } 148 | 149 | return enabledBenchmarks; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/synthetic/MemoryActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.synthetic; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.os.Bundle; 22 | import android.view.Menu; 23 | import android.view.MenuItem; 24 | import android.view.View; 25 | import android.view.WindowManager; 26 | import android.widget.TextView; 27 | 28 | import com.android.benchmark.R; 29 | import com.android.benchmark.app.PerfTimeline; 30 | 31 | 32 | public class MemoryActivity extends Activity { 33 | private TextView mTextStatus; 34 | private TextView mTextMin; 35 | private TextView mTextMax; 36 | private TextView mTextTypical; 37 | private PerfTimeline mTimeline; 38 | 39 | TestInterface mTI; 40 | int mActiveTest; 41 | 42 | private class SyntheticTestCallback extends TestInterface.TestResultCallback { 43 | @Override 44 | void onTestResult(int command, float result) { 45 | Intent resultIntent = new Intent(); 46 | resultIntent.putExtra("com.android.benchmark.synthetic.TEST_RESULT", result); 47 | setResult(RESULT_OK, resultIntent); 48 | finish(); 49 | } 50 | } 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | super.onCreate(savedInstanceState); 55 | setContentView(R.layout.activity_memory); 56 | 57 | mTextStatus = (TextView) findViewById(R.id.textView_status); 58 | mTextMin = (TextView) findViewById(R.id.textView_min); 59 | mTextMax = (TextView) findViewById(R.id.textView_max); 60 | mTextTypical = (TextView) findViewById(R.id.textView_typical); 61 | 62 | mTimeline = (PerfTimeline) findViewById(R.id.mem_timeline); 63 | 64 | mTI = new TestInterface(mTimeline, 2, new SyntheticTestCallback()); 65 | mTI.mTextMax = mTextMax; 66 | mTI.mTextMin = mTextMin; 67 | mTI.mTextStatus = mTextStatus; 68 | mTI.mTextTypical = mTextTypical; 69 | 70 | mTimeline.mLinesLow = mTI.mLinesLow; 71 | mTimeline.mLinesHigh = mTI.mLinesHigh; 72 | mTimeline.mLinesValue = mTI.mLinesValue; 73 | 74 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 75 | } 76 | 77 | @Override 78 | protected void onResume() { 79 | super.onResume(); 80 | Intent i = getIntent(); 81 | mActiveTest = i.getIntExtra("test", 0); 82 | 83 | switch (mActiveTest) { 84 | case 0: 85 | mTI.runMemoryBandwidth(); 86 | break; 87 | case 1: 88 | mTI.runMemoryLatency(); 89 | break; 90 | case 2: 91 | mTI.runPowerManagement(); 92 | break; 93 | case 3: 94 | mTI.runCPUHeatSoak(); 95 | break; 96 | case 4: 97 | mTI.runCPUGFlops(); 98 | break; 99 | default: 100 | break; 101 | 102 | } 103 | } 104 | 105 | @Override 106 | public boolean onCreateOptionsMenu(Menu menu) { 107 | // Inflate the menu; this adds items to the action bar if it is present. 108 | getMenuInflater().inflate(R.menu.menu_memory, menu); 109 | return true; 110 | } 111 | 112 | @Override 113 | public boolean onOptionsItemSelected(MenuItem item) { 114 | // Handle action bar item clicks here. The action bar will 115 | // automatically handle clicks on the Home/Up button, so long 116 | // as you specify a parent activity in AndroidManifest.xml. 117 | int id = item.getItemId(); 118 | 119 | //noinspection SimplifiableIfStatement 120 | if (id == R.id.action_settings) { 121 | return true; 122 | } 123 | 124 | return super.onOptionsItemSelected(item); 125 | } 126 | 127 | public void onCpuBandwidth(View v) { 128 | 129 | 130 | } 131 | 132 | 133 | 134 | 135 | } 136 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/BitmapUploadActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.animation.ObjectAnimator; 20 | import android.animation.ValueAnimator; 21 | import android.content.Context; 22 | import android.content.Intent; 23 | import android.graphics.Bitmap; 24 | import android.graphics.Canvas; 25 | import android.graphics.Color; 26 | import android.graphics.Rect; 27 | import android.os.Bundle; 28 | import androidx.appcompat.app.AppCompatActivity; 29 | import android.util.AttributeSet; 30 | import android.util.DisplayMetrics; 31 | import android.view.MotionEvent; 32 | import android.view.View; 33 | 34 | import com.android.benchmark.R; 35 | import com.android.benchmark.registry.BenchmarkRegistry; 36 | import com.android.benchmark.ui.automation.Automator; 37 | import com.android.benchmark.ui.automation.Interaction; 38 | 39 | /** 40 | * 41 | */ 42 | public class BitmapUploadActivity extends AppCompatActivity { 43 | private Automator mAutomator; 44 | 45 | public static class UploadView extends View { 46 | private int mColorValue; 47 | private Bitmap mBitmap; 48 | private final DisplayMetrics mMetrics = new DisplayMetrics(); 49 | private final Rect mRect = new Rect(); 50 | 51 | public UploadView(Context context, AttributeSet attrs) { 52 | super(context, attrs); 53 | } 54 | 55 | @SuppressWarnings("unused") 56 | public void setColorValue(int colorValue) { 57 | if (colorValue == mColorValue) return; 58 | 59 | mColorValue = colorValue; 60 | 61 | // modify the bitmap's color to ensure it's uploaded to the GPU 62 | mBitmap.eraseColor(Color.rgb(mColorValue, 255 - mColorValue, 255)); 63 | 64 | invalidate(); 65 | } 66 | 67 | @Override 68 | protected void onAttachedToWindow() { 69 | super.onAttachedToWindow(); 70 | 71 | getDisplay().getMetrics(mMetrics); 72 | int minDisplayDimen = Math.min(mMetrics.widthPixels, mMetrics.heightPixels); 73 | int bitmapSize = Math.min((int) (minDisplayDimen * 0.75), 720); 74 | if (mBitmap == null 75 | || mBitmap.getWidth() != bitmapSize 76 | || mBitmap.getHeight() != bitmapSize) { 77 | mBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888); 78 | } 79 | } 80 | 81 | @Override 82 | protected void onDraw(Canvas canvas) { 83 | if (mBitmap != null) { 84 | mRect.set(0, 0, getWidth(), getHeight()); 85 | canvas.drawBitmap(mBitmap, null, mRect, null); 86 | } 87 | } 88 | 89 | @Override 90 | public boolean onTouchEvent(MotionEvent event) { 91 | // animate color to force bitmap uploads 92 | return super.onTouchEvent(event); 93 | } 94 | } 95 | 96 | @Override 97 | protected void onCreate(Bundle savedInstanceState) { 98 | super.onCreate(savedInstanceState); 99 | setContentView(R.layout.activity_bitmap_upload); 100 | 101 | final View uploadRoot = findViewById(R.id.upload_root); 102 | uploadRoot.setKeepScreenOn(true); 103 | uploadRoot.setOnTouchListener(new View.OnTouchListener() { 104 | @Override 105 | public boolean onTouch(View view, MotionEvent motionEvent) { 106 | UploadView uploadView = (UploadView) findViewById(R.id.upload_view); 107 | ObjectAnimator colorValueAnimator = 108 | ObjectAnimator.ofInt(uploadView, "colorValue", 0, 255); 109 | colorValueAnimator.setRepeatMode(ValueAnimator.REVERSE); 110 | colorValueAnimator.setRepeatCount(100); 111 | colorValueAnimator.start(); 112 | 113 | // animate scene root to guarantee there's a minimum amount of GPU rendering work 114 | ObjectAnimator yAnimator = ObjectAnimator.ofFloat( 115 | view, "translationY", 0, 100); 116 | yAnimator.setRepeatMode(ValueAnimator.REVERSE); 117 | yAnimator.setRepeatCount(100); 118 | yAnimator.start(); 119 | 120 | return true; 121 | } 122 | }); 123 | 124 | final UploadView uploadView = (UploadView) findViewById(R.id.upload_view); 125 | final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 126 | final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 127 | 128 | String name = BenchmarkRegistry.getBenchmarkName(this, R.id.benchmark_bitmap_upload); 129 | 130 | mAutomator = new Automator(name, runId, iteration, getWindow(), 131 | new Automator.AutomateCallback() { 132 | @Override 133 | public void onPostAutomate() { 134 | Intent result = new Intent(); 135 | setResult(RESULT_OK, result); 136 | finish(); 137 | } 138 | 139 | @Override 140 | public void onAutomate() { 141 | int[] coordinates = new int[2]; 142 | uploadRoot.getLocationOnScreen(coordinates); 143 | 144 | int x = coordinates[0]; 145 | int y = coordinates[1]; 146 | 147 | float width = uploadRoot.getWidth(); 148 | float height = uploadRoot.getHeight(); 149 | 150 | float middleX = (x + width) / 5; 151 | float middleY = (y + height) / 5; 152 | 153 | addInteraction(Interaction.newTap(middleX, middleY)); 154 | } 155 | }); 156 | 157 | mAutomator.start(); 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/EditTextInputActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.content.Intent; 20 | import android.os.Bundle; 21 | import androidx.appcompat.app.ActionBar; 22 | import androidx.appcompat.app.AppCompatActivity; 23 | import android.view.KeyEvent; 24 | import android.widget.EditText; 25 | 26 | import com.android.benchmark.R; 27 | import com.android.benchmark.ui.automation.Automator; 28 | import com.android.benchmark.ui.automation.Interaction; 29 | 30 | public class EditTextInputActivity extends AppCompatActivity { 31 | 32 | private Automator mAutomator; 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | final EditText editText = new EditText(this); 37 | final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 38 | final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 39 | 40 | editText.setWidth(400); 41 | editText.setHeight(200); 42 | setContentView(editText); 43 | 44 | String testName = getString(R.string.edit_text_input_name); 45 | 46 | ActionBar actionBar = getSupportActionBar(); 47 | if (actionBar != null) { 48 | actionBar.setTitle(testName); 49 | } 50 | 51 | mAutomator = new Automator(testName, runId, iteration, getWindow(), 52 | new Automator.AutomateCallback() { 53 | @Override 54 | public void onPostAutomate() { 55 | Intent result = new Intent(); 56 | setResult(RESULT_OK, result); 57 | finish(); 58 | } 59 | 60 | @Override 61 | public void onAutomate() { 62 | 63 | int[] coordinates = new int[2]; 64 | editText.getLocationOnScreen(coordinates); 65 | 66 | int x = coordinates[0]; 67 | int y = coordinates[1]; 68 | 69 | float width = editText.getWidth(); 70 | float height = editText.getHeight(); 71 | 72 | float middleX = (x + width) / 2; 73 | float middleY = (y + height) / 2; 74 | 75 | Interaction tap = Interaction.newTap(middleX, middleY); 76 | addInteraction(tap); 77 | 78 | int[] alphabet = { 79 | KeyEvent.KEYCODE_A, 80 | KeyEvent.KEYCODE_B, 81 | KeyEvent.KEYCODE_C, 82 | KeyEvent.KEYCODE_D, 83 | KeyEvent.KEYCODE_E, 84 | KeyEvent.KEYCODE_F, 85 | KeyEvent.KEYCODE_G, 86 | KeyEvent.KEYCODE_H, 87 | KeyEvent.KEYCODE_I, 88 | KeyEvent.KEYCODE_J, 89 | KeyEvent.KEYCODE_K, 90 | KeyEvent.KEYCODE_L, 91 | KeyEvent.KEYCODE_M, 92 | KeyEvent.KEYCODE_N, 93 | KeyEvent.KEYCODE_O, 94 | KeyEvent.KEYCODE_P, 95 | KeyEvent.KEYCODE_Q, 96 | KeyEvent.KEYCODE_R, 97 | KeyEvent.KEYCODE_S, 98 | KeyEvent.KEYCODE_T, 99 | KeyEvent.KEYCODE_U, 100 | KeyEvent.KEYCODE_V, 101 | KeyEvent.KEYCODE_W, 102 | KeyEvent.KEYCODE_X, 103 | KeyEvent.KEYCODE_Y, 104 | KeyEvent.KEYCODE_Z, 105 | KeyEvent.KEYCODE_SPACE 106 | }; 107 | Interaction typeAlphabet = Interaction.newKeyInput(new int[] { 108 | KeyEvent.KEYCODE_A, 109 | KeyEvent.KEYCODE_B, 110 | KeyEvent.KEYCODE_C, 111 | KeyEvent.KEYCODE_D, 112 | KeyEvent.KEYCODE_E, 113 | KeyEvent.KEYCODE_F, 114 | KeyEvent.KEYCODE_G, 115 | KeyEvent.KEYCODE_H, 116 | KeyEvent.KEYCODE_I, 117 | KeyEvent.KEYCODE_J, 118 | KeyEvent.KEYCODE_K, 119 | KeyEvent.KEYCODE_L, 120 | KeyEvent.KEYCODE_M, 121 | KeyEvent.KEYCODE_N, 122 | KeyEvent.KEYCODE_O, 123 | KeyEvent.KEYCODE_P, 124 | KeyEvent.KEYCODE_Q, 125 | KeyEvent.KEYCODE_R, 126 | KeyEvent.KEYCODE_S, 127 | KeyEvent.KEYCODE_T, 128 | KeyEvent.KEYCODE_U, 129 | KeyEvent.KEYCODE_V, 130 | KeyEvent.KEYCODE_W, 131 | KeyEvent.KEYCODE_X, 132 | KeyEvent.KEYCODE_Y, 133 | KeyEvent.KEYCODE_Z, 134 | KeyEvent.KEYCODE_SPACE, 135 | }); 136 | 137 | for (int i = 0; i < 5; i++) { 138 | addInteraction(typeAlphabet); 139 | } 140 | } 141 | }); 142 | mAutomator.start(); 143 | } 144 | 145 | @Override 146 | protected void onPause() { 147 | super.onPause(); 148 | if (mAutomator != null) { 149 | mAutomator.cancel(); 150 | mAutomator = null; 151 | } 152 | } 153 | 154 | private String getRunFilename() { 155 | StringBuilder builder = new StringBuilder(); 156 | builder.append(getClass().getSimpleName()); 157 | builder.append(System.currentTimeMillis()); 158 | return builder.toString(); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/FullScreenOverdrawActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.animation.ObjectAnimator; 20 | import android.animation.ValueAnimator; 21 | import android.content.Context; 22 | import android.content.Intent; 23 | import android.graphics.Canvas; 24 | import android.graphics.Color; 25 | import android.graphics.Paint; 26 | import androidx.appcompat.app.AppCompatActivity; 27 | import android.os.Bundle; 28 | import android.view.MotionEvent; 29 | import android.view.View; 30 | 31 | import com.android.benchmark.R; 32 | import com.android.benchmark.registry.BenchmarkRegistry; 33 | import com.android.benchmark.ui.automation.Automator; 34 | import com.android.benchmark.ui.automation.Interaction; 35 | 36 | public class FullScreenOverdrawActivity extends AppCompatActivity { 37 | 38 | private Automator mAutomator; 39 | 40 | private class OverdrawView extends View { 41 | Paint paint = new Paint(); 42 | int mColorValue = 0; 43 | 44 | public OverdrawView(Context context) { 45 | super(context); 46 | } 47 | 48 | @SuppressWarnings("unused") 49 | public void setColorValue(int colorValue) { 50 | mColorValue = colorValue; 51 | invalidate(); 52 | } 53 | 54 | @Override 55 | public boolean onTouchEvent(MotionEvent event) { 56 | ObjectAnimator objectAnimator = ObjectAnimator.ofInt(this, "colorValue", 0, 255); 57 | objectAnimator.setRepeatMode(ValueAnimator.REVERSE); 58 | objectAnimator.setRepeatCount(100); 59 | objectAnimator.start(); 60 | return super.onTouchEvent(event); 61 | } 62 | 63 | @Override 64 | protected void onDraw(Canvas canvas) { 65 | paint.setColor(Color.rgb(mColorValue, 255 - mColorValue, 255)); 66 | 67 | for (int i = 0; i < 10; i++) { 68 | canvas.drawRect(0, 0, getWidth(), getHeight(), paint); 69 | } 70 | } 71 | } 72 | 73 | @Override 74 | protected void onCreate(Bundle savedInstanceState) { 75 | super.onCreate(savedInstanceState); 76 | 77 | final OverdrawView overdrawView = new OverdrawView(this); 78 | overdrawView.setKeepScreenOn(true); 79 | setContentView(overdrawView); 80 | 81 | final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 82 | final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 83 | 84 | String name = BenchmarkRegistry.getBenchmarkName(this, R.id.benchmark_overdraw); 85 | 86 | mAutomator = new Automator(name, runId, iteration, getWindow(), 87 | new Automator.AutomateCallback() { 88 | @Override 89 | public void onPostAutomate() { 90 | Intent result = new Intent(); 91 | setResult(RESULT_OK, result); 92 | finish(); 93 | } 94 | 95 | @Override 96 | public void onAutomate() { 97 | int[] coordinates = new int[2]; 98 | overdrawView.getLocationOnScreen(coordinates); 99 | 100 | int x = coordinates[0]; 101 | int y = coordinates[1]; 102 | 103 | float width = overdrawView.getWidth(); 104 | float height = overdrawView.getHeight(); 105 | 106 | float middleX = (x + width) / 5; 107 | float middleY = (y + height) / 5; 108 | 109 | addInteraction(Interaction.newTap(middleX, middleY)); 110 | } 111 | }); 112 | 113 | mAutomator.start(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/ImageListViewScrollActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.graphics.Bitmap; 20 | import android.os.AsyncTask; 21 | import android.view.LayoutInflater; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | import android.widget.BaseAdapter; 25 | import android.widget.ImageView; 26 | import android.widget.ListAdapter; 27 | import android.widget.TextView; 28 | 29 | import com.android.benchmark.R; 30 | 31 | import java.lang.ref.WeakReference; 32 | import java.util.HashMap; 33 | 34 | public class ImageListViewScrollActivity extends ListViewScrollActivity { 35 | 36 | private static final int LIST_SIZE = 100; 37 | 38 | private static final int[] IMG_RES_ID = new int[]{ 39 | R.drawable.img1, 40 | R.drawable.img2, 41 | R.drawable.img3, 42 | R.drawable.img4, 43 | R.drawable.img1, 44 | R.drawable.img2, 45 | R.drawable.img3, 46 | R.drawable.img4, 47 | R.drawable.img1, 48 | R.drawable.img2, 49 | R.drawable.img3, 50 | R.drawable.img4, 51 | R.drawable.img1, 52 | R.drawable.img2, 53 | R.drawable.img3, 54 | R.drawable.img4, 55 | }; 56 | 57 | private static Bitmap[] mBitmapCache = new Bitmap[IMG_RES_ID.length]; 58 | 59 | private static final String[] WORDS = Utils.buildStringList(LIST_SIZE); 60 | 61 | private HashMap mInFlight = new HashMap<>(); 62 | 63 | @Override 64 | protected ListAdapter createListAdapter() { 65 | return new ImageListAdapter(); 66 | } 67 | 68 | @Override 69 | protected String getName() { 70 | return getString(R.string.image_list_view_scroll_name); 71 | } 72 | 73 | class BitmapWorkerTask extends AsyncTask { 74 | private final WeakReference imageViewReference; 75 | private int data = 0; 76 | private int cacheIdx = 0; 77 | volatile boolean cancelled = false; 78 | 79 | public BitmapWorkerTask(ImageView imageView, int cacheIdx) { 80 | // Use a WeakReference to ensure the ImageView can be garbage collected 81 | imageViewReference = new WeakReference<>(imageView); 82 | this.cacheIdx = cacheIdx; 83 | } 84 | 85 | // Decode image in background. 86 | @Override 87 | protected Bitmap doInBackground(Integer... params) { 88 | data = params[0]; 89 | return Utils.decodeSampledBitmapFromResource(getResources(), data, 100, 100); 90 | } 91 | 92 | // Once complete, see if ImageView is still around and set bitmap. 93 | @Override 94 | protected void onPostExecute(Bitmap bitmap) { 95 | if (bitmap != null) { 96 | final ImageView imageView = imageViewReference.get(); 97 | if (imageView != null) { 98 | if (!cancelled) { 99 | imageView.setImageBitmap(bitmap); 100 | } 101 | mBitmapCache[cacheIdx] = bitmap; 102 | } 103 | } 104 | } 105 | } 106 | 107 | @Override 108 | protected void onPause() { 109 | super.onPause(); 110 | for (int i = 0; i < mBitmapCache.length; i++) { 111 | mBitmapCache[i] = null; 112 | } 113 | } 114 | 115 | class ImageListAdapter extends BaseAdapter { 116 | 117 | @Override 118 | public int getCount() { 119 | return LIST_SIZE; 120 | } 121 | 122 | @Override 123 | public Object getItem(int postition) { 124 | return null; 125 | } 126 | 127 | @Override 128 | public long getItemId(int postition) { 129 | return postition; 130 | } 131 | 132 | @Override 133 | public View getView(int position, View convertView, ViewGroup parent) { 134 | if (convertView == null) { 135 | convertView = LayoutInflater.from(getBaseContext()) 136 | .inflate(R.layout.image_scroll_list_item, parent, false); 137 | } 138 | 139 | ImageView imageView = (ImageView) convertView.findViewById(R.id.image_scroll_image); 140 | BitmapWorkerTask inFlight = mInFlight.get(convertView); 141 | if (inFlight != null) { 142 | inFlight.cancelled = true; 143 | mInFlight.remove(convertView); 144 | } 145 | 146 | int cacheIdx = position % IMG_RES_ID.length; 147 | Bitmap bitmap = mBitmapCache[(cacheIdx)]; 148 | if (bitmap == null) { 149 | BitmapWorkerTask bitmapWorkerTask = new BitmapWorkerTask(imageView, cacheIdx); 150 | bitmapWorkerTask.execute(IMG_RES_ID[(cacheIdx)]); 151 | mInFlight.put(convertView, bitmapWorkerTask); 152 | } 153 | 154 | imageView.setImageBitmap(bitmap); 155 | 156 | TextView textView = (TextView) convertView.findViewById(R.id.image_scroll_text); 157 | textView.setText(WORDS[position]); 158 | 159 | return convertView; 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/ListActivityBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.app.ActionBar; 20 | import android.os.Bundle; 21 | import androidx.fragment.app.FragmentManager; 22 | import androidx.fragment.app.ListFragment; 23 | import androidx.appcompat.app.AppCompatActivity; 24 | import android.view.Window; 25 | import android.widget.ListAdapter; 26 | 27 | import com.android.benchmark.R; 28 | 29 | /** 30 | * Simple list activity base class 31 | */ 32 | public abstract class ListActivityBase extends AppCompatActivity { 33 | 34 | @Override 35 | public void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_list_fragment); 38 | 39 | ActionBar actionBar = getActionBar(); 40 | if (actionBar != null) { 41 | actionBar.setTitle(getName()); 42 | } 43 | 44 | if (findViewById(R.id.list_fragment_container) != null) { 45 | FragmentManager fm = getSupportFragmentManager(); 46 | ListFragment listView = new ListFragment(); 47 | listView.setListAdapter(createListAdapter()); 48 | fm.beginTransaction().add(R.id.list_fragment_container, listView).commit(); 49 | } 50 | } 51 | 52 | protected abstract ListAdapter createListAdapter(); 53 | protected abstract String getName(); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/ListViewScrollActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.content.Intent; 20 | import android.os.Bundle; 21 | import androidx.appcompat.app.ActionBar; 22 | import android.view.FrameMetrics; 23 | import android.view.MotionEvent; 24 | import android.widget.ArrayAdapter; 25 | import android.widget.FrameLayout; 26 | import android.widget.ListAdapter; 27 | 28 | import com.android.benchmark.R; 29 | import com.android.benchmark.ui.automation.Automator; 30 | import com.android.benchmark.ui.automation.Interaction; 31 | 32 | import java.io.File; 33 | import java.util.List; 34 | 35 | public class ListViewScrollActivity extends ListActivityBase { 36 | 37 | private static final int LIST_SIZE = 400; 38 | private static final int INTERACTION_COUNT = 4; 39 | 40 | private Automator mAutomator; 41 | 42 | @Override 43 | public void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 46 | final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 47 | 48 | ActionBar actionBar = getSupportActionBar(); 49 | if (actionBar != null) { 50 | actionBar.setTitle(getTitle()); 51 | } 52 | 53 | mAutomator = new Automator(getName(), runId, iteration, getWindow(), 54 | new Automator.AutomateCallback() { 55 | @Override 56 | public void onPostAutomate() { 57 | Intent result = new Intent(); 58 | setResult(RESULT_OK, result); 59 | finish(); 60 | } 61 | 62 | @Override 63 | public void onPostInteraction(List metrics) {} 64 | 65 | @Override 66 | public void onAutomate() { 67 | FrameLayout v = (FrameLayout) findViewById(R.id.list_fragment_container); 68 | 69 | int[] coordinates = new int[2]; 70 | v.getLocationOnScreen(coordinates); 71 | 72 | int x = coordinates[0]; 73 | int y = coordinates[1]; 74 | 75 | float width = v.getWidth(); 76 | float height = v.getHeight(); 77 | 78 | float middleX = (x + width) / 5; 79 | float middleY = (y + height) / 5; 80 | 81 | Interaction flingUp = Interaction.newFlingUp(middleX, middleY); 82 | Interaction flingDown = Interaction.newFlingDown(middleX, middleY); 83 | 84 | for (int i = 0; i < INTERACTION_COUNT; i++) { 85 | addInteraction(flingUp); 86 | addInteraction(flingDown); 87 | } 88 | } 89 | }); 90 | 91 | mAutomator.start(); 92 | } 93 | 94 | @Override 95 | protected void onPause() { 96 | super.onPause(); 97 | if (mAutomator != null) { 98 | mAutomator.cancel(); 99 | mAutomator = null; 100 | } 101 | } 102 | 103 | @Override 104 | protected ListAdapter createListAdapter() { 105 | return new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, 106 | Utils.buildStringList(LIST_SIZE)); 107 | } 108 | 109 | @Override 110 | protected String getName() { 111 | return getString(R.string.list_view_scroll_name); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/ShadowGridActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | package com.android.benchmark.ui; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import androidx.fragment.app.FragmentManager; 21 | import androidx.fragment.app.ListFragment; 22 | import androidx.appcompat.app.AppCompatActivity; 23 | import android.view.View; 24 | import android.widget.ArrayAdapter; 25 | import android.widget.ListView; 26 | 27 | import com.android.benchmark.R; 28 | import com.android.benchmark.ui.automation.Automator; 29 | import com.android.benchmark.ui.automation.Interaction; 30 | 31 | public class ShadowGridActivity extends AppCompatActivity { 32 | private Automator mAutomator; 33 | public static class MyListFragment extends ListFragment { 34 | @Override 35 | public void onViewCreated(View view, Bundle savedInstanceState) { 36 | super.onViewCreated(view, savedInstanceState); 37 | getListView().setDivider(null); 38 | } 39 | } 40 | 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 45 | final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 46 | 47 | FragmentManager fm = getSupportFragmentManager(); 48 | if (fm.findFragmentById(android.R.id.content) == null) { 49 | ListFragment listFragment = new MyListFragment(); 50 | 51 | listFragment.setListAdapter(new ArrayAdapter<>(this, 52 | R.layout.card_row, R.id.card_text, Utils.buildStringList(200))); 53 | fm.beginTransaction().add(android.R.id.content, listFragment).commit(); 54 | 55 | String testName = getString(R.string.shadow_grid_name); 56 | 57 | mAutomator = new Automator(testName, runId, iteration, getWindow(), 58 | new Automator.AutomateCallback() { 59 | @Override 60 | public void onPostAutomate() { 61 | Intent result = new Intent(); 62 | setResult(RESULT_OK, result); 63 | finish(); 64 | } 65 | 66 | @Override 67 | public void onAutomate() { 68 | ListView v = (ListView) findViewById(android.R.id.list); 69 | 70 | int[] coordinates = new int[2]; 71 | v.getLocationOnScreen(coordinates); 72 | 73 | int x = coordinates[0]; 74 | int y = coordinates[1]; 75 | 76 | float width = v.getWidth(); 77 | float height = v.getHeight(); 78 | 79 | float middleX = (x + width) / 2; 80 | float middleY = (y + height) / 2; 81 | 82 | Interaction flingUp = Interaction.newFlingUp(middleX, middleY); 83 | Interaction flingDown = Interaction.newFlingDown(middleX, middleY); 84 | 85 | addInteraction(flingUp); 86 | addInteraction(flingDown); 87 | addInteraction(flingUp); 88 | addInteraction(flingDown); 89 | addInteraction(flingUp); 90 | addInteraction(flingDown); 91 | addInteraction(flingUp); 92 | addInteraction(flingDown); 93 | } 94 | }); 95 | mAutomator.start(); 96 | } 97 | } 98 | 99 | @Override 100 | protected void onPause() { 101 | super.onPause(); 102 | if (mAutomator != null) { 103 | mAutomator.cancel(); 104 | mAutomator = null; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/TextScrollActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.content.Intent; 20 | import android.os.Bundle; 21 | import android.widget.ArrayAdapter; 22 | import android.widget.ListAdapter; 23 | import android.widget.ListView; 24 | 25 | import com.android.benchmark.registry.BenchmarkRegistry; 26 | import com.android.benchmark.ui.automation.Automator; 27 | import com.android.benchmark.ui.automation.Interaction; 28 | 29 | import java.io.File; 30 | 31 | public class TextScrollActivity extends ListActivityBase { 32 | 33 | public static final String EXTRA_HIT_RATE = ".TextScrollActivity.EXTRA_HIT_RATE"; 34 | 35 | private static final int PARAGRAPH_COUNT = 200; 36 | 37 | private int mHitPercentage = 100; 38 | private Automator mAutomator; 39 | private String mName; 40 | 41 | @Override 42 | public void onCreate(Bundle savedInstanceState) { 43 | mHitPercentage = getIntent().getIntExtra(EXTRA_HIT_RATE, 44 | mHitPercentage); 45 | super.onCreate(savedInstanceState); 46 | final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0); 47 | final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1); 48 | final int id = getIntent().getIntExtra(BenchmarkRegistry.EXTRA_ID, -1); 49 | 50 | if (id == -1) { 51 | finish(); 52 | return; 53 | } 54 | 55 | mName = BenchmarkRegistry.getBenchmarkName(this, id); 56 | 57 | mAutomator = new Automator(getName(), runId, iteration, getWindow(), 58 | new Automator.AutomateCallback() { 59 | @Override 60 | public void onPostAutomate() { 61 | Intent result = new Intent(); 62 | setResult(RESULT_OK, result); 63 | finish(); 64 | } 65 | 66 | @Override 67 | public void onAutomate() { 68 | ListView v = (ListView) findViewById(android.R.id.list); 69 | 70 | int[] coordinates = new int[2]; 71 | v.getLocationOnScreen(coordinates); 72 | 73 | int x = coordinates[0]; 74 | int y = coordinates[1]; 75 | 76 | float width = v.getWidth(); 77 | float height = v.getHeight(); 78 | 79 | float middleX = (x + width) / 2; 80 | float middleY = (y + height) / 2; 81 | 82 | Interaction flingUp = Interaction.newFlingUp(middleX, middleY); 83 | Interaction flingDown = Interaction.newFlingDown(middleX, middleY); 84 | 85 | addInteraction(flingUp); 86 | addInteraction(flingDown); 87 | addInteraction(flingUp); 88 | addInteraction(flingDown); 89 | addInteraction(flingUp); 90 | addInteraction(flingDown); 91 | addInteraction(flingUp); 92 | addInteraction(flingDown); 93 | } 94 | }); 95 | 96 | mAutomator.start(); 97 | } 98 | 99 | @Override 100 | protected void onPause() { 101 | super.onPause(); 102 | if (mAutomator != null) { 103 | mAutomator.cancel(); 104 | mAutomator = null; 105 | } 106 | } 107 | 108 | @Override 109 | protected ListAdapter createListAdapter() { 110 | return new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, 111 | Utils.buildParagraphListWithHitPercentage(PARAGRAPH_COUNT, 80)); 112 | } 113 | 114 | @Override 115 | protected String getName() { 116 | return mName; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.ui; 18 | 19 | import android.content.res.Resources; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | 23 | import java.util.Random; 24 | 25 | public class Utils { 26 | 27 | private static final int RANDOM_WORD_LENGTH = 10; 28 | 29 | public static String getRandomWord(Random random, int length) { 30 | StringBuilder builder = new StringBuilder(); 31 | for (int i = 0; i < length; i++) { 32 | char base = random.nextBoolean() ? 'A' : 'a'; 33 | char nextChar = (char)(random.nextInt(26) + base); 34 | builder.append(nextChar); 35 | } 36 | return builder.toString(); 37 | } 38 | 39 | public static String[] buildStringList(int count) { 40 | Random random = new Random(0); 41 | String[] result = new String[count]; 42 | for (int i = 0; i < count; i++) { 43 | result[i] = getRandomWord(random, RANDOM_WORD_LENGTH); 44 | } 45 | 46 | return result; 47 | } 48 | 49 | // a small number of strings reused frequently, expected to hit 50 | // in the word-granularity text layout cache 51 | static final String[] CACHE_HIT_STRINGS = new String[] { 52 | "a", 53 | "small", 54 | "number", 55 | "of", 56 | "strings", 57 | "reused", 58 | "frequently" 59 | }; 60 | 61 | private static final int WORDS_IN_PARAGRAPH = 150; 62 | 63 | // misses are fairly long 'words' to ensure they miss 64 | private static final int PARAGRAPH_MISS_MIN_LENGTH = 4; 65 | private static final int PARAGRAPH_MISS_MAX_LENGTH = 9; 66 | 67 | static String[] buildParagraphListWithHitPercentage(int paragraphCount, int hitPercentage) { 68 | if (hitPercentage < 0 || hitPercentage > 100) throw new IllegalArgumentException(); 69 | 70 | String[] strings = new String[paragraphCount]; 71 | Random random = new Random(0); 72 | for (int i = 0; i < strings.length; i++) { 73 | StringBuilder result = new StringBuilder(); 74 | for (int word = 0; word < WORDS_IN_PARAGRAPH; word++) { 75 | if (word != 0) { 76 | result.append(" "); 77 | } 78 | if (random.nextInt(100) < hitPercentage) { 79 | // add a common word, which is very likely to hit in the cache 80 | result.append(CACHE_HIT_STRINGS[random.nextInt(CACHE_HIT_STRINGS.length)]); 81 | } else { 82 | // construct a random word, which will *most likely* miss 83 | int length = PARAGRAPH_MISS_MIN_LENGTH; 84 | length += random.nextInt(PARAGRAPH_MISS_MAX_LENGTH - PARAGRAPH_MISS_MIN_LENGTH); 85 | 86 | result.append(getRandomWord(random, length)); 87 | } 88 | } 89 | strings[i] = result.toString(); 90 | } 91 | 92 | return strings; 93 | } 94 | 95 | 96 | public static int calculateInSampleSize( 97 | BitmapFactory.Options options, int reqWidth, int reqHeight) { 98 | // Raw height and width of image 99 | final int height = options.outHeight; 100 | final int width = options.outWidth; 101 | int inSampleSize = 1; 102 | 103 | if (height > reqHeight || width > reqWidth) { 104 | 105 | final int halfHeight = height / 2; 106 | final int halfWidth = width / 2; 107 | 108 | // Calculate the largest inSampleSize value that is a power of 2 and keeps both 109 | // height and width larger than the requested height and width. 110 | while ((halfHeight / inSampleSize) > reqHeight 111 | && (halfWidth / inSampleSize) > reqWidth) { 112 | inSampleSize *= 2; 113 | } 114 | } 115 | 116 | return inSampleSize; 117 | } 118 | 119 | public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, 120 | int reqWidth, int reqHeight) { 121 | 122 | // First decode with inJustDecodeBounds=true to check dimensions 123 | final BitmapFactory.Options options = new BitmapFactory.Options(); 124 | options.inJustDecodeBounds = true; 125 | BitmapFactory.decodeResource(res, resId, options); 126 | 127 | // Calculate inSampleSize 128 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 129 | 130 | // Decode bitmap with inSampleSize set 131 | options.inJustDecodeBounds = false; 132 | return BitmapFactory.decodeResource(res, resId, options); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/automation/CollectorThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark.ui.automation; 18 | 19 | import android.annotation.TargetApi; 20 | import android.os.Handler; 21 | import android.os.HandlerThread; 22 | import android.os.Message; 23 | import android.os.SystemClock; 24 | import android.view.FrameMetrics; 25 | import android.view.Window; 26 | 27 | import java.lang.ref.WeakReference; 28 | import java.util.LinkedList; 29 | import java.util.List; 30 | 31 | /** 32 | * 33 | */ 34 | final class CollectorThread extends HandlerThread { 35 | private FrameStatsCollector mCollector; 36 | private Window mAttachedWindow; 37 | private List mFrameTimingStats; 38 | private long mLastFrameTime; 39 | private WatchdogHandler mWatchdog; 40 | private WeakReference mListener; 41 | 42 | private volatile boolean mCollecting; 43 | 44 | 45 | interface CollectorListener { 46 | void onCollectorThreadReady(); 47 | void onPostInteraction(List stats); 48 | } 49 | 50 | private final class WatchdogHandler extends Handler { 51 | private static final long SCHEDULE_INTERVAL_MILLIS = 20 * Automator.FRAME_PERIOD_MILLIS; 52 | 53 | private static final int MSG_SCHEDULE = 0; 54 | 55 | @Override 56 | public void handleMessage(Message msg) { 57 | if (!mCollecting) { 58 | return; 59 | } 60 | 61 | long currentTime = SystemClock.uptimeMillis(); 62 | if (mLastFrameTime + SCHEDULE_INTERVAL_MILLIS <= currentTime) { 63 | // haven't seen a frame in a while, interaction is probably done 64 | mCollecting = false; 65 | CollectorListener listener = mListener.get(); 66 | if (listener != null) { 67 | listener.onPostInteraction(mFrameTimingStats); 68 | } 69 | } else { 70 | schedule(); 71 | } 72 | } 73 | 74 | public void schedule() { 75 | sendMessageDelayed(obtainMessage(MSG_SCHEDULE), SCHEDULE_INTERVAL_MILLIS); 76 | } 77 | 78 | public void deschedule() { 79 | removeMessages(MSG_SCHEDULE); 80 | } 81 | } 82 | 83 | static boolean tripleBuffered = false; 84 | static int janks = 0; 85 | static int total = 0; 86 | @TargetApi(24) 87 | private class FrameStatsCollector implements Window.OnFrameMetricsAvailableListener { 88 | @Override 89 | public void onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics, int dropCount) { 90 | if (!mCollecting) { 91 | return; 92 | } 93 | mFrameTimingStats.add(new FrameMetrics(frameMetrics)); 94 | mLastFrameTime = SystemClock.uptimeMillis(); 95 | } 96 | } 97 | 98 | public CollectorThread(CollectorListener listener) { 99 | super("FrameStatsCollectorThread"); 100 | mFrameTimingStats = new LinkedList<>(); 101 | mListener = new WeakReference<>(listener); 102 | } 103 | 104 | @TargetApi(24) 105 | public void attachToWindow(Window window) { 106 | if (mAttachedWindow != null) { 107 | mAttachedWindow.removeOnFrameMetricsAvailableListener(mCollector); 108 | } 109 | 110 | mAttachedWindow = window; 111 | window.addOnFrameMetricsAvailableListener(mCollector, new Handler(getLooper())); 112 | } 113 | 114 | @TargetApi(24) 115 | public synchronized void detachFromWindow() { 116 | if (mAttachedWindow != null) { 117 | mAttachedWindow.removeOnFrameMetricsAvailableListener(mCollector); 118 | } 119 | 120 | mAttachedWindow = null; 121 | } 122 | 123 | @TargetApi(24) 124 | @Override 125 | protected void onLooperPrepared() { 126 | super.onLooperPrepared(); 127 | mCollector = new FrameStatsCollector(); 128 | mWatchdog = new WatchdogHandler(); 129 | 130 | CollectorListener listener = mListener.get(); 131 | if (listener != null) { 132 | listener.onCollectorThreadReady(); 133 | } 134 | } 135 | 136 | public boolean quitCollector() { 137 | stopCollecting(); 138 | detachFromWindow(); 139 | System.out.println("Jank Percentage: " + (100 * janks/ (double) total) + "%"); 140 | tripleBuffered = false; 141 | total = 0; 142 | janks = 0; 143 | return quit(); 144 | } 145 | 146 | void stopCollecting() { 147 | if (!mCollecting) { 148 | return; 149 | } 150 | 151 | mCollecting = false; 152 | mWatchdog.deschedule(); 153 | 154 | 155 | } 156 | 157 | public void markInteractionStart() { 158 | mLastFrameTime = 0; 159 | mFrameTimingStats.clear(); 160 | mCollecting = true; 161 | 162 | mWatchdog.schedule(); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/automation/FrameTimingStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.ui.automation; 18 | 19 | import androidx.annotation.IntDef; 20 | 21 | import java.io.DataInput; 22 | import java.io.DataInputStream; 23 | import java.io.IOException; 24 | import java.util.Arrays; 25 | 26 | public class FrameTimingStats { 27 | @IntDef ({ 28 | Index.FLAGS, 29 | Index.INTENDED_VSYNC, 30 | Index.VSYNC, 31 | Index.OLDEST_INPUT_EVENT, 32 | Index.NEWEST_INPUT_EVENT, 33 | Index.HANDLE_INPUT_START, 34 | Index.ANIMATION_START, 35 | Index.PERFORM_TRAVERSALS_START, 36 | Index.DRAW_START, 37 | Index.SYNC_QUEUED, 38 | Index.SYNC_START, 39 | Index.ISSUE_DRAW_COMMANDS_START, 40 | Index.SWAP_BUFFERS, 41 | Index.FRAME_COMPLETED, 42 | }) 43 | public @interface Index { 44 | int FLAGS = 0; 45 | int INTENDED_VSYNC = 1; 46 | int VSYNC = 2; 47 | int OLDEST_INPUT_EVENT = 3; 48 | int NEWEST_INPUT_EVENT = 4; 49 | int HANDLE_INPUT_START = 5; 50 | int ANIMATION_START = 6; 51 | int PERFORM_TRAVERSALS_START = 7; 52 | int DRAW_START = 8; 53 | int SYNC_QUEUED = 9; 54 | int SYNC_START = 10; 55 | int ISSUE_DRAW_COMMANDS_START = 11; 56 | int SWAP_BUFFERS = 12; 57 | int FRAME_COMPLETED = 13; 58 | 59 | int FRAME_STATS_COUNT = 14; // must always be last 60 | } 61 | 62 | private final long[] mStats; 63 | 64 | FrameTimingStats(long[] stats) { 65 | mStats = Arrays.copyOf(stats, Index.FRAME_STATS_COUNT); 66 | } 67 | 68 | public FrameTimingStats(DataInputStream inputStream) throws IOException { 69 | mStats = new long[Index.FRAME_STATS_COUNT]; 70 | update(inputStream); 71 | } 72 | 73 | public void update(DataInputStream inputStream) throws IOException { 74 | for (int i = 0; i < mStats.length; i++) { 75 | mStats[i] = inputStream.readLong(); 76 | } 77 | } 78 | 79 | public long get(@Index int index) { 80 | return mStats[index]; 81 | } 82 | 83 | public long[] data() { 84 | return mStats; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/ui/automation/Interaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and limitations under the 13 | * License. 14 | * 15 | */ 16 | 17 | package com.android.benchmark.ui.automation; 18 | 19 | import android.os.SystemClock; 20 | import androidx.annotation.IntDef; 21 | import android.view.MotionEvent; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * Encodes a UI interaction as a series of MotionEvents 28 | */ 29 | public class Interaction { 30 | private static final int STEP_COUNT = 20; 31 | // TODO: scale to device display density 32 | private static final int DEFAULT_FLING_SIZE_PX = 500; 33 | private static final int DEFAULT_FLING_DURATION_MS = 20; 34 | private static final int DEFAULT_TAP_DURATION_MS = 20; 35 | private List mEvents; 36 | 37 | // Interaction parameters 38 | private final float[] mXPositions; 39 | private final float[] mYPositions; 40 | private final long mDuration; 41 | private final int[] mKeyCodes; 42 | private final @Interaction.Type int mType; 43 | 44 | @IntDef({ 45 | Interaction.Type.TAP, 46 | Interaction.Type.FLING, 47 | Interaction.Type.PINCH, 48 | Interaction.Type.KEY_EVENT}) 49 | public @interface Type { 50 | int TAP = 0; 51 | int FLING = 1; 52 | int PINCH = 2; 53 | int KEY_EVENT = 3; 54 | } 55 | 56 | public static Interaction newFling(float startX, float startY, 57 | float endX, float endY, long duration) { 58 | return new Interaction(Interaction.Type.FLING, new float[]{startX, endX}, 59 | new float[]{startY, endY}, duration); 60 | } 61 | 62 | public static Interaction newFlingDown(float startX, float startY) { 63 | return new Interaction(Interaction.Type.FLING, 64 | new float[]{startX, startX}, 65 | new float[]{startY, startY + DEFAULT_FLING_SIZE_PX}, DEFAULT_FLING_DURATION_MS); 66 | } 67 | 68 | public static Interaction newFlingUp(float startX, float startY) { 69 | return new Interaction(Interaction.Type.FLING, 70 | new float[]{startX, startX}, new float[]{startY, startY - DEFAULT_FLING_SIZE_PX}, 71 | DEFAULT_FLING_DURATION_MS); 72 | } 73 | 74 | public static Interaction newTap(float startX, float startY) { 75 | return new Interaction(Interaction.Type.TAP, 76 | new float[]{startX, startX}, new float[]{startY, startY}, 77 | DEFAULT_FLING_DURATION_MS); 78 | } 79 | 80 | public static Interaction newKeyInput(int[] keyCodes) { 81 | return new Interaction(keyCodes); 82 | } 83 | 84 | public List getEvents() { 85 | switch (mType) { 86 | case Type.FLING: 87 | mEvents = createInterpolatedEventList(mXPositions, mYPositions, mDuration); 88 | break; 89 | case Type.PINCH: 90 | break; 91 | case Type.TAP: 92 | mEvents = createInterpolatedEventList(mXPositions, mYPositions, mDuration); 93 | break; 94 | } 95 | 96 | return mEvents; 97 | } 98 | 99 | public int getType() { 100 | return mType; 101 | } 102 | 103 | public int[] getKeyCodes() { 104 | return mKeyCodes; 105 | } 106 | 107 | private static List createInterpolatedEventList( 108 | float[] xPos, float[] yPos, long duration) { 109 | long startTime = SystemClock.uptimeMillis() + 100; 110 | List result = new ArrayList<>(); 111 | 112 | float startX = xPos[0]; 113 | float startY = yPos[0]; 114 | 115 | MotionEvent downEvent = MotionEvent.obtain( 116 | startTime, startTime, MotionEvent.ACTION_DOWN, startX, startY, 0); 117 | result.add(downEvent); 118 | 119 | for (int i = 1; i < xPos.length; i++) { 120 | float endX = xPos[i]; 121 | float endY = yPos[i]; 122 | float stepX = (endX - startX) / STEP_COUNT; 123 | float stepY = (endY - startY) / STEP_COUNT; 124 | float stepT = duration / STEP_COUNT; 125 | 126 | for (int j = 0; j < STEP_COUNT; j++) { 127 | long deltaT = Math.round(j * stepT); 128 | long deltaX = Math.round(j * stepX); 129 | long deltaY = Math.round(j * stepY); 130 | MotionEvent moveEvent = MotionEvent.obtain(startTime, startTime + deltaT, 131 | MotionEvent.ACTION_MOVE, startX + deltaX, startY + deltaY, 0); 132 | result.add(moveEvent); 133 | } 134 | 135 | startX = endX; 136 | startY = endY; 137 | } 138 | 139 | float lastX = xPos[xPos.length - 1]; 140 | float lastY = yPos[yPos.length - 1]; 141 | MotionEvent lastEvent = MotionEvent.obtain(startTime, startTime + duration, 142 | MotionEvent.ACTION_UP, lastX, lastY, 0); 143 | result.add(lastEvent); 144 | 145 | return result; 146 | } 147 | 148 | private Interaction(@Interaction.Type int type, 149 | float[] xPos, float[] yPos, long duration) { 150 | mType = type; 151 | mXPositions = xPos; 152 | mYPositions = yPos; 153 | mDuration = duration; 154 | mKeyCodes = null; 155 | } 156 | 157 | private Interaction(int[] codes) { 158 | mKeyCodes = codes; 159 | mType = Type.KEY_EVENT; 160 | mYPositions = null; 161 | mXPositions = null; 162 | mDuration = 0; 163 | } 164 | 165 | private Interaction(@Interaction.Type int type, 166 | List xPositions, List yPositions, long duration) { 167 | if (xPositions.size() != yPositions.size()) { 168 | throw new IllegalArgumentException("must have equal number of x and y positions"); 169 | } 170 | 171 | int current = 0; 172 | mXPositions = new float[xPositions.size()]; 173 | for (float p : xPositions) { 174 | mXPositions[current++] = p; 175 | } 176 | 177 | current = 0; 178 | mYPositions = new float[yPositions.size()]; 179 | for (float p : xPositions) { 180 | mXPositions[current++] = p; 181 | } 182 | 183 | mType = type; 184 | mDuration = duration; 185 | mKeyCodes = null; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/benchmark/utils/CatFile.java: -------------------------------------------------------------------------------- 1 | package com.android.benchmark.utils; 2 | 3 | import com.topjohnwu.superuser.Shell; 4 | import com.topjohnwu.superuser.io.SuFile; 5 | 6 | import java.io.File; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class CatFile { 11 | public static List read(String filePath) { 12 | List output = new ArrayList<>(); 13 | File myFile = SuFile.open(filePath); 14 | if (myFile.exists() && myFile.canRead()) { 15 | if (Shell.rootAccess()) { 16 | output = Shell.su("cat " + filePath).exec().getOut(); 17 | } else { 18 | output = Shell.sh("cat " + filePath).exec().getOut(); 19 | } 20 | } 21 | 22 | return output; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/jni/Android.bp.converted: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | cc_library_shared { 16 | name: "libnativebench", 17 | cflags: [ 18 | "-Wno-unused-parameter", 19 | "-Wno-unused-variable", 20 | ], 21 | srcs: [ 22 | "Bench.cpp", 23 | "WorkerPool.cpp", 24 | "test.cpp", 25 | ], 26 | host_ldlibs: ["-llog"], 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | APP_ABI := armeabi 16 | 17 | APP_MODULES := nativebench 18 | -------------------------------------------------------------------------------- /app/src/main/jni/Bench.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | #ifndef ANDROID_BENCH_H 18 | #define ANDROID_BENCH_H 19 | 20 | #include 21 | 22 | #include "WorkerPool.h" 23 | 24 | #include 25 | 26 | 27 | 28 | class Bench { 29 | public: 30 | Bench(); 31 | ~Bench(); 32 | 33 | struct GFlop { 34 | int kernelXSize; 35 | //int kernelYSize; 36 | int imageXSize; 37 | //int imageYSize; 38 | 39 | float *srcBuffer; 40 | float *kernelBuffer; 41 | float *dstBuffer; 42 | 43 | 44 | }; 45 | GFlop mGFlop; 46 | 47 | bool init(); 48 | 49 | bool runPowerManagementTest(uint64_t options); 50 | bool runCPUHeatSoak(uint64_t options); 51 | 52 | bool startMemTests(); 53 | void endMemTests(); 54 | float runMemoryBandwidthTest(uint64_t options); 55 | float runMemoryLatencyTest(uint64_t options); 56 | 57 | float runGFlopsTest(uint64_t options); 58 | 59 | void getData(float *data, size_t count) const; 60 | 61 | 62 | void finish(); 63 | 64 | void setPriority(int32_t p); 65 | void destroyWorkerThreadResources(); 66 | 67 | uint64_t getTimeNanos() const; 68 | uint64_t getTimeMillis() const; 69 | 70 | // Adds a work unit completed to the timeline and returns 71 | // true if the test is ongoing, false if time is up 72 | bool incTimeBucket() const; 73 | 74 | 75 | protected: 76 | WorkerPool mWorkers; 77 | 78 | bool mExit; 79 | bool mPaused; 80 | 81 | static void testWork(void *usr, uint32_t idx); 82 | 83 | private: 84 | uint8_t * volatile mMemSrc; 85 | uint8_t * volatile mMemDst; 86 | size_t mMemLoopCount; 87 | size_t mMemLatencyLastSize; 88 | 89 | 90 | float ** mIpKernel; 91 | float * volatile * mSrcBuf; 92 | float * volatile * mOutBuf; 93 | uint32_t * mTimeBucket; 94 | 95 | uint64_t mTimeStartNanos; 96 | uint64_t mTimeEndNanos; 97 | uint64_t mTimeBucketDivisor; 98 | uint32_t mTimeBuckets; 99 | 100 | uint64_t mTimeEndGroupNanos; 101 | 102 | bool initIP(); 103 | void GflopKernelC(); 104 | void GflopKernelC_y3(); 105 | 106 | bool allocateBuckets(size_t); 107 | 108 | 109 | }; 110 | 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /app/src/main/jni/WorkerPool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | #include "WorkerPool.h" 18 | //#include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | //static pthread_key_t gThreadTLSKey = 0; 26 | //static uint32_t gThreadTLSKeyCount = 0; 27 | //static pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER; 28 | 29 | 30 | WorkerPool::Signal::Signal() { 31 | mSet = true; 32 | } 33 | 34 | WorkerPool::Signal::~Signal() { 35 | pthread_mutex_destroy(&mMutex); 36 | pthread_cond_destroy(&mCondition); 37 | } 38 | 39 | bool WorkerPool::Signal::init() { 40 | int status = pthread_mutex_init(&mMutex, NULL); 41 | if (status) { 42 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool mutex init failure"); 43 | return false; 44 | } 45 | 46 | status = pthread_cond_init(&mCondition, NULL); 47 | if (status) { 48 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool condition init failure"); 49 | pthread_mutex_destroy(&mMutex); 50 | return false; 51 | } 52 | 53 | return true; 54 | } 55 | 56 | void WorkerPool::Signal::set() { 57 | int status; 58 | 59 | status = pthread_mutex_lock(&mMutex); 60 | if (status) { 61 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool: error %i locking for set condition.", status); 62 | return; 63 | } 64 | 65 | mSet = true; 66 | 67 | status = pthread_cond_signal(&mCondition); 68 | if (status) { 69 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool: error %i on set condition.", status); 70 | } 71 | 72 | status = pthread_mutex_unlock(&mMutex); 73 | if (status) { 74 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool: error %i unlocking for set condition.", status); 75 | } 76 | } 77 | 78 | bool WorkerPool::Signal::wait(uint64_t timeout) { 79 | int status; 80 | bool ret = false; 81 | 82 | status = pthread_mutex_lock(&mMutex); 83 | if (status) { 84 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool: error %i locking for condition.", status); 85 | return false; 86 | } 87 | 88 | if (!mSet) { 89 | if (!timeout) { 90 | status = pthread_cond_wait(&mCondition, &mMutex); 91 | } else { 92 | #if defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE) 93 | status = pthread_cond_timeout_np(&mCondition, &mMutex, timeout / 1000000); 94 | #else 95 | // This is safe it will just make things less reponsive 96 | status = pthread_cond_wait(&mCondition, &mMutex); 97 | #endif 98 | } 99 | } 100 | 101 | if (!status) { 102 | mSet = false; 103 | ret = true; 104 | } else { 105 | #ifndef RS_SERVER 106 | if (status != ETIMEDOUT) { 107 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool: error %i waiting for condition.", status); 108 | } 109 | #endif 110 | } 111 | 112 | status = pthread_mutex_unlock(&mMutex); 113 | if (status) { 114 | __android_log_print(ANDROID_LOG_INFO, "bench", "WorkerPool: error %i unlocking for condition.", status); 115 | } 116 | 117 | return ret; 118 | } 119 | 120 | 121 | 122 | WorkerPool::WorkerPool() { 123 | mExit = false; 124 | mRunningCount = 0; 125 | mLaunchCount = 0; 126 | mCount = 0; 127 | mThreadId = NULL; 128 | mNativeThreadId = NULL; 129 | mLaunchSignals = NULL; 130 | mLaunchCallback = NULL; 131 | 132 | 133 | } 134 | 135 | 136 | WorkerPool::~WorkerPool() { 137 | __android_log_print(ANDROID_LOG_INFO, "bench", "~wp"); 138 | mExit = true; 139 | mLaunchData = NULL; 140 | mLaunchCallback = NULL; 141 | mRunningCount = mCount; 142 | 143 | __sync_synchronize(); 144 | for (uint32_t ct = 0; ct < mCount; ct++) { 145 | mLaunchSignals[ct].set(); 146 | } 147 | void *res; 148 | for (uint32_t ct = 0; ct < mCount; ct++) { 149 | pthread_join(mThreadId[ct], &res); 150 | } 151 | //rsAssert(__sync_fetch_and_or(&mRunningCount, 0) == 0); 152 | free(mThreadId); 153 | free(mNativeThreadId); 154 | delete[] mLaunchSignals; 155 | } 156 | 157 | bool WorkerPool::init(int threadCount) { 158 | int cpu = sysconf(_SC_NPROCESSORS_CONF); 159 | if (threadCount > 0) { 160 | cpu = threadCount; 161 | } 162 | if (cpu < 1) { 163 | return false; 164 | } 165 | mCount = (uint32_t)cpu; 166 | 167 | __android_log_print(ANDROID_LOG_INFO, "Bench", "ThreadLaunch %i", mCount); 168 | 169 | mThreadId = (pthread_t *) calloc(mCount, sizeof(pthread_t)); 170 | mNativeThreadId = (pid_t *) calloc(mCount, sizeof(pid_t)); 171 | mLaunchSignals = new Signal[mCount]; 172 | mLaunchCallback = NULL; 173 | 174 | mCompleteSignal.init(); 175 | mRunningCount = mCount; 176 | mLaunchCount = 0; 177 | __sync_synchronize(); 178 | 179 | pthread_attr_t threadAttr; 180 | int status = pthread_attr_init(&threadAttr); 181 | if (status) { 182 | __android_log_print(ANDROID_LOG_INFO, "bench", "Failed to init thread attribute."); 183 | return false; 184 | } 185 | 186 | for (uint32_t ct=0; ct < mCount; ct++) { 187 | status = pthread_create(&mThreadId[ct], &threadAttr, helperThreadProc, this); 188 | if (status) { 189 | mCount = ct; 190 | __android_log_print(ANDROID_LOG_INFO, "bench", "Created fewer than expected number of threads."); 191 | return false; 192 | } 193 | } 194 | while (__sync_fetch_and_or(&mRunningCount, 0) != 0) { 195 | usleep(100); 196 | } 197 | 198 | pthread_attr_destroy(&threadAttr); 199 | return true; 200 | } 201 | 202 | void * WorkerPool::helperThreadProc(void *vwp) { 203 | WorkerPool *wp = (WorkerPool *)vwp; 204 | 205 | uint32_t idx = __sync_fetch_and_add(&wp->mLaunchCount, 1); 206 | 207 | wp->mLaunchSignals[idx].init(); 208 | wp->mNativeThreadId[idx] = gettid(); 209 | 210 | while (!wp->mExit) { 211 | wp->mLaunchSignals[idx].wait(); 212 | if (wp->mLaunchCallback) { 213 | // idx +1 is used because the calling thread is always worker 0. 214 | wp->mLaunchCallback(wp->mLaunchData, idx); 215 | } 216 | __sync_fetch_and_sub(&wp->mRunningCount, 1); 217 | wp->mCompleteSignal.set(); 218 | } 219 | 220 | //ALOGV("RS helperThread exited %p idx=%i", dc, idx); 221 | return NULL; 222 | } 223 | 224 | 225 | void WorkerPool::waitForAll() const { 226 | } 227 | 228 | void WorkerPool::waitFor(uint64_t) const { 229 | } 230 | 231 | 232 | 233 | uint64_t WorkerPool::launchWork(WorkerCallback_t cb, void *usr, int maxThreads) { 234 | //__android_log_print(ANDROID_LOG_INFO, "bench", "lw 1"); 235 | mLaunchData = usr; 236 | mLaunchCallback = cb; 237 | 238 | if (maxThreads < 1) { 239 | maxThreads = mCount; 240 | } 241 | if ((uint32_t)maxThreads > mCount) { 242 | //__android_log_print(ANDROID_LOG_INFO, "bench", "launchWork max > count", maxThreads, mCount); 243 | maxThreads = mCount; 244 | } 245 | 246 | //__android_log_print(ANDROID_LOG_INFO, "bench", "lw 2 %i %i %i", maxThreads, mRunningCount, mCount); 247 | mRunningCount = maxThreads; 248 | __sync_synchronize(); 249 | 250 | for (int ct = 0; ct < maxThreads; ct++) { 251 | mLaunchSignals[ct].set(); 252 | } 253 | 254 | //__android_log_print(ANDROID_LOG_INFO, "bench", "lw 3 %i", mRunningCount); 255 | while (__sync_fetch_and_or(&mRunningCount, 0) != 0) { 256 | //__android_log_print(ANDROID_LOG_INFO, "bench", "lw 3.1 %i", mRunningCount); 257 | mCompleteSignal.wait(); 258 | } 259 | 260 | //__android_log_print(ANDROID_LOG_INFO, "bench", "lw 4 %i", mRunningCount); 261 | return 0; 262 | 263 | } 264 | 265 | 266 | 267 | -------------------------------------------------------------------------------- /app/src/main/jni/WorkerPool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | #ifndef ANDROID_WORKER_POOL_H 18 | #define ANDROID_WORKER_POOL_H 19 | 20 | #include 21 | #include 22 | 23 | 24 | 25 | class WorkerPool { 26 | public: 27 | WorkerPool(); 28 | ~WorkerPool(); 29 | 30 | typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); 31 | 32 | bool init(int threadCount = -1); 33 | int getWorkerCount() const {return mCount;} 34 | 35 | void waitForAll() const; 36 | void waitFor(uint64_t) const; 37 | uint64_t launchWork(WorkerCallback_t cb, void *usr, int maxThreads = -1); 38 | 39 | 40 | 41 | 42 | protected: 43 | class Signal { 44 | public: 45 | Signal(); 46 | ~Signal(); 47 | 48 | bool init(); 49 | void set(); 50 | 51 | // returns true if the signal occured 52 | // false for timeout 53 | bool wait(uint64_t timeout = 0); 54 | 55 | protected: 56 | bool mSet; 57 | pthread_mutex_t mMutex; 58 | pthread_cond_t mCondition; 59 | }; 60 | 61 | bool mExit; 62 | volatile int mRunningCount; 63 | volatile int mLaunchCount; 64 | uint32_t mCount; 65 | pthread_t *mThreadId; 66 | pid_t *mNativeThreadId; 67 | Signal mCompleteSignal; 68 | Signal *mLaunchSignals; 69 | WorkerCallback_t mLaunchCallback; 70 | void *mLaunchData; 71 | 72 | 73 | 74 | 75 | private: 76 | //static void * threadProc(void *); 77 | static void * helperThreadProc(void *); 78 | 79 | 80 | }; 81 | 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /app/src/main/jni/test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | #include 18 | #include 19 | //#include 20 | //#include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "jni.h" 27 | #include "Bench.h" 28 | 29 | #define FUNC(name) Java_com_android_benchmark_synthetic_TestInterface_##name 30 | 31 | static uint64_t GetTime() { 32 | struct timespec t; 33 | clock_gettime(CLOCK_MONOTONIC, &t); 34 | return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000); 35 | } 36 | 37 | extern "C" { 38 | 39 | jlong Java_com_android_benchmark_synthetic_TestInterface_nInit(JNIEnv *_env, jobject _this, jlong options) { 40 | Bench *b = new Bench(); 41 | bool ret = b->init(); 42 | 43 | if (ret) { 44 | return (jlong)b; 45 | } 46 | 47 | delete b; 48 | return 0; 49 | } 50 | 51 | void Java_com_android_benchmark_synthetic_TestInterface_nDestroy(JNIEnv *_env, jobject _this, jlong _b) { 52 | Bench *b = (Bench *)_b; 53 | 54 | delete b; 55 | } 56 | 57 | jboolean Java_com_android_benchmark_synthetic_TestInterface_nRunPowerManagementTest( 58 | JNIEnv *_env, jobject _this, jlong _b, jlong options) { 59 | Bench *b = (Bench *)_b; 60 | return b->runPowerManagementTest(options); 61 | } 62 | 63 | jboolean Java_com_android_benchmark_synthetic_TestInterface_nRunCPUHeatSoakTest( 64 | JNIEnv *_env, jobject _this, jlong _b, jlong options) { 65 | Bench *b = (Bench *)_b; 66 | return b->runCPUHeatSoak(options); 67 | } 68 | 69 | float Java_com_android_benchmark_synthetic_TestInterface_nGetData( 70 | JNIEnv *_env, jobject _this, jlong _b, jfloatArray data) { 71 | Bench *b = (Bench *)_b; 72 | 73 | jsize len = _env->GetArrayLength(data); 74 | float * ptr = _env->GetFloatArrayElements(data, 0); 75 | 76 | b->getData(ptr, len); 77 | 78 | _env->ReleaseFloatArrayElements(data, (jfloat *)ptr, 0); 79 | 80 | return 0; 81 | } 82 | 83 | jboolean Java_com_android_benchmark_synthetic_TestInterface_nMemTestStart( 84 | JNIEnv *_env, jobject _this, jlong _b) { 85 | Bench *b = (Bench *)_b; 86 | return b->startMemTests(); 87 | } 88 | 89 | float Java_com_android_benchmark_synthetic_TestInterface_nMemTestBandwidth( 90 | JNIEnv *_env, jobject _this, jlong _b, jlong opt) { 91 | Bench *b = (Bench *)_b; 92 | return b->runMemoryBandwidthTest(opt); 93 | } 94 | 95 | float Java_com_android_benchmark_synthetic_TestInterface_nGFlopsTest( 96 | JNIEnv *_env, jobject _this, jlong _b, jlong opt) { 97 | Bench *b = (Bench *)_b; 98 | return b->runGFlopsTest(opt); 99 | } 100 | 101 | float Java_com_android_benchmark_synthetic_TestInterface_nMemTestLatency( 102 | JNIEnv *_env, jobject _this, jlong _b, jlong opt) { 103 | Bench *b = (Bench *)_b; 104 | return b->runMemoryLatencyTest(opt); 105 | } 106 | 107 | void Java_com_android_benchmark_synthetic_TestInterface_nMemTestEnd( 108 | JNIEnv *_env, jobject _this, jlong _b) { 109 | Bench *b = (Bench *)_b; 110 | b->endMemTests(); 111 | } 112 | 113 | float Java_com_android_benchmark_synthetic_TestInterface_nMemoryTest( 114 | JNIEnv *_env, jobject _this, jint subtest) { 115 | 116 | uint8_t * volatile m1 = (uint8_t *)malloc(1024*1024*64); 117 | uint8_t * m2 = (uint8_t *)malloc(1024*1024*64); 118 | 119 | memset(m1, 0, 1024*1024*16); 120 | memset(m2, 0, 1024*1024*16); 121 | 122 | //__android_log_print(ANDROID_LOG_INFO, "bench", "test %i %p %p", subtest, m1, m2); 123 | 124 | 125 | size_t loopCount = 0; 126 | uint64_t start = GetTime(); 127 | while((GetTime() - start) < 1000000000) { 128 | memcpy(m1, m2, subtest); 129 | loopCount++; 130 | } 131 | if (loopCount == 0) { 132 | loopCount = 1; 133 | } 134 | 135 | size_t count = loopCount; 136 | uint64_t t1 = GetTime(); 137 | while (loopCount > 0) { 138 | memcpy(m1, m2, subtest); 139 | loopCount--; 140 | } 141 | uint64_t t2 = GetTime(); 142 | 143 | double dt = t2 - t1; 144 | dt /= 1000 * 1000 * 1000; 145 | double bw = ((double)subtest) * count / dt; 146 | 147 | bw /= 1024 * 1024 * 1024; 148 | 149 | __android_log_print(ANDROID_LOG_INFO, "bench", "size %i, bw %f", subtest, bw); 150 | 151 | free (m1); 152 | free (m2); 153 | return (float)bw; 154 | } 155 | 156 | jlong Java_com_android_benchmark_synthetic_MemoryAvailableLoad1_nMemTestMalloc( 157 | JNIEnv *_env, jobject _this, jint bytes) { 158 | uint8_t *p = (uint8_t *)malloc(bytes); 159 | memset(p, 0, bytes); 160 | return (jlong)p; 161 | } 162 | 163 | void Java_com_android_benchmark_synthetic_MemoryAvailableLoad1_nMemTestFree( 164 | JNIEnv *_env, jobject _this, jlong ptr) { 165 | free((void *)ptr); 166 | } 167 | 168 | jlong Java_com_android_benchmark_synthetic_MemoryAvailableLoad2_nMemTestMalloc( 169 | JNIEnv *_env, jobject _this, jint bytes) { 170 | return Java_com_android_benchmark_synthetic_MemoryAvailableLoad1_nMemTestMalloc(_env, _this, bytes); 171 | } 172 | 173 | void Java_com_android_benchmark_synthetic_MemoryAvailableLoad2_nMemTestFree( 174 | JNIEnv *_env, jobject _this, jlong ptr) { 175 | Java_com_android_benchmark_synthetic_MemoryAvailableLoad1_nMemTestFree(_env, _this, ptr); 176 | } 177 | 178 | }; // extern "C" 179 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/drawable/ic_play.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/drawable/img1.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/drawable/img2.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/img3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/drawable/img3.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/img4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/drawable/img4.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_bitmap_upload.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 25 | 29 | 33 | 34 | 35 | 38 | 39 | 43 | 44 | 47 | 48 | 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_list_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 28 | 29 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_memory.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | 14 | 20 | 21 | 27 | 28 | 34 | 35 | 41 | 42 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_running_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 16 | 17 | 24 | 25 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/benchmark_list_group_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/benchmark_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 23 | 24 | 25 | 30 | 31 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/card_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 27 | 31 | 35 | 36 | 37 | 40 | 41 | 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_dashboard.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 24 | 25 | 31 | 32 | 41 | 42 | 48 | 49 | 57 | 58 | 59 | 60 | 61 | 62 | 66 | 67 | 71 | 72 | 76 | 77 | 78 | 79 | 80 | 81 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_ui_results_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/image_scroll_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 11 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/results_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/running_benchmark_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 26 | 30 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_memory.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 21 | 64dp 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #3F51B5 20 | #303F9F 21 | #FF4081 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 256dp 20 | 16dp 21 | 16dp 22 | 16dp 23 | 16dp 24 | 200dp 25 | 200dp 26 | 16dp 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | JankBenchX 19 | 20 | Export to CSV 21 | Upload Results 22 | View Results Online 23 | 24 | List View Fling 25 | Tests list view fling performance 26 | Image List View Fling 27 | Tests list view fling performance with images 28 | Shadow Grid Fling 29 | Tests shadow grid fling performance with images 30 | High-hitrate text render 31 | Tests high hitrate text rendering 32 | Low-hitrate text render 33 | Tests low-hitrate text rendering 34 | Edit Text Input 35 | Tests edit text input 36 | Overdraw Test 37 | Tests how the device handles overdraw 38 | Bitmap Upload Test 39 | Tests bitmap upload 40 | Memory Bandwidth 41 | Test device\'s memory bandwidth 42 | Memory Latency 43 | Test device\'s memory latency 44 | Power Management 45 | Test device\'s power management 46 | CPU Heat Soak 47 | How hot can we make it? 48 | CPU GFlops 49 | How many gigaflops can the device attain? 50 | 51 | UI 52 | Compute 53 | Generic 54 | ImageListViewScroll 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 31 | 32 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/xml/benchmark.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 28 | 29 | 34 | 35 | 40 | 41 | 46 | 47 | 52 | 53 | 58 | 59 | 64 | 65 | 70 | 71 | 102 | 103 | -------------------------------------------------------------------------------- /app/src/test/java/com/android/benchmark/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | 17 | package com.android.benchmark; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.*; 22 | 23 | /** 24 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 25 | */ 26 | public class ExampleUnitTest { 27 | @Test 28 | public void addition_isCorrect() throws Exception { 29 | assertEquals(4, 2 + 2); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/test/java/com/android/benchmark/api/JankBenchServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.android.benchmark.api; 2 | 3 | import com.android.benchmark.models.Entry; 4 | 5 | import org.junit.Test; 6 | 7 | import java.io.IOException; 8 | 9 | import retrofit2.Call; 10 | import retrofit2.Response; 11 | import retrofit2.Retrofit; 12 | import retrofit2.converter.gson.GsonConverterFactory; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | public class JankBenchServiceTest { 17 | 18 | @Test 19 | public void uploadEntry() throws IOException { 20 | Retrofit retrofit = new Retrofit.Builder() 21 | .baseUrl("http://127.0.0.1:5000/") 22 | .addConverterFactory(GsonConverterFactory.create()) 23 | .build(); 24 | 25 | JankBenchService resource = retrofit.create(JankBenchService.class); 26 | Entry entry = new Entry(); // TODO: Add data here 27 | 28 | Call call = resource.uploadEntry(entry); 29 | Response response = call.execute(); 30 | 31 | assertTrue(response.isSuccessful()); 32 | } 33 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.1.3' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | # AndroidX package structure to make it clearer which packages are bundled with the 20 | # Android operating system, and which are packaged with your app's APK 21 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 22 | android.useAndroidX=true 23 | # Automatically convert third-party libraries to use AndroidX 24 | android.enableJetifier=true 25 | 26 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Apr 12 21:45:59 SGT 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /scripts/adbutil.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import re 3 | import threading 4 | 5 | ATRACE_PATH="/android/catapult/systrace/systrace/systrace.py" 6 | 7 | class AdbError(RuntimeError): 8 | def __init__(self, arg): 9 | self.args = arg 10 | 11 | def am(serial, cmd, args): 12 | if not isinstance(args, list): 13 | args = [args] 14 | full_args = ["am"] + [cmd] + args 15 | __call_adb(serial, full_args, False) 16 | 17 | def pm(serial, cmd, args): 18 | if not isinstance(args, list): 19 | args = [args] 20 | full_args = ["pm"] + [cmd] + args 21 | __call_adb(serial, full_args, False) 22 | 23 | def dumpsys(serial, topic): 24 | return __call_adb(serial, ["dumpsys"] + [topic], True) 25 | 26 | def trace(serial, 27 | tags = ["gfx", "sched", "view", "freq", "am", "wm", "power", "load", "memreclaim"], 28 | time = "10"): 29 | args = [ATRACE_PATH, "-e", serial, "-t" + time, "-b32768"] + tags 30 | subprocess.call(args) 31 | 32 | def wake(serial): 33 | output = dumpsys(serial, "power") 34 | wakefulness = re.search('mWakefulness=([a-zA-Z]+)', output) 35 | if wakefulness.group(1) != "Awake": 36 | __call_adb(serial, ["input", "keyevent", "KEYCODE_POWER"], False) 37 | 38 | def root(serial): 39 | subprocess.call(["adb", "-s", serial, "root"]) 40 | 41 | def pull(serial, path, dest): 42 | subprocess.call(["adb", "-s", serial, "wait-for-device", "pull"] + [path] + [dest]) 43 | 44 | def shell(serial, cmd): 45 | __call_adb(serial, cmd, False) 46 | 47 | def track_logcat(serial, awaited_string, callback): 48 | threading.Thread(target=__track_logcat, name=serial + "-waiter", args=(serial, awaited_string, callback)).start() 49 | 50 | def __call_adb(serial, args, block): 51 | full_args = ["adb", "-s", serial, "wait-for-device", "shell"] + args 52 | print full_args 53 | output = None 54 | try: 55 | if block: 56 | output = subprocess.check_output(full_args) 57 | else: 58 | subprocess.call(full_args) 59 | except subprocess.CalledProcessError: 60 | raise AdbError("Error calling " + " ".join(args)) 61 | 62 | return output 63 | -------------------------------------------------------------------------------- /scripts/devices.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | DEVICES = { 4 | 'bullhead': '00606a370e3ca155', 5 | 'volantis': 'HT4BTWV00612', 6 | 'angler': '84B5T15A29021748', 7 | 'seed': '1285c85e', 8 | 'ryu': '5A27000599', 9 | 'shamu': 'ZX1G22W24R', 10 | } 11 | 12 | -------------------------------------------------------------------------------- /scripts/external/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshchoo/JankBenchX/09e5e8c01b8fcf851d037031085f33727b3f8caf/scripts/external/__init__.py -------------------------------------------------------------------------------- /scripts/itr_collect.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import optparse 4 | import sys 5 | import sqlite3 6 | import scipy.stats 7 | import numpy 8 | 9 | import adbutil 10 | from devices import DEVICES 11 | 12 | DB_PATH="/data/data/com.android.benchmark/databases/BenchmarkResults" 13 | OUT_PATH = "db/" 14 | 15 | QUERY_BAD_FRAME = ("select run_id, name, total_duration from ui_results " 16 | "where total_duration >=12 order by run_id, name") 17 | QUERY_PERCENT_JANK = ("select run_id, name, sum(jank_frame) as jank_count, count (*) as total " 18 | "from ui_results group by run_id, name") 19 | 20 | class IterationResult: 21 | def __init__(self): 22 | self.durations = [] 23 | self.jank_count = 0 24 | self.total_count = 0 25 | 26 | 27 | def get_scoremap(dbpath): 28 | db = sqlite3.connect(dbpath) 29 | rows = db.execute(QUERY_BAD_FRAME) 30 | 31 | scoremap = {} 32 | for row in rows: 33 | run_id = row[0] 34 | name = row[1] 35 | total_duration = row[2] 36 | 37 | if not run_id in scoremap: 38 | scoremap[run_id] = {} 39 | 40 | if not name in scoremap[run_id]: 41 | scoremap[run_id][name] = IterationResult() 42 | 43 | 44 | scoremap[run_id][name].durations.append(float(total_duration)) 45 | 46 | for row in db.execute(QUERY_PERCENT_JANK): 47 | run_id = row[0] 48 | name = row[1] 49 | jank_count = row[2] 50 | total_count = row[3] 51 | 52 | if run_id in scoremap.keys() and name in scoremap[run_id].keys(): 53 | scoremap[run_id][name].jank_count = long(jank_count) 54 | scoremap[run_id][name].total_count = long(total_count) 55 | 56 | 57 | db.close() 58 | return scoremap 59 | 60 | def score_device(name, serial, pull = False, verbose = False): 61 | dbpath = OUT_PATH + name + ".db" 62 | 63 | if pull: 64 | adbutil.root(serial) 65 | adbutil.pull(serial, DB_PATH, dbpath) 66 | 67 | scoremap = None 68 | try: 69 | scoremap = get_scoremap(dbpath) 70 | except sqlite3.DatabaseError: 71 | print "Database corrupt, fetching..." 72 | adbutil.root(serial) 73 | adbutil.pull(serial, DB_PATH, dbpath) 74 | scoremap = get_scoremap(dbpath) 75 | 76 | per_test_score = {} 77 | per_test_sample_count = {} 78 | global_overall = {} 79 | 80 | for run_id in iter(scoremap): 81 | overall = [] 82 | if len(scoremap[run_id]) < 1: 83 | if verbose: 84 | print "Skipping short run %s" % run_id 85 | continue 86 | print "Run: %s" % run_id 87 | for test in iter(scoremap[run_id]): 88 | if verbose: 89 | print "\t%s" % test 90 | scores = [] 91 | sample_count = 0 92 | res = scoremap[run_id][test] 93 | stddev = numpy.std(res.durations) 94 | mean = numpy.mean(res.durations) 95 | sample_count = len(res.durations) 96 | pj = 100 * res.jank_count / float(res.total_count) 97 | score = stddev * mean *pj 98 | if score == 0: 99 | score = 1 100 | scores.append(score) 101 | if verbose: 102 | print "\tScore = %f x %f x %f = %f (%d samples)" % (stddev, mean, pj, score, len(res.durations)) 103 | 104 | geo_run = scipy.stats.gmean(scores) 105 | if test not in per_test_score: 106 | per_test_score[test] = [] 107 | 108 | if test not in per_test_sample_count: 109 | per_test_sample_count[test] = [] 110 | 111 | per_test_score[test].append(geo_run) 112 | per_test_sample_count[test].append(int(sample_count)) 113 | overall.append(geo_run) 114 | 115 | if not verbose: 116 | print "\t%s:\t%0.2f (%0.2f avg. sample count)" % (test, geo_run, sample_count) 117 | else: 118 | print "\tOverall:\t%0.2f (%0.2f avg. sample count)" % (geo_run, sample_count) 119 | print "" 120 | 121 | global_overall[run_id] = scipy.stats.gmean(overall) 122 | print "Run Overall: %f" % global_overall[run_id] 123 | print "" 124 | 125 | print "" 126 | print "Variability (CV) - %s:" % name 127 | 128 | for test in per_test_score: 129 | print "\t%s:\t%0.2f%% (%0.2f avg sample count)" % (test, 100 * scipy.stats.variation(per_test_score[test]), numpy.mean(per_test_sample_count[test])) 130 | 131 | print "\tOverall: %0.2f%%" % (100 * scipy.stats.variation([x for x in global_overall.values()])) 132 | print "" 133 | 134 | def parse_options(argv): 135 | usage = 'Usage: %prog [options]' 136 | desc = 'Example: %prog' 137 | parser = optparse.OptionParser(usage=usage, description=desc) 138 | parser.add_option("-p", dest='pull', action="store_true") 139 | parser.add_option("-d", dest='device', action="store") 140 | parser.add_option("-v", dest='verbose', action="store_true") 141 | options, categories = parser.parse_args(argv[1:]) 142 | return options 143 | 144 | def main(): 145 | options = parse_options(sys.argv) 146 | if options.device != None: 147 | score_device(options.device, DEVICES[options.device], options.pull, options.verbose) 148 | else: 149 | for name, serial in DEVICES.iteritems(): 150 | print "======== %s =========" % name 151 | score_device(name, serial, options.pull, options.verbose) 152 | 153 | if __name__ == "__main__": 154 | main() 155 | -------------------------------------------------------------------------------- /scripts/runall.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import optparse 4 | import sys 5 | import time 6 | 7 | import adbutil 8 | from devices import DEVICES 9 | 10 | def parse_options(argv): 11 | usage = 'Usage: %prog [options]' 12 | desc = 'Example: %prog' 13 | parser = optparse.OptionParser(usage=usage, description=desc) 14 | parser.add_option("-c", dest='clear', action="store_true") 15 | parser.add_option("-d", dest='device', action="store",) 16 | parser.add_option("-t", dest='trace', action="store_true") 17 | options, categories = parser.parse_args(argv[1:]) 18 | return (options, categories) 19 | 20 | def clear_data(device = None): 21 | if device != None: 22 | dev = DEVICES[device] 23 | adbutil.root(dev) 24 | adbutil.pm(dev, "clear", "com.android.benchmark") 25 | else: 26 | for name, dev in DEVICES.iteritems(): 27 | print("Clearing " + name) 28 | adbutil.root(dev) 29 | adbutil.pm(dev, "clear", "com.android.benchmark") 30 | 31 | def start_device(name, dev): 32 | print("Go " + name + "!") 33 | try: 34 | adbutil.am(dev, "force-stop", "com.android.benchmark") 35 | adbutil.wake(dev) 36 | adbutil.am(dev, "start", 37 | ["-n", "\"com.android.benchmark/.app.RunLocalBenchmarksActivity\"", 38 | "--eia", "\"com.android.benchmark.EXTRA_ENABLED_BENCHMARK_IDS\"", "\"0,1,2,3,4,5,6\"", 39 | "--ei", "\"com.android.benchmark.EXTRA_RUN_COUNT\"", "\"5\""]) 40 | except adbutil.AdbError: 41 | print "Couldn't launch " + name + "." 42 | 43 | def start_benchmark(device, trace): 44 | if device != None: 45 | start_device(device, DEVICES[device]) 46 | if trace: 47 | time.sleep(3) 48 | adbutil.trace(DEVICES[device]) 49 | else: 50 | if trace: 51 | print("Note: -t only valid with -d, can't trace") 52 | for name, dev in DEVICES.iteritems(): 53 | start_device(name, dev) 54 | 55 | def main(): 56 | options, categories = parse_options(sys.argv) 57 | if options.clear: 58 | print options.device 59 | clear_data(options.device) 60 | else: 61 | start_benchmark(options.device, options.trace) 62 | 63 | 64 | if __name__ == "__main__": 65 | main() 66 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='JankBenchX' 3 | --------------------------------------------------------------------------------