Skip to content

Commit 9e84066

Browse files
committed
Merge branch 'main' into bot/update-baseline-profiles
# Conflicts: # MacrobenchmarkSample/app/build.gradle.kts # MacrobenchmarkSample/baselineProfile/build.gradle.kts # MacrobenchmarkSample/baselineProfile/src/main/java/com/example/macrobenchmark/baselineprofile/BaselineProfileGeneratorScaffold.kt # MacrobenchmarkSample/baselineProfile/src/main/java/com/example/macrobenchmark/baselineprofile/RecyclerViewActivityBaselineProfileGenerator.kt # MacrobenchmarkSample/gradle/libs.versions.toml # MacrobenchmarkSample/macrobenchmark/build.gradle.kts
2 parents f0713be + 8e71615 commit 9e84066

File tree

19 files changed

+710
-2139
lines changed

19 files changed

+710
-2139
lines changed

MacrobenchmarkSample/app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ plugins {
2121
}
2222

2323
android {
24-
compileSdk = 33
24+
compileSdk = 34
2525
namespace = "com.example.macrobenchmark.target"
2626

2727
defaultConfig {
2828
applicationId = "com.example.macrobenchmark.target"
2929
versionCode = 1
3030
versionName = "1.0"
31+
targetSdk = 34
3132
minSdk = 21
32-
targetSdk = 33
3333
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3434
}
3535

MacrobenchmarkSample/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
44

5+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
6+
57
<application
68
android:name=".ExampleApplication"
79
android:allowBackup="false"

MacrobenchmarkSample/app/src/main/java/com/example/macrobenchmark/target/activity/FullyDrawnStartupActivity.kt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ package com.example.macrobenchmark.target.activity
1818

1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
21-
import androidx.activity.compose.ReportDrawnAfter
21+
import androidx.activity.compose.ReportDrawnWhen
2222
import androidx.activity.compose.setContent
2323
import androidx.activity.viewModels
24+
import androidx.compose.foundation.layout.Column
25+
import androidx.compose.material.CircularProgressIndicator
2426
import androidx.compose.material.Text
25-
import androidx.compose.runtime.Composable
27+
import androidx.compose.runtime.LaunchedEffect
28+
import androidx.compose.runtime.getValue
29+
import androidx.compose.runtime.mutableStateOf
30+
import androidx.compose.runtime.remember
31+
import androidx.compose.runtime.setValue
2632
import com.example.macrobenchmark.target.util.SampleViewModel
2733

2834
class FullyDrawnStartupActivity : ComponentActivity() {
@@ -32,15 +38,21 @@ class FullyDrawnStartupActivity : ComponentActivity() {
3238
override fun onCreate(savedInstanceState: Bundle?) {
3339
super.onCreate(savedInstanceState)
3440
setContent {
35-
TextBlock("Compose Macrobenchmark Target")
36-
ReportDrawnAfter {
37-
sampleViewModel.data.isReady()
41+
var isLoaded by remember { mutableStateOf(false) }
42+
ReportDrawnWhen { isLoaded }
43+
44+
LaunchedEffect(Unit) {
45+
isLoaded = sampleViewModel.data.isReady()
3846
}
39-
}
40-
}
4147

42-
@Composable
43-
fun TextBlock(text: String) {
44-
Text(text)
48+
Column {
49+
Text("Compose Macrobenchmark Target")
50+
if (!isLoaded) {
51+
CircularProgressIndicator()
52+
} else {
53+
Text("Fully Drawn")
54+
}
55+
}
56+
}
4557
}
46-
}
58+
}

MacrobenchmarkSample/app/src/main/java/com/example/macrobenchmark/target/util/Data.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616

1717
package com.example.macrobenchmark.target.util
1818

19-
import kotlinx.coroutines.CoroutineScope
2019
import kotlinx.coroutines.Dispatchers
2120
import kotlinx.coroutines.delay
22-
import kotlinx.coroutines.launch
21+
import kotlinx.coroutines.withContext
2322
import java.util.Random
2423

2524
/** Pretending to load data from a remote source */
2625
class SampleData {
2726
private val random = Random()
2827
suspend fun isReady(): Boolean {
29-
CoroutineScope(Dispatchers.Default).launch {
30-
delay(random.nextInt(500).toLong())
28+
withContext(Dispatchers.Default) {
29+
delay(1000 + random.nextInt(1000).toLong())
3130
}
3231
return true
3332
}

MacrobenchmarkSample/baseBenchmarks/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ plugins {
2121

2222
android {
2323
namespace = "com.example.benchmark.macro.base"
24-
compileSdk = 33
24+
compileSdk = 34
2525

2626
defaultConfig {
2727
minSdk = 23

MacrobenchmarkSample/baselineProfile/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugins {
2323

2424
android {
2525
namespace = "com.example.benchmark.baselinprofile"
26-
compileSdk = 33
26+
compileSdk = 34
2727

2828
compileOptions {
2929
sourceCompatibility = JavaVersion.VERSION_17
@@ -38,7 +38,7 @@ android {
3838
// Minimum supported version for Baseline Profiles.
3939
// On lower APIs, apps are fully AOT compile, therefore Baseline Profiles aren't needed.
4040
minSdk = 24
41-
targetSdk = 33
41+
targetSdk = 34
4242

4343
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
4444
}

MacrobenchmarkSample/baselineProfile/src/main/java/com/example/macrobenchmark/baselineprofile/BaselineProfileGeneratorScaffold.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
package com.example.macrobenchmark.baselineprofile
1818

19-
import androidx.benchmark.macro.ExperimentalStableBaselineProfilesApi
19+
import android.os.Build
20+
import androidx.annotation.RequiresApi
2021
import androidx.benchmark.macro.MacrobenchmarkScope
2122
import androidx.benchmark.macro.junit4.BaselineProfileRule
2223
import androidx.test.ext.junit.runners.AndroidJUnit4
23-
import androidx.test.uiautomator.Tracer
24-
import org.junit.BeforeClass
2524
import org.junit.Rule
2625
import org.junit.Test
2726
import org.junit.runner.RunWith
@@ -31,29 +30,20 @@ import org.junit.runner.RunWith
3130
* start generating a profile directly by implementing [MacrobenchmarkScope.profileBlock].
3231
*/
3332
@RunWith(AndroidJUnit4::class)
33+
@RequiresApi(Build.VERSION_CODES.P)
3434
abstract class BaselineProfileGeneratorScaffold {
3535

3636
@get:Rule
3737
val rule = BaselineProfileRule()
38-
39-
40-
companion object {
41-
@BeforeClass
42-
@JvmStatic
43-
fun beforeClass() {
44-
Tracer.getInstance().setOutputMode(Tracer.Mode.LOGCAT)
45-
}
46-
}
47-
38+
4839
/**
4940
* Generate a baseline profile in this function.
5041
*/
5142
abstract fun MacrobenchmarkScope.profileBlock()
5243

53-
@OptIn(ExperimentalStableBaselineProfilesApi::class)
5444
@Test
5545
fun profileGenerator() {
56-
rule.collectStableBaselineProfile(
46+
rule.collect(
5747
packageName = TARGET_PACKAGE,
5848
maxIterations = 10
5949
) {

0 commit comments

Comments
 (0)