Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2017 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 18 | WINSCOPE_URL='http://go/winscope/' |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 19 | |
| 20 | set -e |
| 21 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 22 | help= |
| 23 | |
| 24 | for arg in "$@"; do |
| 25 | case $arg in |
| 26 | -h|--help) help=1;; |
| 27 | --);; |
| 28 | -*) echo "Unknown option: $arg"; help=1;; |
| 29 | *) outfile="$arg";; |
| 30 | esac |
| 31 | done |
| 32 | |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 33 | outfileTrans=${outfile}_transactiontrace.pb |
| 34 | outfileSurf=${outfile}_layerstrace.pb |
| 35 | |
| 36 | outfileTrans_abs="$(cd "$(dirname "$outfileTrans")"; pwd)/$(basename "$outfileTrans")" |
| 37 | outfileSurf_abs="$(cd "$(dirname "$outfileSurf")"; pwd)/$(basename "$outfileSurf")" |
| 38 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 39 | if [ "$help" != "" ]; then |
| 40 | echo "usage: $0 [-h | --help] [OUTFILE]" |
| 41 | echo |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 42 | echo "Records Transaction traces (default transactiontrace.pb)." |
| 43 | echo "Records Surface traces (default layerstrace.pb)." |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 44 | echo "To view the traces, use $WINSCOPE_URL." |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | function log_error() { |
| 49 | echo "FAILED" |
| 50 | } |
| 51 | trap log_error ERR |
| 52 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 53 | function start_tracing() { |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 54 | echo -n "Starting transaction and surface recording..." |
| 55 | echo |
| 56 | adb shell su root service call SurfaceFlinger 1020 i32 1 >/dev/null |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 57 | adb shell su root service call SurfaceFlinger 1025 i32 1 >/dev/null |
| 58 | echo "DONE" |
| 59 | trap stop_tracing EXIT |
| 60 | } |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 61 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 62 | function stop_tracing() { |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 63 | echo -n "Stopping transaction and surface recording..." |
| 64 | echo |
| 65 | adb shell su root service call SurfaceFlinger 1020 i32 0 >/dev/null |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 66 | adb shell su root service call SurfaceFlinger 1025 i32 0 >/dev/null |
| 67 | echo "DONE" |
| 68 | trap - EXIT |
| 69 | } |
| 70 | |
| 71 | which adb >/dev/null 2>/dev/null || { echo "ERROR: ADB not found."; exit 1; } |
| 72 | adb get-state 2>/dev/null | grep -q device || { echo "ERROR: No device connected or device is unauthorized."; exit 1; } |
| 73 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 74 | start_tracing |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 75 | read -p "Press ENTER to stop recording" -s x |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 76 | echo |
| 77 | stop_tracing |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 78 | adb exec-out su root cat /data/misc/wmtrace/transaction_trace.pb >"$outfileTrans" |
| 79 | adb exec-out su root cat /data/misc/wmtrace/layers_trace.pb >"$outfileSurf" |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 80 | |
| 81 | echo |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 82 | echo "To view the trace, go to $WINSCOPE_URL, and open" |
| 83 | echo "${outfileTrans_abs}" |
| 84 | echo "${outfileSurf_abs}" |