Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoetryActivity.Companion
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.PerformanceTracingInterceptor
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.PerformanceTracingInterceptor.Companion.NODES_TO_TRACE
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.SimulatedPerfConfig
import com.squareup.benchmarks.performance.complex.poetry.robots.landscapeOrientation
import com.squareup.benchmarks.performance.complex.poetry.robots.openRavenAndNavigate
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.landscapeOrientation
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.openRavenAndNavigate
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -115,15 +113,11 @@ class ComplexPoetryBenchmarks {
device.landscapeOrientation()
}
) {
startActivityAndWait{
val renderPassConfig = SimulatedPerfConfig(
isComplex = true,
complexityDelay = 200L,
useInitializingState = true,
traceRenderingPasses = true,
traceLatency = false
)
it.putExtra(PerformancePoetryActivity.PERF_CONFIG_EXTRA, renderPassConfig)
startActivityAndWait { intent ->
intent.apply {
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_INITIALIZING, true)
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_RENDERING, true)
}
}
device.landscapeOrientation()

Expand All @@ -139,21 +133,35 @@ class ComplexPoetryBenchmarks {
}

/**
* This test is focused on two different measurements:
* This test is focused on measuring the latency of Workflow's 'work'. By that we mean how much
* time Workflow spends producing the next set of updates to the View's that can be passed
* to Android to draw as a frame.
*
* Frame-Latency-N: is the trace between passing the Rendering to the view layer and the
* 'post frame rendered callback' for the Nth frame in the scenario. In other words, this traces
* the time it takes from a Rendering produced by Workflow to process through the Workflow UI
* layer and then be rendered in the next frame.
* How do we measure this? The [EventHandlingTracingInterceptor] is a [WorkflowInterceptor] that
* sets up a [RenderContextInterceptor] which has a hook for everytime we 'send' an action to the
* [RenderContext]. Because this is done on the main thread, we can wrap this function call in a
* synchronous trace section as it will be equivalent to the main thread 'message' that handles
* all of the work before invoking the Choreographer to draw the updated Views.
*
* XScreen-onY-Z: is the time between the execution of event handler 'onY' and the production of
* the next root Rendering by Workflow for the Zth instance of the 'onY' handler on X Screen.
* In other words, this measures the time Workflow takes in processing a UI event into a new
* Rendering. This will be similar to the render pass traced above, but more comprehensive to
* include all of the event handling time.
* We do this for certain [Worker]s results by annotating the [Worker] with a pattern in
* its [toString()] - see [TraceableWorker].
* We do this for UI events by adding in an injected name to the eventHandler.
*
* These are formatted as:
* - "Worker-<Work>-Finished-XX"
* - "E-<Screen>-<Event>-XX"
*
* Where XX is the counted instance of that event's response.
*/
@OptIn(ExperimentalMetricApi::class)
fun benchmarkLatencyTraceSections(compilationMode: CompilationMode) {
fun addLatency(intent: Intent) {
intent.apply {
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_INITIALIZING, true)
putExtra(PerformancePoetryActivity.EXTRA_PERF_CONFIG_EVENT_LATENCY, true)
}
}

benchmarkRule.measureRepeated(
packageName = PACKAGE_NAME,
metrics = LATENCY_TRACE_SECTIONS.map { TraceSectionMetric(it) },
Expand All @@ -165,68 +173,46 @@ class ComplexPoetryBenchmarks {
device.landscapeOrientation()
}
) {
startActivityAndWait{
val renderPassConfig = SimulatedPerfConfig(
isComplex = true,
complexityDelay = 200L,
useInitializingState = true,
traceRenderingPasses = false,
traceLatency = true
)
it.putExtra(PerformancePoetryActivity.PERF_CONFIG_EXTRA, renderPassConfig)
}
startActivityAndWait(::addLatency)
device.landscapeOrientation()
device.waitForIdle()

device.openRavenAndNavigate()
}
}

companion object {
const val RENDER_PASSES = 61
const val RENDER_PASSES = 58
const val PACKAGE_NAME = "com.squareup.benchmarks.performance.complex.poetry"

val LATENCY_TRACE_SECTIONS = listOf(
"PoemListScreen-onPoemSelected(2)-1 ",
"StanzaListScreen-onStanzaSelected(4)-1 ",
"StanzaScreen-onGoForth-1 ",
"StanzaScreen-onGoForth-2 ",
"StanzaScreen-onGoForth-3 ",
"StanzaScreen-onGoForth-4 ",
"StanzaScreen-onGoForth-5 ",
"StanzaScreen-onGoBack-1 ",
"StanzaScreen-onGoBack-2 ",
"StanzaScreen-onGoBack-3 ",
"StanzaScreen-onGoBack-4 ",
"StanzaScreen-onGoBack-5 ",
"StanzaListScreen-onExit-1 ",
"Frame-Latency-00 ",
"Frame-Latency-01 ",
"Frame-Latency-02 ",
"Frame-Latency-03 ",
"Frame-Latency-04 ",
"Frame-Latency-05 ",
"Frame-Latency-06 ",
"Frame-Latency-07 ",
"Frame-Latency-08 ",
"Frame-Latency-09 ",
"Frame-Latency-10 ",
"Frame-Latency-11 ",
"Frame-Latency-12 ",
"Frame-Latency-13 ",
"Frame-Latency-14 ",
"Frame-Latency-15 ",
"Frame-Latency-16 ",
"Frame-Latency-17 ",
"Frame-Latency-18 ",
"Frame-Latency-19 ",
"Frame-Latency-20 ",
"Frame-Latency-21 ",
"Frame-Latency-22 ",
"Frame-Latency-23 ",
"Frame-Latency-24 ",
"Frame-Latency-25 ",
"Frame-Latency-26 ",
"Frame-Latency-27 ",
"E-PoemList-PoemSelected-00",
"Worker-ComplexCallBrowser(2)-Finished-00",
"Worker-PoemLoading-Finished-00",
"E-StanzaList-StanzaSelected-00",
"Worker-PoemLoading-Finished-01",
"E-StanzaWorkflow-ShowNextStanza-00",
"Worker-PoemLoading-Finished-02",
"E-StanzaWorkflow-ShowNextStanza-01",
"Worker-PoemLoading-Finished-03",
"E-StanzaWorkflow-ShowNextStanza-02",
"Worker-PoemLoading-Finished-04",
"E-StanzaWorkflow-ShowNextStanza-03",
"Worker-PoemLoading-Finished-05",
"E-StanzaWorkflow-ShowNextStanza-04",
"Worker-PoemLoading-Finished-06",
"E-StanzaWorkflow-ShowPreviousStanza-00",
"Worker-PoemLoading-Finished-07",
"E-StanzaWorkflow-ShowPreviousStanza-01",
"Worker-PoemLoading-Finished-08",
"E-StanzaWorkflow-ShowPreviousStanza-02",
"Worker-PoemLoading-Finished-09",
"E-StanzaWorkflow-ShowPreviousStanza-03",
"Worker-PoemLoading-Finished-10",
"E-StanzaWorkflow-ShowPreviousStanza-04",
"Worker-PoemLoading-Finished-11",
"E-StanzaList-Exit-00",
"Worker-ComplexCallBrowser(-1)-Finished-00",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.squareup.benchmarks.performance.complex.poetry.benchmark.ComplexPoetryBenchmarks.Companion.PACKAGE_NAME
import com.squareup.benchmarks.performance.complex.poetry.robots.openRavenAndNavigate
import com.squareup.benchmarks.performance.complex.poetry.cyborgs.openRavenAndNavigate
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down
Loading