Skip to content

Commit

Permalink
Split unified benchmark module to individual library benchmark modules (
Browse files Browse the repository at this point in the history
#2139)

* Split benchmark module to individual benchmarks in particular library modules

* Removed benchmark module

* Updated kokoro script to run benchmarks

* spotless apply

* Review comment changes
  • Loading branch information
aditya-07 committed Aug 21, 2023
1 parent 173db10 commit 14e1277
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 30 deletions.
1 change: 1 addition & 0 deletions engine/benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions engine/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Android FHIR SDK Engine Benchmark module

Contains test cases that evaluate the performance of individual tasks executed for the first time directly on hardware.

The test cases are designed to run in sequence of their alphabetic order to make sure larger tasks do not build cache for smaller ones. Their class names are prefixed by an extra letter to inform their position relative to others in the list.

# How to run the benchmark

In Android Studio, set your build variants to `release` and run your benchmark as you would any `@Test` using the gutter action next to your test class or method.

![gutter test action](https://developer.android.com/static/topic/performance/images/benchmark_images/microbenchmark_run.png)

The results will be similar to this:
```
1,297,374 ns 5345 allocs trace EngineDatabaseBenchmark.createAndGet
1,114,474,793 ns 4922289 allocs trace FhirSyncWorkerBenchmark.oneTimeSync_50patients
15,251,125 ns 100542 allocs trace FhirSyncWorkerBenchmark.oneTimeSync_1patient
179,806,709 ns 986017 allocs trace FhirSyncWorkerBenchmark.oneTimeSync_10patients
1,451,758 ns 11883 allocs trace GzipUploadInterceptorBenchmark.upload_10patientsWithGzip
1,537,559 ns 11829 allocs trace GzipUploadInterceptorBenchmark.upload_10patientsWithoutGzip
73,640,833 ns 1074360 allocs trace GzipUploadInterceptorBenchmark.upload_1000patientsWithGzip
7,493,642 ns 108428 allocs trace GzipUploadInterceptorBenchmark.upload_100patientsWithoutGzip
7,799,264 ns 108465 allocs trace GzipUploadInterceptorBenchmark.upload_100patientsWithGzip
71,189,333 ns 1074466 allocs trace GzipUploadInterceptorBenchmark.upload_1000patientsWithoutGzip
```

Alternatively, from the command line, run the connectedCheck to run all of the tests from specified Gradle module:

```bash
./gradlew :engine:benchmark:connectedReleaseAndroidTest
```

In this case, results will be saved to the `outputs/androidTest-results/connected/<device>/test-result.pb`. To visualize on Android Studio, click Run / Import Tests From File and find the `.pb` file
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-dontobfuscate

-ignorewarnings

-keepattributes *Annotation*

-dontnote junit.framework.**
-dontnote junit.runner.**

-dontwarn androidx.test.**
-dontwarn org.junit.**
-dontwarn org.hamcrest.**
-dontwarn com.squareup.javawriter.JavaWriter

-keepclasseswithmembers @org.junit.runner.RunWith public class *
80 changes: 80 additions & 0 deletions engine/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Dependencies.forceHapiVersion
import Dependencies.forceJacksonVersion
import Dependencies.removeIncompatibleDependencies

plugins {
id(Plugins.BuildPlugins.androidLib)
id(Plugins.BuildPlugins.kotlinAndroid)
id(Plugins.BuildPlugins.benchmark)
}

android {
namespace = "com.google.android.fhir.benchmark"
compileSdk = Sdk.compileSdk
defaultConfig {
minSdk = Sdk.minSdk
testInstrumentationRunner = Dependencies.androidBenchmarkRunner
}

testBuildType = "release"
buildTypes { release {} }
packaging {
resources.excludes.addAll(
listOf(
"license.html",
"META-INF/ASL2.0",
"META-INF/ASL-2.0.txt",
"META-INF/DEPENDENCIES",
"META-INF/LGPL-3.0.txt",
"META-INF/LICENSE",
"META-INF/LICENSE.txt",
"META-INF/license.txt",
"META-INF/license.html",
"META-INF/LICENSE.md",
"META-INF/NOTICE",
"META-INF/NOTICE.txt",
"META-INF/NOTICE.md",
"META-INF/notice.txt",
"META-INF/LGPL-3.0.txt",
"META-INF/sun-jaxb.episode",
"META-INF/*.kotlin_module",
"readme.html",
)
)
}
kotlin { jvmToolchain(11) }
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
}

afterEvaluate { configureFirebaseTestLabForMicroBenchmark() }

configurations {
all {
removeIncompatibleDependencies()
forceHapiVersion()
forceJacksonVersion()
}
}

dependencies {
androidTestImplementation(Dependencies.AndroidxTest.benchmarkJunit)
androidTestImplementation(Dependencies.AndroidxTest.extJunit)
androidTestImplementation(Dependencies.AndroidxTest.runner)
androidTestImplementation(Dependencies.Cql.engineJackson)
androidTestImplementation(Dependencies.Cql.evaluator)
androidTestImplementation(Dependencies.Cql.evaluatorBuilder)
androidTestImplementation(Dependencies.junit)
androidTestImplementation(Dependencies.Kotlin.kotlinCoroutinesAndroid)
androidTestImplementation(Dependencies.truth)
androidTestImplementation(Dependencies.Androidx.workRuntimeKtx)
androidTestImplementation(Dependencies.AndroidxTest.workTestingRuntimeKtx)
androidTestImplementation(Dependencies.mockWebServer)
androidTestImplementation(Dependencies.Retrofit.coreRetrofit)

androidTestImplementation(project(":engine"))
// for test json files only
androidTestImplementation(project(":workflow-testing"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
manifest, as it is not possible to override this flag from Gradle.
-->
<application
android:debuggable="false"
tools:ignore="HardcodedDebugMode"
tools:replace="android:debuggable"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
>
<profileable android:shell="true" />
<profileable android:shell="true" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2022-2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@ import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class F_EngineDatabaseBenchmark {
class EngineDatabaseBenchmark {

@get:Rule val benchmarkRule = BenchmarkRule()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class H_FhirSyncWorkerBenchmark {
class FhirSyncWorkerBenchmark {

@get:Rule val benchmarkRule = BenchmarkRule()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Url

class I_GzipUploadInterceptorBenchmark {
class GzipUploadInterceptorBenchmark {

@get:Rule val benchmarkRule = BenchmarkRule()

Expand Down
2 changes: 2 additions & 0 deletions engine/benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" ?>
<manifest />
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu/kokoro_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function build_only() {
function device_tests() {
./gradlew packageDebugAndroidTest --scan --stacktrace
./gradlew packageReleaseAndroidTest --scan --stacktrace
local lib_names=("benchmark" "datacapture" "engine" "knowledge" "workflow")
local lib_names=("workflow:benchmark" "engine:benchmark" "datacapture" "engine" "knowledge" "workflow")
firebase_pids=()
for lib_name in "${lib_names[@]}"; do
./gradlew :$lib_name:runFlank --scan --stacktrace &
Expand Down
6 changes: 4 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ if (kokoroRun == true) {
}
}

include(":benchmark")

include(":catalog")

include(":common")
Expand All @@ -47,3 +45,7 @@ include(":knowledge")
include(":workflow")

include(":workflow-testing")

include(":workflow:benchmark")

include(":engine:benchmark")
1 change: 1 addition & 0 deletions workflow/benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
7 changes: 3 additions & 4 deletions benchmark/README.md → workflow/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Android FHIR SDK Benchmark module
# Android FHIR SDK Workflow Benchmark module

Contains test cases that evaluate the performance of individual tasks executed for the first time directly on hardware.

Expand All @@ -24,14 +24,13 @@ The results will be similar to this:
1,238,212,883 ns trace D_FhirJsonParserBenchmark.parseLightFhirBundle
2,785,964,288 ns trace E_ElmJsonLibraryLoaderBenchmark.parseImmunityCheckCqlFromFhirLibrary
713,779,915 ns trace E_ElmJsonLibraryLoaderBenchmark.parseFhirHelpersCqlFromFhirLibrary
121,204,232 ns trace F_EngineDatabaseBenchmark.createAndGet
9,833,892,387 ns trace G_CqlEvaluatorBenchmark.evaluatesLibrary
9,833,892,387 ns trace F_CqlEvaluatorBenchmark.evaluatesLibrary
```

Alternatively, from the command line, run the connectedCheck to run all of the tests from specified Gradle module:

```bash
./gradlew benchmark:connectedReleaseAndroidTest
./gradlew workflow:benchmark:connectedReleaseAndroidTest
```

In this case, results will be saved to the `outputs/androidTest-results/connected/<device>/test-result.pb`. To visualize on Android Studio, click Run / Import Tests From File and find the `.pb` file
37 changes: 37 additions & 0 deletions workflow/benchmark/benchmark-proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http:https://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-dontobfuscate

-ignorewarnings

-keepattributes *Annotation*

-dontnote junit.framework.**
-dontnote junit.runner.**

-dontwarn androidx.test.**
-dontwarn org.junit.**
-dontwarn org.hamcrest.**
-dontwarn com.squareup.javawriter.JavaWriter

-keepclasseswithmembers @org.junit.runner.RunWith public class *
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

android {
namespace = "com.google.android.fhir.benchmark"
namespace = "com.google.android.fhir.workflow.benchmark"
compileSdk = Sdk.compileSdk
defaultConfig {
minSdk = Sdk.minSdk
Expand Down Expand Up @@ -71,10 +71,7 @@ dependencies {
androidTestImplementation(Dependencies.truth)
androidTestImplementation(Dependencies.Androidx.workRuntimeKtx)
androidTestImplementation(Dependencies.AndroidxTest.workTestingRuntimeKtx)
androidTestImplementation(Dependencies.mockWebServer)
androidTestImplementation(Dependencies.Retrofit.coreRetrofit)

androidTestImplementation(project(":engine"))
androidTestImplementation(Dependencies.androidFhirEngine) { exclude(module = "truth") }
androidTestImplementation(project(":knowledge")) {
exclude(group = Dependencies.androidFhirGroup, module = Dependencies.androidFhirEngineModule)
}
Expand Down
23 changes: 23 additions & 0 deletions workflow/benchmark/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<manifest
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:tools="http:https://schemas.android.com/tools"
>

<!--
Important: disable debugging for accurate performance results
In a com.android.library project, this flag must be disabled from this
manifest, as it is not possible to override this flag from Gradle.
-->
<application
android:debuggable="false"
tools:ignore="HardcodedDebugMode"
tools:replace="android:debuggable"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
>
<profileable android:shell="true" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2022-2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.android.fhir.benchmark
package com.google.android.fhir.workflow.benchmark

import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2022-2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.android.fhir.benchmark
package com.google.android.fhir.workflow.benchmark

import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2022-2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.android.fhir.benchmark
package com.google.android.fhir.workflow.benchmark

import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Google LLC
* Copyright 2022-2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.android.fhir.benchmark
package com.google.android.fhir.workflow.benchmark

import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
Expand Down

0 comments on commit 14e1277

Please sign in to comment.