Skip to content

Commit 3bf9224

Browse files
wip got benchmark traces working
1 parent 15ecc74 commit 3bf9224

File tree

17 files changed

+259
-20
lines changed

17 files changed

+259
-20
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
23+
-dontobfuscate
24+
25+
-ignorewarnings
26+
27+
-keepattributes *Annotation*
28+
29+
-dontnote junit.framework.**
30+
-dontnote junit.runner.**
31+
32+
-dontwarn androidx.test.**
33+
-dontwarn org.junit.**
34+
-dontwarn org.hamcrest.**
35+
-dontwarn com.squareup.javawriter.JavaWriter
36+
37+
-keepclasseswithmembers @org.junit.runner.RunWith public class *

benchmarks/compose-workflow/build.gradle.kts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,64 @@
1+
import com.rickbusarow.kgx.libsCatalog
2+
import com.rickbusarow.kgx.version
3+
import com.squareup.workflow1.buildsrc.internal.javaTarget
4+
import com.squareup.workflow1.buildsrc.internal.javaTargetVersion
5+
16
plugins {
2-
id("com.android.application")
7+
id("com.android.library")
38
id("kotlin-android")
4-
id("android-defaults")
9+
// id("android-defaults")
10+
alias(libs.plugins.androidx.benchmark)
511
alias(libs.plugins.compose.compiler)
612
}
713

814
// Note: We are not including our defaults from .buildscript as we do not need the base Workflow
915
// dependencies that those include.
1016

1117
android {
18+
compileSdk = libsCatalog.version("compileSdk").toInt()
19+
20+
compileOptions {
21+
sourceCompatibility = javaTargetVersion
22+
targetCompatibility = javaTargetVersion
23+
}
24+
25+
kotlinOptions {
26+
jvmTarget = javaTarget
27+
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
28+
}
29+
1230
defaultConfig {
31+
minSdk = 28
32+
targetSdk = libsCatalog.version("targetSdk").toInt()
33+
1334
// TODO why isn't this taking?
1435
testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner"
36+
37+
// must be one of: 'None', 'StackSampling', or 'MethodTracing'
38+
testInstrumentationRunnerArguments["androidx.benchmark.profiling.mode"] = "MethodTracing"
39+
testInstrumentationRunnerArguments["androidx.benchmark.output.enable"] = "true"
1540
}
1641

42+
// buildTypes {
43+
// debug {
44+
// isDebuggable = false
45+
// isProfileable = true
46+
// }
47+
// }
48+
49+
testBuildType = "release"
50+
// testBuildType = "debug"
1751
buildTypes {
1852
debug {
19-
isDebuggable = false
53+
// Since isDebuggable can"t be modified by gradle for library modules,
54+
// it must be done in a manifest - see src/androidTest/AndroidManifest.xml
55+
isMinifyEnabled = true
56+
proguardFiles(
57+
getDefaultProguardFile("proguard-android-optimize.txt"), "benchmark-proguard-rules.pro"
58+
)
59+
}
60+
release {
61+
isDefault = true
2062
}
2163
}
2264

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<!--
6+
Important: disable debugging for accurate performance results
7+
8+
In a com.android.library project, this flag must be disabled from this
9+
manifest, as it is not possible to override this flag from Gradle.
10+
-->
11+
<application
12+
android:debuggable="false"
13+
tools:ignore="HardcodedDebugMode"
14+
tools:replace="android:debuggable">
15+
<profileable android:shell="true"/>
16+
</application>
317
</manifest>

benchmarks/compose-workflow/src/androidTest/baseline-proguard-rules.pro

Lines changed: 0 additions & 1 deletion
This file was deleted.

benchmarks/cw2/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
23+
-dontobfuscate
24+
25+
-ignorewarnings
26+
27+
-keepattributes *Annotation*
28+
29+
-dontnote junit.framework.**
30+
-dontnote junit.runner.**
31+
32+
-dontwarn androidx.test.**
33+
-dontwarn org.junit.**
34+
-dontwarn org.hamcrest.**
35+
-dontwarn com.squareup.javawriter.JavaWriter
36+
37+
-keepclasseswithmembers @org.junit.runner.RunWith public class *

benchmarks/cw2/build.gradle.kts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import com.rickbusarow.kgx.libsCatalog
2+
import com.rickbusarow.kgx.version
3+
import com.squareup.workflow1.buildsrc.internal.javaTarget
4+
import com.squareup.workflow1.buildsrc.internal.javaTargetVersion
5+
6+
plugins {
7+
id("com.android.library")
8+
id("kotlin-android")
9+
alias(libs.plugins.androidx.benchmark)
10+
}
11+
12+
android {
13+
namespace = "com.example.cw2"
14+
compileSdk = libsCatalog.version("compileSdk").toInt()
15+
16+
defaultConfig {
17+
minSdk = 28
18+
targetSdk = libsCatalog.version("targetSdk").toInt()
19+
20+
testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner"
21+
}
22+
23+
testBuildType = "release"
24+
buildTypes {
25+
debug {
26+
// Since isDebuggable can"t be modified by gradle for library modules,
27+
// it must be done in a manifest - see src/androidTest/AndroidManifest.xml
28+
isMinifyEnabled = true
29+
proguardFiles(
30+
getDefaultProguardFile("proguard-android-optimize.txt"), "benchmark-proguard-rules.pro"
31+
)
32+
}
33+
release {
34+
isDefault = true
35+
}
36+
}
37+
compileOptions {
38+
sourceCompatibility = javaTargetVersion
39+
targetCompatibility = javaTargetVersion
40+
}
41+
kotlinOptions {
42+
jvmTarget = javaTarget
43+
}
44+
}
45+
46+
dependencies {
47+
androidTestImplementation(libs.androidx.test.runner)
48+
androidTestImplementation(libs.androidx.test.junit)
49+
androidTestImplementation(libs.junit)
50+
androidTestImplementation(libs.androidx.benchmark)
51+
// Add your dependencies here. Note that you cannot benchmark code
52+
// in an app module this way - you will need to move any code you
53+
// want to benchmark to a library module:
54+
// https://developer.android.com/studio/projects/android-library#Convert
55+
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
<!--
6+
Important: disable debugging for accurate performance results
7+
8+
In a com.android.library project, this flag must be disabled from this
9+
manifest, as it is not possible to override this flag from Gradle.
10+
-->
11+
<application
12+
android:debuggable="false"
13+
tools:ignore="HardcodedDebugMode"
14+
tools:replace="android:debuggable" />
15+
</manifest>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.example.cw2
2+
3+
import android.util.Log
4+
import androidx.benchmark.junit4.BenchmarkRule
5+
import androidx.benchmark.junit4.measureRepeated
6+
import androidx.test.ext.junit.runners.AndroidJUnit4
7+
import org.junit.Rule
8+
import org.junit.Test
9+
import org.junit.runner.RunWith
10+
11+
/**
12+
* Benchmark, which will execute on an Android device.
13+
*
14+
* The body of [BenchmarkRule.measureRepeated] is measured in a loop, and Studio will
15+
* output the result. Modify your code to see how it affects performance.
16+
*/
17+
@RunWith(AndroidJUnit4::class)
18+
class ExampleBenchmark {
19+
20+
@get:Rule
21+
val benchmarkRule = BenchmarkRule()
22+
23+
@Test
24+
fun log() {
25+
benchmarkRule.measureRepeated {
26+
Log.d("LogBenchmark", "the cost of writing this log method will be measured")
27+
}
28+
}
29+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest />

0 commit comments

Comments
 (0)