Skip to content

Commit 26651e0

Browse files
Make baseline profile generators independently copyable
Remove dependency on BaselineProfileGeneratorScaffold. This makes it easier to copy each generator into a separate project.
1 parent 8ca6d63 commit 26651e0

File tree

5 files changed

+72
-114
lines changed

5 files changed

+72
-114
lines changed

MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/BaselineProfileGeneratorScaffold.kt

Lines changed: 0 additions & 52 deletions
This file was deleted.

MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/ComposeActivityBaselineProfileGenerator.kt

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,41 @@
1717
package com.example.macrobenchmark.baselineprofile
1818

1919
import android.content.Intent
20-
import androidx.benchmark.macro.MacrobenchmarkScope
21-
import androidx.test.ext.junit.runners.AndroidJUnit4
20+
import androidx.benchmark.macro.junit4.BaselineProfileRule
21+
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
2222
import androidx.test.uiautomator.By
2323
import androidx.test.uiautomator.Direction
2424
import com.example.macrobenchmark.benchmark.util.findOrFail
2525
import com.example.macrobenchmark.benchmark.util.waitAndFind
2626
import org.junit.Ignore
27+
import org.junit.Rule
28+
import org.junit.Test
2729
import org.junit.runner.RunWith
2830

2931
@Ignore // TODO causing stale object excpetion on CI .. why?
30-
@RunWith(AndroidJUnit4::class)
31-
class ComposeActivityBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
32+
@RunWith(AndroidJUnit4ClassRunner::class)
33+
class ComposeActivityBaselineProfileGenerator {
3234

33-
override fun MacrobenchmarkScope.profileBlock() {
34-
// Start into the Compose Activity
35-
startActivityAndWait(Intent("$TARGET_PACKAGE.COMPOSE_ACTIVITY"))
35+
@get:Rule
36+
val rule = BaselineProfileRule()
3637

37-
// Scrolling through the Compose journey
38-
device.waitAndFind(By.res("myLazyColumn")).also {
39-
it.setGestureMargin(device.displayWidth / 10)
40-
it.fling(Direction.DOWN)
41-
}
38+
@Test
39+
fun generate() {
40+
rule.collect(
41+
packageName = TARGET_PACKAGE,
42+
maxIterations = 15,
43+
stableIterations = 3
44+
) {
45+
// Start into the Compose Activity
46+
startActivityAndWait(Intent("$TARGET_PACKAGE.COMPOSE_ACTIVITY"))
47+
48+
// Scrolling through the Compose journey
49+
device.waitAndFind(By.res("myLazyColumn")).also {
50+
it.setGestureMargin(device.displayWidth / 10)
51+
it.fling(Direction.DOWN)
52+
}
4253

43-
device.findOrFail(By.res("myLazyColumn")).fling(Direction.UP)
54+
device.findOrFail(By.res("myLazyColumn")).fling(Direction.UP)
55+
}
4456
}
4557
}

MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/LoginBaselineProfileGenerator.kt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,31 @@
1717
package com.example.macrobenchmark.baselineprofile
1818

1919
import android.content.Intent
20-
import androidx.benchmark.macro.MacrobenchmarkScope
20+
import androidx.benchmark.macro.junit4.BaselineProfileRule
21+
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
2122
import androidx.test.uiautomator.By
23+
import org.junit.Rule
24+
import org.junit.Test
25+
import org.junit.runner.RunWith
2226

23-
class LoginBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
27+
@RunWith(AndroidJUnit4ClassRunner::class)
28+
class LoginBaselineProfileGenerator {
2429

25-
override fun MacrobenchmarkScope.profileBlock() {
26-
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY"))
27-
device.findObject(By.res("userName")).text = "user"
28-
device.findObject(By.res("password")).text = "password"
29-
device.findObject(By.res("login")).click()
30-
device.waitForIdle()
30+
@get:Rule
31+
val rule = BaselineProfileRule()
32+
33+
@Test
34+
fun generate() {
35+
rule.collect(
36+
packageName = TARGET_PACKAGE,
37+
maxIterations = 15,
38+
stableIterations = 3
39+
) {
40+
startActivityAndWait(Intent("$packageName.LOGIN_ACTIVITY"))
41+
device.findObject(By.res("userName")).text = "user"
42+
device.findObject(By.res("password")).text = "password"
43+
device.findObject(By.res("login")).click()
44+
device.waitForIdle()
45+
}
3146
}
3247
}

MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/RecyclerViewActivityBaselineProfileGenerator.kt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,38 @@
1717
package com.example.macrobenchmark.baselineprofile
1818

1919
import android.content.Intent
20-
import androidx.benchmark.macro.MacrobenchmarkScope
21-
import androidx.test.ext.junit.runners.AndroidJUnit4
20+
import androidx.benchmark.macro.junit4.BaselineProfileRule
21+
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
2222
import androidx.test.uiautomator.By
2323
import androidx.test.uiautomator.Direction
2424
import org.junit.Ignore
25+
import org.junit.Rule
26+
import org.junit.Test
2527
import org.junit.runner.RunWith
2628

2729
@Ignore // TODO flinging not working, ignore for now to test the pipeline
28-
@RunWith(AndroidJUnit4::class)
29-
class RecyclerViewActivityBaselineProfileGenerator : BaselineProfileGeneratorScaffold() {
30+
@RunWith(AndroidJUnit4ClassRunner::class)
31+
class RecyclerViewActivityBaselineProfileGenerator {
3032

31-
override fun MacrobenchmarkScope.profileBlock() {
32-
// Start into the RecyclerViewActivity
33-
startActivityAndWait(Intent("$TARGET_PACKAGE.RECYCLER_VIEW_ACTIVITY"))
33+
@get:Rule
34+
val rule = BaselineProfileRule()
3435

35-
// Scrolling RecyclerView journey
36-
device.findObject(By.res(packageName, "recycler")).also {
37-
it.setGestureMargin(device.displayWidth / 10)
38-
it.fling(Direction.DOWN)
39-
it.fling(Direction.UP)
36+
@Test
37+
fun generate() {
38+
rule.collect(
39+
packageName = TARGET_PACKAGE,
40+
maxIterations = 15,
41+
stableIterations = 3
42+
) {
43+
// Start into the RecyclerViewActivity
44+
startActivityAndWait(Intent("$TARGET_PACKAGE.RECYCLER_VIEW_ACTIVITY"))
45+
46+
// Scrolling RecyclerView journey
47+
device.findObject(By.res(packageName, "recycler")).also {
48+
it.setGestureMargin(device.displayWidth / 10)
49+
it.fling(Direction.DOWN)
50+
it.fling(Direction.UP)
51+
}
4052
}
4153
}
4254
}

MacrobenchmarkSample/macrobenchmark/src/main/kotlin/com/example/macrobenchmark/baselineprofile/StartupOnlyBaselineProfileGenerator.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)