Fixed
Status Update
Comments
ya...@google.com <ya...@google.com> #3
Yes, it works. But hardware events like cpu-cycles may not be supported. And cpu-cycles is the default event used (as in https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:benchmark/benchmark-common/src/main/java/androidx/benchmark/simpleperf/RecordOptions.java;l=189 ).
On emulators, we can use software event cpu-clock to replace cpu-cycles. cpu-clock uses a hrtimer in kernel to count thread time used in nanoseconds.
If you want to support both real devices and emulators, you can always use cpu-clock.
By the way, simpleperf error message can be got from `adb logcat` by filtering simpleperf.
On emulators, we can use software event cpu-clock to replace cpu-cycles. cpu-clock uses a hrtimer in kernel to count thread time used in nanoseconds.
If you want to support both real devices and emulators, you can always use cpu-clock.
By the way, simpleperf error message can be got from `adb logcat` by filtering simpleperf.
cc...@google.com <cc...@google.com> #4
If cpu cycles is a hardware event, I assume we'd want to use that when possible. Is there any way to check if the emulator I'm running on has support for cpu cycles? If not, we could either check for emulators and always use cpu-clock, or retry with cpu-clock if it fails, though I'd like to avoid waiting on a timeout.
We don't currently have an easy way to check logcat, as we're running the capture entirely on a device (via on-device shell commands).
ya...@google.com <ya...@google.com> #5
The most reliable way is to run `simpleperf list hw`, and see if cpu-cycles is in it.
The other way is to use different methods (like system property) to check if it's an emulator.
The other way is to use different methods (like system property) to check if it's an emulator.
cc...@google.com <cc...@google.com> #6
Perfect, thanks!
ap...@google.com <ap...@google.com> #7
Project: platform/frameworks/support
Branch: androidx-main
commit 0ded70b4c6097c0c857dbdd3320b2d52929a6116
Author: Chris Craik <ccraik@google.com>
Date: Tue Nov 09 09:08:38 2021
Use cpu-clock if cpu-cycles hw event not present, fix profiler lifecycle
Test: TrivialKotlinBenchmark (with simpleperf enabled, API 29 + 30)
Test: ./gradlew benchmark:benchmark-common:cC
Fixes: 202719335
Relnote: "Fixes multiple crashes in StackSampling profiling mode on
emulators and non-rooted devices"
Note, emulators tested on locally all had the hw counter available, so
haven't reprod fallback path, just validated hw event list parsing.
Also fixes intersections between profiler and thermal throttle
detection, where simpleperf would be started/stopped multiple times in
a row.
Change-Id: Icdbda7d0659aa07f1bdd47eb1b5234af7e714ce8
M benchmark/benchmark-common/src/main/java/androidx/benchmark/BenchmarkState.kt
M benchmark/benchmark-common/src/main/java/androidx/benchmark/ThrottleDetector.kt
M benchmark/benchmark-common/src/main/java/androidx/benchmark/Profiler.kt
M benchmark/benchmark-common/src/androidTest/java/androidx/benchmark/BenchmarkStateTest.kt
https://android-review.googlesource.com/1886304
Branch: androidx-main
commit 0ded70b4c6097c0c857dbdd3320b2d52929a6116
Author: Chris Craik <ccraik@google.com>
Date: Tue Nov 09 09:08:38 2021
Use cpu-clock if cpu-cycles hw event not present, fix profiler lifecycle
Test: TrivialKotlinBenchmark (with simpleperf enabled, API 29 + 30)
Test: ./gradlew benchmark:benchmark-common:cC
Fixes: 202719335
Relnote: "Fixes multiple crashes in StackSampling profiling mode on
emulators and non-rooted devices"
Note, emulators tested on locally all had the hw counter available, so
haven't reprod fallback path, just validated hw event list parsing.
Also fixes intersections between profiler and thermal throttle
detection, where simpleperf would be started/stopped multiple times in
a row.
Change-Id: Icdbda7d0659aa07f1bdd47eb1b5234af7e714ce8
M benchmark/benchmark-common/src/main/java/androidx/benchmark/BenchmarkState.kt
M benchmark/benchmark-common/src/main/java/androidx/benchmark/ThrottleDetector.kt
M benchmark/benchmark-common/src/main/java/androidx/benchmark/Profiler.kt
M benchmark/benchmark-common/src/androidTest/java/androidx/benchmark/BenchmarkStateTest.kt
Description
Component used: androidx.benchmark:benchmark-junit4
Version used: 1.1.0-alpha08
Devices/Android versions reproduced on: Android Emulator API 29, 30, 31
Benchmarking
performance-samples/BenchmarkSample
fails on mentioned devices when using simpleperf sampling (StackSamplingSimpleperf
)On real devices: Pixel 3 API 31 and Samsung SM-F711B API 30 it works fine.
Stacktrace: