1
1
package com.squareup.benchmarks.performance.complex.poetry.benchmark
2
2
3
3
import android.content.Context
4
+ import android.content.Intent
4
5
import androidx.benchmark.macro.BaselineProfileMode
5
6
import androidx.benchmark.macro.CompilationMode
6
7
import androidx.benchmark.macro.ExperimentalMetricApi
7
- import androidx.benchmark.macro.FrameTimingMetric
8
8
import androidx.benchmark.macro.StartupMode
9
9
import androidx.benchmark.macro.StartupTimingMetric
10
10
import androidx.benchmark.macro.TraceSectionMetric
@@ -13,8 +13,11 @@ import androidx.test.core.app.ApplicationProvider
13
13
import androidx.test.ext.junit.runners.AndroidJUnit4
14
14
import androidx.test.platform.app.InstrumentationRegistry
15
15
import androidx.test.uiautomator.UiDevice
16
+ import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity
17
+ import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion
16
18
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.PerformanceTracingInterceptor
17
19
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.PerformanceTracingInterceptor.Companion.NODES_TO_TRACE
20
+ import com.squareup.benchmarks.performance.complex.poetry.instrumentation.SimulatedPerfConfig
18
21
import com.squareup.benchmarks.performance.complex.poetry.robots.landscapeOrientation
19
22
import com.squareup.benchmarks.performance.complex.poetry.robots.openRavenAndNavigate
20
23
import org.junit.Before
@@ -27,14 +30,13 @@ import org.junit.runner.RunWith
27
30
* info.
28
31
*
29
32
* [benchmarkStartup] will measure startup times with different compilation modes.
33
+ * The above can be run as tests using Full, Partial, or No aot compiling on the app.
30
34
*
31
- * [benchmarkTraceSections ] will measure the trace timings instrumented via the
35
+ * [benchmarkNodeAndRenderPassTraceSections ] will measure the trace timings instrumented via the
32
36
* [PerformanceTracingInterceptor] installed by default in the Workflow tree.
33
37
*
34
- * [benchmarkFrameTiming] measures frame timing but it is still WIP and not useful in its current
35
- * form as there is not enough scrolling/animation in the scenario.
36
- *
37
- * The above can be run as tests using Full, Partial, or No aot compiling on the app.
38
+ * [benchmarkLatencyTraceSections] will measure the time between a UI event to producing a
39
+ * Rendering and the time between the Rendering and the Choreographer rendering the frame.
38
40
*/
39
41
@RunWith(AndroidJUnit4 ::class )
40
42
class ComplexPoetryBenchmarks {
@@ -78,16 +80,16 @@ class ComplexPoetryBenchmarks {
78
80
}
79
81
80
82
/* *
81
- * This is a LONG test. Searching and pulling form the perfetto trace after each
83
+ * This is a LONG test. Searching and pulling form the Perfetto trace after each
82
84
* iteration takes a long time. This test with 20 iterations runs for 1 hr 12 m on
83
85
* a Nexus 6.
84
86
*/
85
- @Test fun benchmarkTraceSectionsFullAOT () {
86
- benchmarkTraceSections (CompilationMode .Full ())
87
+ @Test fun benchmarkNodeAndRenderPassTraceSectionsFullAot () {
88
+ benchmarkNodeAndRenderPassTraceSections (CompilationMode .Full ())
87
89
}
88
90
89
91
@OptIn(ExperimentalMetricApi ::class )
90
- private fun benchmarkTraceSections (compilationMode : CompilationMode ) {
92
+ private fun benchmarkNodeAndRenderPassTraceSections (compilationMode : CompilationMode ) {
91
93
val traceMetricsList = NODES_TO_TRACE .flatMap { node ->
92
94
List (RENDER_PASSES + 1 ) { i ->
93
95
val passNumber = i.toString()
@@ -110,50 +112,121 @@ class ComplexPoetryBenchmarks {
110
112
compilationMode = compilationMode,
111
113
setupBlock = {
112
114
pressHome()
115
+ device.landscapeOrientation()
113
116
}
114
117
) {
118
+ startActivityAndWait{
119
+ val renderPassConfig = SimulatedPerfConfig (
120
+ isComplex = true ,
121
+ complexityDelay = 200L ,
122
+ useInitializingState = true ,
123
+ traceRenderingPasses = true ,
124
+ traceLatency = false
125
+ )
126
+ it.putExtra(PerformancePoetryActivity .PERF_CONFIG_EXTRA , renderPassConfig)
127
+ }
115
128
device.landscapeOrientation()
116
- // Use default performance config for now, so no need to customize intent.
117
- startActivityAndWait()
118
129
119
130
device.openRavenAndNavigate()
120
131
}
121
132
}
122
133
123
- @Test fun benchmarkFrameTimingNoCompilation () {
124
- benchmarkFrameTiming(CompilationMode .None ())
125
- }
126
-
127
- @Test fun benchmarkFrameTimingPartialAOTWithProfile () {
128
- benchmarkFrameTiming(CompilationMode .Partial (baselineProfileMode = BaselineProfileMode .Require ))
129
- }
130
-
131
- @Test fun benchmarkFrameTimingFullAOT () {
132
- benchmarkFrameTiming(CompilationMode .Full ())
134
+ /* *
135
+ * Another LONG test.
136
+ */
137
+ @Test fun benchmarkLatencyTraceSectionsFullAot () {
138
+ benchmarkLatencyTraceSections(CompilationMode .Full ())
133
139
}
134
140
141
+ /* *
142
+ * This test is focused on two different measurements:
143
+ *
144
+ * Frame-Latency-N: is the trace between passing the Rendering to the view layer and the
145
+ * 'post frame rendered callback' for the Nth frame in the scenario. In other words, this traces
146
+ * the time it takes from a Rendering produced by Workflow to process through the Workflow UI
147
+ * layer and then be rendered in the next frame.
148
+ *
149
+ * XScreen-onY-Z: is the time between the execution of event handler 'onY' and the production of
150
+ * the next root Rendering by Workflow for the Zth instance of the 'onY' handler on X Screen.
151
+ * In other words, this measures the time Workflow takes in processing a UI event into a new
152
+ * Rendering. This will be similar to the render pass traced above, but more comprehensive to
153
+ * include all of the event handling time.
154
+ */
135
155
@OptIn(ExperimentalMetricApi ::class )
136
- private fun benchmarkFrameTiming (compilationMode : CompilationMode ) {
156
+ fun benchmarkLatencyTraceSections (compilationMode : CompilationMode ) {
137
157
benchmarkRule.measureRepeated(
138
158
packageName = PACKAGE_NAME ,
139
- metrics = listOf ( FrameTimingMetric ()) ,
140
- iterations = 1 ,
159
+ metrics = LATENCY_TRACE_SECTIONS .map { TraceSectionMetric (it) } ,
160
+ iterations = 20 ,
141
161
startupMode = StartupMode .WARM ,
142
162
compilationMode = compilationMode,
143
163
setupBlock = {
144
164
pressHome()
165
+ device.landscapeOrientation()
145
166
}
146
167
) {
147
- startActivityAndWait()
168
+ startActivityAndWait{
169
+ val renderPassConfig = SimulatedPerfConfig (
170
+ isComplex = true ,
171
+ complexityDelay = 200L ,
172
+ useInitializingState = true ,
173
+ traceRenderingPasses = false ,
174
+ traceLatency = true
175
+ )
176
+ it.putExtra(PerformancePoetryActivity .PERF_CONFIG_EXTRA , renderPassConfig)
177
+ }
178
+ device.landscapeOrientation()
148
179
149
- // N.B. This is *not* a good scenario to measure frame timing as there isn't much scrolling
150
- // or animation involved. This benchmark needs another app scenario.
151
180
device.openRavenAndNavigate()
152
181
}
153
182
}
154
183
155
184
companion object {
156
185
const val RENDER_PASSES = 61
157
186
const val PACKAGE_NAME = " com.squareup.benchmarks.performance.complex.poetry"
187
+
188
+ val LATENCY_TRACE_SECTIONS = listOf (
189
+ " PoemListScreen-onPoemSelected(2)-1 " ,
190
+ " StanzaListScreen-onStanzaSelected(4)-1 " ,
191
+ " StanzaScreen-onGoForth-1 " ,
192
+ " StanzaScreen-onGoForth-2 " ,
193
+ " StanzaScreen-onGoForth-3 " ,
194
+ " StanzaScreen-onGoForth-4 " ,
195
+ " StanzaScreen-onGoForth-5 " ,
196
+ " StanzaScreen-onGoBack-1 " ,
197
+ " StanzaScreen-onGoBack-2 " ,
198
+ " StanzaScreen-onGoBack-3 " ,
199
+ " StanzaScreen-onGoBack-4 " ,
200
+ " StanzaScreen-onGoBack-5 " ,
201
+ " StanzaListScreen-onExit-1 " ,
202
+ " Frame-Latency-00 " ,
203
+ " Frame-Latency-01 " ,
204
+ " Frame-Latency-02 " ,
205
+ " Frame-Latency-03 " ,
206
+ " Frame-Latency-04 " ,
207
+ " Frame-Latency-05 " ,
208
+ " Frame-Latency-06 " ,
209
+ " Frame-Latency-07 " ,
210
+ " Frame-Latency-08 " ,
211
+ " Frame-Latency-09 " ,
212
+ " Frame-Latency-10 " ,
213
+ " Frame-Latency-11 " ,
214
+ " Frame-Latency-12 " ,
215
+ " Frame-Latency-13 " ,
216
+ " Frame-Latency-14 " ,
217
+ " Frame-Latency-15 " ,
218
+ " Frame-Latency-16 " ,
219
+ " Frame-Latency-17 " ,
220
+ " Frame-Latency-18 " ,
221
+ " Frame-Latency-19 " ,
222
+ " Frame-Latency-20 " ,
223
+ " Frame-Latency-21 " ,
224
+ " Frame-Latency-22 " ,
225
+ " Frame-Latency-23 " ,
226
+ " Frame-Latency-24 " ,
227
+ " Frame-Latency-25 " ,
228
+ " Frame-Latency-26 " ,
229
+ " Frame-Latency-27 " ,
230
+ )
158
231
}
159
232
}
0 commit comments