Skip to content

Commit 249db05

Browse files
Add Baseline Profile Gradle Plugin (#229)
--------- Co-authored-by: Ben Weiss <[email protected]>
1 parent 0afea7e commit 249db05

17 files changed

+199
-124
lines changed

.github/workflows/macrobenchmark.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ jobs:
2121
macrobenchmark: ${{ steps.filter.outputs.macrobenchmark }}
2222
steps:
2323
- name: Checkout
24-
uses: actions/checkout@v2
25-
with:
26-
fetch-depth: 1
24+
uses: actions/checkout@v3
2725
- uses: dorny/paths-filter@v2
2826
id: filter
2927
with:
@@ -34,13 +32,14 @@ jobs:
3432
build:
3533
needs: changes
3634
# Only run action for the main repo & not forks and if change is in macrobenchmark sample
37-
if: github.repository_owner == 'android' && needs.changes.outputs.macrobenchmark == 'true'
38-
runs-on: ubuntu-latest
35+
if: github.repository_owner == 'android' && (needs.changes.outputs.macrobenchmark == 'true' || github.event_name == 'workflow_dispatch')
36+
runs-on: macos-latest
37+
defaults:
38+
run:
39+
working-directory: ./MacrobenchmarkSample
3940
steps:
4041
- name: Checkout
4142
uses: actions/checkout@v3
42-
with:
43-
fetch-depth: 1
4443

4544
- name: Setup JDK
4645
id: setup-java
@@ -49,12 +48,13 @@ jobs:
4948
java-version: '17'
5049
distribution: 'zulu'
5150

52-
- name: Build Macrobenchmark Sample
53-
uses: eskatos/gradle-command-action@v1
54-
env:
55-
JAVA_HOME: ${{ steps.setup-java.outputs.path }}
51+
- name: Setup Gradle
52+
uses: gradle/gradle-build-action@v2
5653
with:
57-
arguments: build
58-
build-root-directory: ${{ github.workspace }}/MacrobenchmarkSample
59-
gradle-executable: ${{ github.workspace }}/MacrobenchmarkSample/gradlew
60-
wrapper-directory: ${{ github.workspace }}/MacrobenchmarkSample/gradle/wrapper
54+
gradle-home-cache-cleanup: true
55+
56+
- name: Build Macrobenchmark Sample
57+
run: >
58+
./gradlew assemble \
59+
-x :baselineProfile:pixel6Api31NonMinifiedReleaseAndroidTest \
60+
-x :baselineProfile:collectNonMinifiedReleaseBaselineProfile

MacrobenchmarkSample/app/build.gradle.kts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
*/
1616

1717
plugins {
18-
id("com.android.application")
19-
id("kotlin-android")
18+
alias(libs.plugins.application)
19+
alias(libs.plugins.kotlin)
20+
alias(libs.plugins.baselineprofile)
2021
}
2122

2223
android {
2324
compileSdk = 34
2425
namespace = "com.example.macrobenchmark.target"
2526

2627
defaultConfig {
27-
applicationId ="com.example.macrobenchmark.target"
28+
applicationId = "com.example.macrobenchmark.target"
2829
versionCode = 1
2930
versionName = "1.0"
3031
minSdk = 23 // Minimum supported version for macrobenchmark
@@ -46,7 +47,10 @@ android {
4647
val release = getByName("release") {
4748
isMinifyEnabled = true
4849
isShrinkResources = true
49-
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
50+
proguardFiles(
51+
getDefaultProguardFile("proguard-android-optimize.txt"),
52+
"proguard-rules.pro"
53+
)
5054
}
5155

5256
create("benchmark") {
@@ -62,11 +66,11 @@ android {
6266
// [END macrobenchmark_setup_app_build_type]
6367

6468
compileOptions {
65-
sourceCompatibility = JavaVersion.VERSION_17
66-
targetCompatibility = JavaVersion.VERSION_17
69+
sourceCompatibility = JavaVersion.VERSION_11
70+
targetCompatibility = JavaVersion.VERSION_11
6771
}
6872
kotlinOptions {
69-
jvmTarget = JavaVersion.VERSION_17.toString()
73+
jvmTarget = JavaVersion.VERSION_11.toString()
7074
freeCompilerArgs = freeCompilerArgs + listOf(
7175
"-opt-in=kotlin.RequiresOptIn"
7276
)
@@ -90,11 +94,12 @@ dependencies {
9094
implementation(libs.google.material)
9195
implementation(libs.kotlin.coroutines)
9296
implementation(libs.kotlin.coroutines.guava)
93-
implementation(libs.kotlin.stdlib)
9497
implementation(libs.lifecycle)
9598
implementation(libs.profileinstaller)
9699
implementation(libs.squareup.curtains)
97100
implementation(libs.tracing)
98101
implementation(libs.viewmodel)
99102
androidTestImplementation(libs.benchmark.junit)
103+
104+
baselineProfile(project(":baselineProfile"))
100105
}
Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,21 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
3-
~ Copyright 2022 The Android Open Source Project
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-
182
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
193
xmlns:tools="http://schemas.android.com/tools">
204

215
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
226

237
<application
8+
android:name=".ExampleApplication"
249
android:allowBackup="false"
2510
android:icon="@mipmap/ic_launcher"
2611
android:label="@string/app_notice"
2712
android:roundIcon="@mipmap/ic_launcher_round"
2813
android:supportsRtl="true"
29-
android:theme="@style/Theme.Macrobenchmarktarget"
30-
android:name=".ExampleApplication"
31-
>
32-
<!-- [START macrobenchmark_setup_profileable] -->
33-
<!-- enable profiling by macrobenchmark -->
14+
android:theme="@style/Theme.Macrobenchmarktarget">
3415
<profileable
3516
android:shell="true"
36-
tools:targetApi="q" />
17+
tools:targetApi="29,q" />
3718
<!-- [END macrobenchmark_setup_profileable] -->
38-
3919
<!--
4020
Activities need to be exported so the Macrobenchmarks can discover them
4121
under the new package visibility changes for Android 11.
@@ -50,66 +30,62 @@
5030
<category android:name="android.intent.category.LAUNCHER" />
5131
</intent-filter>
5232
</activity>
53-
5433
<activity
5534
android:name=".activity.clicklatency.ComposeActivity"
5635
android:exported="true">
5736
<intent-filter>
5837
<action android:name="com.example.macrobenchmark.target.COMPOSE_ACTIVITY" />
38+
5939
<category android:name="android.intent.category.DEFAULT" />
6040
</intent-filter>
6141
</activity>
62-
6342
<activity
6443
android:name=".activity.FullyDrawnStartupActivity"
6544
android:exported="true">
6645
<intent-filter>
6746
<action android:name="com.example.macrobenchmark.target.FULLY_DRAWN_STARTUP_ACTIVITY" />
47+
6848
<category android:name="android.intent.category.DEFAULT" />
6949
</intent-filter>
7050
</activity>
71-
7251
<activity
7352
android:name=".activity.clicklatency.ListViewActivity"
7453
android:exported="true">
7554
<intent-filter>
7655
<action android:name="com.example.macrobenchmark.target.LIST_VIEW_ACTIVITY" />
56+
7757
<category android:name="android.intent.category.DEFAULT" />
7858
</intent-filter>
7959
</activity>
80-
8160
<activity
8261
android:name=".activity.login.LoginActivity"
8362
android:exported="true">
8463
<intent-filter>
8564
<action android:name="com.example.macrobenchmark.target.LOGIN_ACTIVITY" />
65+
8666
<category android:name="android.intent.category.DEFAULT" />
8767
</intent-filter>
88-
</activity>
89-
90-
<!-- non-exported activities -->
68+
</activity> <!-- non-exported activities -->
9169
<activity android:name=".activity.clicklatency.NonExportedRecyclerActivity" />
92-
9370
<activity android:name=".activity.clicklatency.NestedRecyclerActivity" />
94-
9571
<activity
9672
android:name=".activity.clicklatency.RecyclerViewActivity"
9773
android:exported="true">
9874
<intent-filter>
9975
<action android:name="com.example.macrobenchmark.target.RECYCLER_VIEW_ACTIVITY" />
76+
10077
<category android:name="android.intent.category.DEFAULT" />
10178
</intent-filter>
10279
</activity>
103-
10480
<activity
10581
android:name=".activity.clicklatency.ScrollViewActivity"
10682
android:exported="true">
10783
<intent-filter>
10884
<action android:name="com.example.macrobenchmark.target.SCROLL_VIEW_ACTIVITY" />
85+
10986
<category android:name="android.intent.category.DEFAULT" />
11087
</intent-filter>
11188
</activity>
112-
11389
</application>
11490

115-
</manifest>
91+
</manifest>

MacrobenchmarkSample/baseBenchmarks/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ android {
4040
}
4141
}
4242
compileOptions {
43-
sourceCompatibility = JavaVersion.VERSION_17
44-
targetCompatibility = JavaVersion.VERSION_17
43+
sourceCompatibility = JavaVersion.VERSION_11
44+
targetCompatibility = JavaVersion.VERSION_11
4545
}
4646
kotlinOptions {
47-
jvmTarget = JavaVersion.VERSION_17.toString()
47+
jvmTarget = JavaVersion.VERSION_11.toString()
4848
}
4949
}
5050

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2023 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+
plugins {
18+
alias(libs.plugins.kotlin)
19+
alias(libs.plugins.test)
20+
alias(libs.plugins.baselineprofile)
21+
22+
}
23+
24+
android {
25+
namespace = "com.example.benchmark.baselinprofile"
26+
compileSdk = 34
27+
28+
compileOptions {
29+
sourceCompatibility = JavaVersion.VERSION_17
30+
targetCompatibility = JavaVersion.VERSION_17
31+
}
32+
33+
kotlinOptions {
34+
jvmTarget = JavaVersion.VERSION_17.toString()
35+
}
36+
37+
defaultConfig {
38+
// Minimum supported version for Baseline Profiles.
39+
// On lower APIs, apps are fully AOT compile, therefore Baseline Profiles aren't needed.
40+
minSdk = 24
41+
targetSdk = 34
42+
43+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
44+
}
45+
46+
testOptions.managedDevices.devices {
47+
create<com.android.build.api.dsl.ManagedVirtualDevice>("pixel6Api31") {
48+
device = "Pixel 6"
49+
apiLevel = 31
50+
systemImageSource = "aosp"
51+
}
52+
}
53+
54+
targetProjectPath = ":app"
55+
}
56+
57+
baselineProfile {
58+
59+
// This specifies the managed devices to use that you run the tests on. The default
60+
// is none.
61+
managedDevices += "pixel6Api31"
62+
63+
// This enables using connected devices to generate profiles. The default is true.
64+
// When using connected devices, they must be rooted or API 33 and higher.
65+
useConnectedDevices = false
66+
}
67+
68+
dependencies {
69+
implementation(libs.benchmark.junit)
70+
implementation(libs.androidx.junit)
71+
implementation(libs.espresso)
72+
implementation(libs.ui.automator)
73+
}
74+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2023 The Android Open Source Project
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+
18+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
19+
20+
<queries>
21+
<package android:name="com.example.macrobenchmark.target" />
22+
</queries>
23+
</manifest>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import androidx.annotation.RequiresApi
2121
import androidx.benchmark.macro.MacrobenchmarkScope
2222
import androidx.benchmark.macro.junit4.BaselineProfileRule
2323
import androidx.test.ext.junit.runners.AndroidJUnit4
24-
import com.example.benchmark.macro.base.util.TARGET_PACKAGE
2524
import org.junit.Rule
2625
import org.junit.Test
2726
import org.junit.runner.RunWith
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2023 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.example.macrobenchmark.baselineprofile
18+
19+
const val TARGET_PACKAGE = "com.example.macrobenchmark.target"

0 commit comments

Comments
 (0)