Debian Codegraph @

libs/hwui/tests/scripts/skp-capture.sh

raw symbols SCIP
1 #!/bin/sh
2
3 # Copyright 2015 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7 #
8 # Before this can be used, the device must be rooted and the filesystem must be writable by Skia
9 # - These steps are necessary once after flashing to enable capture -
10 # adb root
11 # adb remount
12 # adb reboot
13
14 if [ -z "$1" ]; then
15 printf 'Usage:\n skp-capture.sh PACKAGE_NAME OPTIONAL_FRAME_COUNT\n\n'
16 printf "Use \`adb shell 'pm list packages'\` to get a listing.\n\n"
17 exit 1
18 fi
19 if ! command -v adb > /dev/null 2>&1; then
20 if [ -x "${ANDROID_SDK_ROOT}/platform-tools/adb" ]; then
21 adb() {
22 "${ANDROID_SDK_ROOT}/platform-tools/adb" "$@"
23 }
24 else
25 echo 'adb missing'
26 exit 2
27 fi
28 fi
29 phase1_timeout_seconds=60
30 phase2_timeout_seconds=300
31 package="$1"
32 extension="skp"
33 if (( "$2" > 1 )); then # 2nd arg is number of frames
34 extension="mskp" # use different extension for multi frame files.
35 fi
36 filename="$(date '+%H%M%S').${extension}"
37 remote_path="/data/data/${package}/cache/${filename}"
38 local_path_prefix="$(date '+%Y-%m-%d_%H%M%S')_${package}"
39 local_path="${local_path_prefix}.${extension}"
40 enable_capture_key='debug.hwui.capture_skp_enabled'
41 enable_capture_value=$(adb shell "getprop '${enable_capture_key}'")
42
43 # TODO(nifong): check if filesystem is writable here with "avbctl get-verity"
44 # result will either start with "verity is disabled" or "verity is enabled"
45
46 if [ -z "$enable_capture_value" ]; then
47 printf 'debug.hwui.capture_skp_enabled was found to be disabled, enabling it now.\n'
48 printf " restart the process you want to capture on the device, then retry this script.\n\n"
49 adb shell "setprop '${enable_capture_key}' true"
50 exit 1
51 fi
52 if [ ! -z "$2" ]; then
53 adb shell "setprop 'debug.hwui.capture_skp_frames' $2"
54 fi
55 filename_key='debug.hwui.skp_filename'
56 adb shell "setprop '${filename_key}' '${remote_path}'"
57 spin() {
58 case "$spin" in
59 1) printf '\b|';;
60 2) printf '\b\\';;
61 3) printf '\b-';;
62 *) printf '\b/';;
63 esac
64 spin=$(( ( ${spin:-0} + 1 ) % 4 ))
65 sleep $1
66 }
67
68 banner() {
69 printf '\n=====================\n'
70 printf ' %s' "$*"
71 printf '\n=====================\n'
72 }
73 banner '...WAITING FOR APP INTERACTION...'
74 # Waiting for nonzero file is an indication that the pipeline has both opened the file and written
75 # the header. With multiple frames this does not occur until the last frame has been recorded,
76 # so we continue to show the "waiting for app interaction" message as long as the app still requires
77 # interaction to draw more frames.
78 adb_test_file_nonzero() {
79 # grab first byte of `wc -c` output
80 X="$(adb shell "wc -c \"$1\" 2> /dev/null | dd bs=1 count=1 2> /dev/null")"
81 test "$X" && test "$X" -ne 0
82 }
83 timeout=$(( $(date +%s) + $phase1_timeout_seconds))
84 while ! adb_test_file_nonzero "$remote_path"; do
85 spin 0.05
86 if [ $(date +%s) -gt $timeout ] ; then
87 printf '\bTimed out.\n'
88 adb shell "setprop '${filename_key}' ''"
89 exit 3
90 fi
91 done
92 printf '\b'
93
94 # Disable further capturing
95 adb shell "setprop '${filename_key}' ''"
96
97 banner '...SAVING...'
98 # return the size of a file in bytes
99 adb_filesize() {
100 adb shell "wc -c \"$1\"" 2> /dev/null | awk '{print $1}'
101 }
102 timeout=$(( $(date +%s) + $phase2_timeout_seconds))
103 last_size='0' # output of last size check command
104 unstable=true # false once the file size stops changing
105 counter=0 # used to perform size check only 1/sec though we update spinner 20/sec
106 # loop until the file size is unchanged for 1 second.
107 while [ $unstable != 0 ] ; do
108 spin 0.05
109 counter=$(( $counter+1 ))
110 if ! (( $counter % 20)) ; then
111 new_size=$(adb_filesize "$remote_path")
112 unstable=$(($(adb_filesize "$remote_path") != last_size))
113 last_size=$new_size
114 fi
115 if [ $(date +%s) -gt $timeout ] ; then
116 printf '\bTimed out.\n'
117 adb shell "setprop '${filename_key}' ''"
118 exit 3
119 fi
120 done
121 printf '\b'
122
123 printf "SKP file serialized: %s\n" $(echo $last_size | numfmt --to=iec)
124
125 i=0; while [ $i -lt 10 ]; do spin 0.10; i=$(($i + 1)); done; echo
126
127 adb pull "$remote_path" "$local_path"
128 if ! [ -f "$local_path" ] ; then
129 printf "something went wrong with `adb pull`."
130 exit 4
131 fi
132 adb shell rm "$remote_path"
133 printf '\nSKP saved to file:\n %s\n\n' "$local_path"
134