The project provides an easy way to save before/after CPU traces from Microbenchmark runs, and compare them visually using Differential Flame Graphs.
Areas where the code got slower are highlighted in red, while areas that are now faster are marked in blue; the intensity of the colour is proportional to the size of the difference.
See also the end-to-end demo (video).
./bench-flame-diff.sh -h
./bench-flame-diff.sh <command> -h
On first usage, initialise all dependencies by running: ./bench-flame-diff.sh init
./bench-flame-diff.sh save
. It‘s worth picking a good names for the saved traces since you’re likely going to e.g. re-use the base while iterating on code changes../bench-flame-diff.sh save
./bench-flame-diff.sh diff
which will create and open a diff in a web browserbase
: flamegraph for the base tracebase-vs-curr
: differential flame graph showing base vs current on the base tracecurr
: flamegraph for the current tracecurr-vs-base
: differential flame graph showing base vs current on the current trace./bench-flame-diff.sh open
This can be done in CLI or by editing build.gradle
. Full documentation is here.
Quick CLI example:
# pick a target benchmark tgt=:compose:foundation:foundation-benchmark:connectedCheck # create a regex that targets a specific benchmark (test) test_rx="androidx.compose.foundation.benchmark.lazy.LazyListScrollingBenchmark.scrollProgrammatically_noNewItems\[.*Row.*\]" # run the benchmark and gather a 5 second (default) stack sample at 1000 Hz (default) ./gradlew $tgt -Pandroid.testInstrumentationRunnerArguments.tests_regex="$test_rx" \ -P android.testInstrumentationRunnerArguments.androidx.benchmark.profiling.mode=StackSampling \ -P android.testInstrumentationRunnerArguments.androidx.benchmark.profiling.sampleDurationSeconds=5 \ -P android.testInstrumentationRunnerArguments.androidx.benchmark.profiling.sampleFrequency=1000
Generate completion files with ./generate-completion-files.sh
and source in your shell config, e.g.:
bash
: dst="$(pwd)/completion_bash.sh"; echo "source '$dst'" >> ~/.bashrc
zsh
: dst="$(pwd)/completion_zsh.sh"; echo "source '$dst'" >> ~/.zshrc
After restarting the shell session, you will be able to ‘tab-autocomplete’ commands and argument names.
On top of dependencies discoverable with ./gradlew app:dependencies
the project depends on:
Both are fetched from the network in the init
command and pinned to known-good-revisions.
File an issue on Buganizer using this link or reach out directly to jgielzak@.
Known issues and future work items are tracked here.