-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add span report to local testing task (#65)
* Add span report to local testing task * Lint * Cleanups
- Loading branch information
Showing
9 changed files
with
204 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ | |
android:exported="true" /> | ||
</application> | ||
|
||
</manifest> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
performance/performance/src/main/java/com/emergetools/test/utils/perfetto/PerfettoUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.emergetools.test.utils.perfetto | ||
|
||
import androidx.benchmark.perfetto.ExperimentalPerfettoTraceProcessorApi | ||
import androidx.benchmark.perfetto.PerfettoTraceProcessor | ||
import androidx.benchmark.perfetto.Row | ||
|
||
/** | ||
* While these are available in PerfettoTraceProcessor, they're marked as internal to the library | ||
* group, preventing us from leveraging them. | ||
* These are simply a copy of those at 1.2.0-beta05, very slightly modified to avoid naming confusion: | ||
* https://github.com/androidx/androidx/blob/f6df7df4bb215d31187a32dea874edd43eb9506f/benchmark/benchmark-macro/src/main/java/androidx/benchmark/perfetto/PerfettoTraceProcessor.kt#L241 | ||
*/ | ||
@OptIn(ExperimentalPerfettoTraceProcessorApi::class) | ||
fun PerfettoTraceProcessor.Session.querySpans( | ||
spanNames: List<String>, | ||
packageName: String?, | ||
): List<Slice> { | ||
val whereClause = spanNames | ||
.joinToString( | ||
separator = " OR ", | ||
prefix = if (packageName == null) { | ||
"(" | ||
} else { | ||
"(process.name LIKE \"$packageName\" OR process.name LIKE \"$packageName:%\") AND (" | ||
}, | ||
postfix = ")" | ||
) { | ||
"slice.name LIKE \"$it\"" | ||
} | ||
val innerJoins = if (packageName != null) { | ||
""" | ||
INNER JOIN thread_track on slice.track_id = thread_track.id | ||
INNER JOIN thread USING(utid) | ||
INNER JOIN process USING(upid) | ||
""".trimMargin() | ||
} else { | ||
"" | ||
} | ||
|
||
return query( | ||
query = """ | ||
SELECT slice.name,ts,dur | ||
FROM slice | ||
$innerJoins | ||
WHERE $whereClause | ||
ORDER BY ts | ||
""".trimMargin() | ||
).toSlices() | ||
} | ||
|
||
data class Slice( | ||
val name: String, | ||
val ts: Long, | ||
val dur: Long, | ||
) { | ||
val durMs: Long = dur / NANOS_IN_MS | ||
|
||
companion object { | ||
const val NANOS_IN_MS = 1_000_000 | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalPerfettoTraceProcessorApi::class) | ||
internal fun Sequence<Row>.toSlices(): List<Slice> = map { | ||
Slice(name = it.string("name"), ts = it.long("ts"), dur = it.long("dur")) | ||
}.toList() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../main/java/com/emergetools/performance/sample/test/ExampleCustomStartupPerformanceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.emergetools.performance.sample.test | ||
|
||
import com.emergetools.relax.Relax | ||
import com.emergetools.test.annotations.EmergeStartupTest | ||
|
||
private const val APP_PACKAGE_NAME = "com.emergetools.performance.sample" | ||
|
||
/** | ||
* An example startup performance test class launching a custom deeplink. | ||
* | ||
* Performance test classes can have multiple tests, but tests in a given class share @EmergeInit and @EmergeSetup | ||
* methods. For tests that require a different init or setup multiple test classes are supported. | ||
* | ||
* Note that each test (ie. each method annotated with @EmergeTest) will be run on a separate device, they cannot | ||
* impact each other in any way. | ||
*/ | ||
class ExampleCustomStartupPerformanceTest { | ||
|
||
/** | ||
* Not implemented as this is a simple sample, but this method can be used to set up persistent | ||
* state, like logging in, before any tests are run. | ||
*/ | ||
// @EmergeInit | ||
// fun init() { | ||
// } | ||
|
||
/** | ||
* Unlike an @EmergeTest method, an @EmergeStartupTest method will be measured from process start | ||
* to the end of the first frame render. | ||
*/ | ||
@EmergeStartupTest | ||
fun myDeeplinkStartupTest() { | ||
Relax(APP_PACKAGE_NAME) { | ||
launchWithLink("emg://emergetools.com/") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters