Skip to content

Commit 6a614e3

Browse files
committed
Set up a separate benchmark app [skip actions]
1 parent f62053f commit 6a614e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+836
-89
lines changed

buildSrc/src/main/kotlin/LicenseeConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.gradle.kotlin.dsl.configure
2020

2121
fun Project.applyLicenseeConfig() {
2222
// Skip project "demo:benchmark" since it's a "com.android.test" project which is not compatible with Licensee
23-
if (project.path == ":demo:macrobenchmark") {
23+
if (project.path == ":engine:benchmarks:macrobenchmark") {
2424
return
2525
}
2626

demo/.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
/build
2-
/src/benchmark/assets/bulk_data
3-
/synthea
1+
/build

demo/build.gradle.kts

-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ android {
2222
isMinifyEnabled = true
2323
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
2424
}
25-
create("benchmark") {
26-
initWith(buildTypes.getByName("release"))
27-
applicationIdSuffix = ".benchmark"
28-
signingConfig = signingConfigs.getByName("debug")
29-
matchingFallbacks += listOf("release")
30-
isDebuggable = false
31-
}
3225
}
3326
buildFeatures {
3427
buildConfig = true
@@ -71,7 +64,6 @@ dependencies {
7164
exclude(group = "com.google.android.fhir", module = "engine")
7265
}
7366
implementation(project(":engine"))
74-
"benchmarkImplementation"(libs.androidx.profileinstaller)
7567

7668
testImplementation(libs.junit)
7769
}

demo/macrobenchmark/src/main/java/com/google/android/fhir/demo/macrobenchmark/ExampleStartupBenchmark.kt

-55
This file was deleted.

demo/src/main/AndroidManifest.xml

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<?xml version="1.0" encoding="utf-8" ?>
2-
<manifest
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
>
2+
<!--
3+
Copyright 2020 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
618

719
<uses-permission android:name="android.permission.INTERNET" />
820

@@ -16,13 +28,10 @@
1628
android:supportsRtl="true"
1729
android:theme="@style/AppTheme"
1830
>
19-
<profileable android:shell="true" tools:targetApi="29" />
20-
2131
<activity
2232
android:name="com.google.android.fhir.demo.MainActivity"
23-
android:exported="true"
24-
android:label="@string/app_name"
2533
android:windowSoftInputMode="adjustResize"
34+
android:exported="true"
2635
>
2736
<intent-filter>
2837
<action android:name="android.intent.action.MAIN" />
@@ -31,5 +40,4 @@
3140
</intent-filter>
3241
</activity>
3342
</application>
34-
3543
</manifest>

engine/benchmarks/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/synthea
File renamed without changes.

engine/benchmarks/app/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
/src/main/assets/bulk_data
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
plugins {
2+
id(Plugins.BuildPlugins.application)
3+
id(Plugins.BuildPlugins.kotlinAndroid)
4+
id(Plugins.BuildPlugins.navSafeArgs)
5+
}
6+
7+
android {
8+
namespace = "com.google.android.fhir.engine.benchmarks.app"
9+
compileSdk = Sdk.COMPILE_SDK
10+
11+
defaultConfig {
12+
applicationId = "com.google.android.fhir.engine.benchmarks.app"
13+
minSdk = Sdk.MIN_SDK
14+
targetSdk = Sdk.TARGET_SDK
15+
versionCode = 1
16+
versionName = "1.0"
17+
testInstrumentationRunner = Dependencies.androidJunitRunner
18+
}
19+
20+
buildTypes {
21+
release {
22+
isMinifyEnabled = false
23+
proguardFiles(
24+
getDefaultProguardFile("proguard-android-optimize.txt"),
25+
"proguard-rules.pro"
26+
)
27+
}
28+
29+
create("benchmark") {
30+
initWith(buildTypes.getByName("release"))
31+
signingConfig = signingConfigs.getByName("debug")
32+
matchingFallbacks += listOf("release")
33+
isDebuggable = false
34+
}
35+
}
36+
compileOptions {
37+
// Flag to enable support for the new language APIs
38+
// See https://developer.android.com/studio/write/java8-support
39+
isCoreLibraryDesugaringEnabled = true
40+
}
41+
42+
kotlin { jvmToolchain(11) }
43+
44+
packaging { resources.excludes.addAll(listOf("META-INF/ASL-2.0.txt", "META-INF/LGPL-3.0.txt")) }
45+
}
46+
47+
dependencies {
48+
coreLibraryDesugaring(Dependencies.desugarJdkLibs)
49+
implementation(libs.androidx.activity)
50+
implementation(libs.androidx.appcompat)
51+
implementation(libs.androidx.constraintlayout)
52+
implementation(libs.androidx.datastore.preferences)
53+
implementation(libs.androidx.fragment)
54+
implementation(libs.androidx.lifecycle.livedata)
55+
implementation(libs.androidx.lifecycle.runtime)
56+
implementation(libs.androidx.lifecycle.viewmodel)
57+
implementation(libs.androidx.profileinstaller)
58+
implementation(libs.androidx.work.runtime)
59+
implementation(libs.bundles.androidx.tracing)
60+
implementation(libs.kotlin.stdlib)
61+
implementation(libs.kotlinx.coroutines.android)
62+
implementation(libs.kotlinx.coroutines.core)
63+
implementation(libs.material)
64+
implementation(project(":engine"))
65+
66+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:name=".BenchmarkApplication"
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:networkSecurityConfig="@xml/network_security_config"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/AppTheme">
16+
17+
<profileable
18+
android:shell="true"
19+
tools:targetApi="29" />
20+
21+
<activity
22+
android:name=".BenchmarkActivity"
23+
android:exported="true">
24+
<intent-filter>
25+
<action android:name="android.intent.action.MAIN" />
26+
27+
<category android:name="android.intent.category.LAUNCHER" />
28+
</intent-filter>
29+
</activity>
30+
</application>
31+
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.google.android.fhir.engine.benchmarks.app
2+
3+
import android.os.Bundle
4+
import android.view.View
5+
import android.widget.TextView
6+
import androidx.appcompat.app.AppCompatActivity
7+
import androidx.core.view.ViewCompat
8+
import androidx.core.view.WindowInsetsCompat
9+
import androidx.lifecycle.ViewModel
10+
import androidx.lifecycle.ViewModelProvider
11+
import androidx.lifecycle.lifecycleScope
12+
import kotlinx.coroutines.launch
13+
14+
15+
class BenchmarkActivity : AppCompatActivity() {
16+
17+
private lateinit var viewModel: BenchmarkViewModel
18+
private lateinit var createTextView: TextView
19+
private lateinit var updateTextView: TextView
20+
21+
override fun onCreate(savedInstanceState: Bundle?) {
22+
super.onCreate(savedInstanceState)
23+
setContentView(R.layout.activity_benchmark)
24+
25+
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
26+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
27+
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
28+
insets
29+
}
30+
31+
val fhirEngine = BenchmarkApplication.fhirEngine(this)
32+
viewModel = ViewModelProvider(
33+
this,
34+
object : ViewModelProvider.Factory {
35+
override fun <T : ViewModel> create(modelClass: Class<T>): T {
36+
if (modelClass.isAssignableFrom(BenchmarkViewModel::class.java)) {
37+
@Suppress("UNCHECKED_CAST")
38+
return BenchmarkViewModel(application, fhirEngine) as T
39+
}
40+
return super.create(modelClass)
41+
}
42+
})[BenchmarkViewModel::class.java]
43+
44+
createTextView = findViewById(R.id.createTextView)
45+
findViewById<View>(R.id.create).setOnClickListener {
46+
lifecycleScope.launch {
47+
createTextView.setText(R.string.creating)
48+
viewModel.createResources()
49+
createTextView.setText(R.string.createText)
50+
}
51+
}
52+
updateTextView = findViewById(R.id.updateTextView)
53+
findViewById<View>(R.id.update).setOnClickListener {
54+
lifecycleScope.launch {
55+
updateTextView.setText(R.string.updating)
56+
viewModel.updateResources()
57+
updateTextView.setText(R.string.updateText)
58+
}
59+
}
60+
findViewById<View>(R.id.get).setOnClickListener { viewModel.getResource() }
61+
findViewById<View>(R.id.delete).setOnClickListener { viewModel.deleteResources() }
62+
}
63+
}

0 commit comments

Comments
 (0)