1cb93a386Sopenharmony_ci# skpbench
2cb93a386Sopenharmony_ci
3cb93a386Sopenharmony_ciskpbench is a benchmarking tool for replaying skp or mksp files on android devices.
4cb93a386Sopenharmony_ciit achieves a lower variance in framerate by controlling the clock speed and stopping
5cb93a386Sopenharmony_ciall other processes that could cause interference.
6cb93a386Sopenharmony_ci
7cb93a386Sopenharmony_ci## Build
8cb93a386Sopenharmony_ci
9cb93a386Sopenharmony_ciskpbench consists of the skpbench binary which must be built for the phone you intend to run on,
10cb93a386Sopenharmony_ciand skpbench.py which runs on the machine the phone is connected to via ADB and is the entry point.
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ciThe to build skia for android are at https://skia.org/user/build#android and reproduced here.
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ciDownload the Android NDK
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_ci```
17cb93a386Sopenharmony_ci./bin/sk asset download android_ndk_linux /tmp/ndk
18cb93a386Sopenharmony_ci```
19cb93a386Sopenharmony_ci
20cb93a386Sopenharmony_ciAfter this is set up once, build skpbench for your target cpu (assumed to be arm64 here for a Pixel 3)
21cb93a386Sopenharmony_ci
22cb93a386Sopenharmony_ci```
23cb93a386Sopenharmony_cibin/gn gen out/arm64 --args='ndk="/tmp/ndk" target_cpu="arm64" is_debug=false'
24cb93a386Sopenharmony_cininja -C out/arm64 skpbench
25cb93a386Sopenharmony_ci```
26cb93a386Sopenharmony_ci
27cb93a386Sopenharmony_ci## Benchmark an SKP on a connected device.
28cb93a386Sopenharmony_ci
29cb93a386Sopenharmony_ciFirst, copy the built skpbench binary and an example skp file to the device.
30cb93a386Sopenharmony_ci(or pull a skp corpus using instructions in the section below)
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ci```
33cb93a386Sopenharmony_ciadb push out/arm64/skpbench /data/local/tmp
34cb93a386Sopenharmony_ciadb push /home/nifong/Downloads/foo.skp /data/local/tmp/skps/
35cb93a386Sopenharmony_ci```
36cb93a386Sopenharmony_ci
37cb93a386Sopenharmony_ciRun skpbench.py
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci```
40cb93a386Sopenharmony_cipython tools/skpbench/skpbench.py \
41cb93a386Sopenharmony_ci  --adb \
42cb93a386Sopenharmony_ci  --config gles \
43cb93a386Sopenharmony_ci  /data/local/tmp/skpbench \
44cb93a386Sopenharmony_ci  /data/local/tmp/skps/foo.skp
45cb93a386Sopenharmony_ci```
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ci`--adb` specifies that it should use adb to the only connected device and run skpbench there.
48cb93a386Sopenharmony_ci`--force` is necessary because we don't yet have a configuration to monitor vitals on the Pixel 3.
49cb93a386Sopenharmony_ci`--config gles` specifies Open GL ES is the backend GPU config to use.
50cb93a386Sopenharmony_ci
51cb93a386Sopenharmony_ciAdditional documentation of arguments is printed by `python tools/skpbench/skpbench.py --help`
52cb93a386Sopenharmony_ci
53cb93a386Sopenharmony_ciOutput appears in the following format
54cb93a386Sopenharmony_ci```
55cb93a386Sopenharmony_ci   accum    median       max       min   stddev  samples  sample_ms  clock  metric  config    bench
56cb93a386Sopenharmony_ci  0.1834    0.1832    0.1897    0.1707    1.59%      101         50  cpu    ms      gles      foo.skp
57cb93a386Sopenharmony_ci```
58cb93a386Sopenharmony_ci
59cb93a386Sopenharmony_ci`accum` is the time taken to draw all frames, divided by the number of frames.
60cb93a386Sopenharmony_ci`metric` specifies that the unit is ms (milliseconds per frame)
61cb93a386Sopenharmony_ci
62cb93a386Sopenharmony_ci## MSKP corpus
63cb93a386Sopenharmony_ci
64cb93a386Sopenharmony_ciA manually collected corpus of MSKPs from around 30 top apps (using skia via HWUI) and of about 20
65cb93a386Sopenharmony_ciactions in RenderEngine exists in a google cloud storage folder managed by skia/infra/bots/assets/mskp/upload.py
66cb93a386Sopenharmony_ci
67cb93a386Sopenharmony_ciTo download the fileset, first determine the highest current version of the fileset
68cb93a386Sopenharmony_ci
69cb93a386Sopenharmony_ci```
70cb93a386Sopenharmony_cigsutil ls gs://skia-assets/assets/mskp/
71cb93a386Sopenharmony_ci```
72cb93a386Sopenharmony_ci
73cb93a386Sopenharmony_ciDownload the latest version.
74cb93a386Sopenharmony_ci
75cb93a386Sopenharmony_ci```
76cb93a386Sopenharmony_cigsutil cp gs://skia-assets/assets/mskp/5.zip ~/Downloads
77cb93a386Sopenharmony_ci```
78cb93a386Sopenharmony_ci
79cb93a386Sopenharmony_ciUnzip the archive and adb push it to the device.
80cb93a386Sopenharmony_ci
81cb93a386Sopenharmony_ciTo upload a new version of the corpus, use the steps above to download and unzip the last version, change the
82cb93a386Sopenharmony_cicontent however you need, then Use the upload tool, passing the directory of the altered archive (not a zip file).
83cb93a386Sopenharmony_ciNote that you must provide it as an absolute path.
84cb93a386Sopenharmony_ci
85cb93a386Sopenharmony_ci```
86cb93a386Sopenharmony_cipython upload.py --target_dir=/home/nifong/scratch/new_mskps
87cb93a386Sopenharmony_ci```
88cb93a386Sopenharmony_ci
89cb93a386Sopenharmony_ciThe upload script should print a version number.
90cb93a386Sopenharmony_ciFinally, submit something like https://skia-review.googlesource.com/c/skia/+/304376
91cb93a386Sopenharmony_cito point jobs at the new version.
92cb93a386Sopenharmony_ci
93cb93a386Sopenharmony_ci## Production
94cb93a386Sopenharmony_ci
95cb93a386Sopenharmony_ciskpbench is run as a tryjob from gerrit, where it uploads the results to perf.skia.org.
96cb93a386Sopenharmony_ciOnce such job name is `Perf-Android-Clang-Pixel4XL-GPU-Adreno640-arm64-Release-All-Android_Skpbench`
97cb93a386Sopenharmony_ci
98cb93a386Sopenharmony_ciPerf results are available by querying with this or similar.
99cb93a386Sopenharmony_ci  extra_config = Android_Skpbench
100cb93a386Sopenharmony_ci  sub_result = accum_cpu_ms
101cb93a386Sopenharmony_ci
102cb93a386Sopenharmony_ciExample perf query
103cb93a386Sopenharmony_cihttps://perf.skia.org/e/?queries=extra_config%3DAndroid_Skpbench%26sub_result%3Daccum_cpu_ms
104