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 | |
Nataniel Borges | 2aa5a1d | 2021-07-20 21:19:53 +0200 | [diff] [blame] | 33 | WINSCOPE_EXT=.winscope |
| 34 | outfileTrans=${outfile}_transactiontrace$WINSCOPE_EXT |
| 35 | outfileSurf=${outfile}_layerstrace$WINSCOPE_EXT |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 36 | |
| 37 | outfileTrans_abs="$(cd "$(dirname "$outfileTrans")"; pwd)/$(basename "$outfileTrans")" |
| 38 | outfileSurf_abs="$(cd "$(dirname "$outfileSurf")"; pwd)/$(basename "$outfileSurf")" |
| 39 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 40 | if [ "$help" != "" ]; then |
| 41 | echo "usage: $0 [-h | --help] [OUTFILE]" |
| 42 | echo |
Nataniel Borges | 2aa5a1d | 2021-07-20 21:19:53 +0200 | [diff] [blame] | 43 | echo "Records Transaction traces (default transactiontrace$WINSCOPE_EXT)." |
| 44 | echo "Records Surface traces (default layerstrace$WINSCOPE_EXT)." |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 45 | echo "To view the traces, use $WINSCOPE_URL." |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | function log_error() { |
| 50 | echo "FAILED" |
| 51 | } |
| 52 | trap log_error ERR |
| 53 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 54 | function start_tracing() { |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 55 | echo -n "Starting transaction and surface recording..." |
| 56 | echo |
| 57 | adb shell su root service call SurfaceFlinger 1020 i32 1 >/dev/null |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 58 | adb shell su root service call SurfaceFlinger 1025 i32 1 >/dev/null |
| 59 | echo "DONE" |
| 60 | trap stop_tracing EXIT |
| 61 | } |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 62 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 63 | function stop_tracing() { |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 64 | echo -n "Stopping transaction and surface recording..." |
| 65 | echo |
| 66 | adb shell su root service call SurfaceFlinger 1020 i32 0 >/dev/null |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 67 | adb shell su root service call SurfaceFlinger 1025 i32 0 >/dev/null |
| 68 | echo "DONE" |
| 69 | trap - EXIT |
| 70 | } |
| 71 | |
| 72 | which adb >/dev/null 2>/dev/null || { echo "ERROR: ADB not found."; exit 1; } |
| 73 | adb get-state 2>/dev/null | grep -q device || { echo "ERROR: No device connected or device is unauthorized."; exit 1; } |
| 74 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 75 | start_tracing |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 76 | read -p "Press ENTER to stop recording" -s x |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 77 | echo |
| 78 | stop_tracing |
Nataniel Borges | 2aa5a1d | 2021-07-20 21:19:53 +0200 | [diff] [blame] | 79 | adb exec-out su root cat /data/misc/wmtrace/transaction_trace$WINSCOPE_EXT >"$outfileTrans" |
| 80 | adb exec-out su root cat /data/misc/wmtrace/layers_trace$WINSCOPE_EXT >"$outfileSurf" |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 81 | |
| 82 | echo |
Robert Delgado | 4489219 | 2019-07-29 13:03:34 -0700 | [diff] [blame] | 83 | echo "To view the trace, go to $WINSCOPE_URL, and open" |
| 84 | echo "${outfileTrans_abs}" |
| 85 | echo "${outfileSurf_abs}" |