blob: ff0174850b0d3196af8dc73f6aaaee2190fa1bcc [file] [log] [blame]
Vishnu Nair46babab2017-12-19 15:15:30 -08001#!/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 Delgado44892192019-07-29 13:03:34 -070018WINSCOPE_URL='http://go/winscope/'
Vishnu Nair46babab2017-12-19 15:15:30 -080019
20set -e
21
Vishnu Nair46babab2017-12-19 15:15:30 -080022help=
23
24for 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
31done
32
Nataniel Borges2aa5a1d2021-07-20 21:19:53 +020033WINSCOPE_EXT=.winscope
34outfileTrans=${outfile}_transactiontrace$WINSCOPE_EXT
35outfileSurf=${outfile}_layerstrace$WINSCOPE_EXT
Robert Delgado44892192019-07-29 13:03:34 -070036
37outfileTrans_abs="$(cd "$(dirname "$outfileTrans")"; pwd)/$(basename "$outfileTrans")"
38outfileSurf_abs="$(cd "$(dirname "$outfileSurf")"; pwd)/$(basename "$outfileSurf")"
39
Vishnu Nair46babab2017-12-19 15:15:30 -080040if [ "$help" != "" ]; then
41 echo "usage: $0 [-h | --help] [OUTFILE]"
42 echo
Nataniel Borges2aa5a1d2021-07-20 21:19:53 +020043 echo "Records Transaction traces (default transactiontrace$WINSCOPE_EXT)."
44 echo "Records Surface traces (default layerstrace$WINSCOPE_EXT)."
Vishnu Nair46babab2017-12-19 15:15:30 -080045 echo "To view the traces, use $WINSCOPE_URL."
Vishnu Nair46babab2017-12-19 15:15:30 -080046 exit 1
47fi
48
49function log_error() {
50 echo "FAILED"
51}
52trap log_error ERR
53
Vishnu Nair46babab2017-12-19 15:15:30 -080054function start_tracing() {
Robert Delgado44892192019-07-29 13:03:34 -070055 echo -n "Starting transaction and surface recording..."
56 echo
57 adb shell su root service call SurfaceFlinger 1020 i32 1 >/dev/null
Vishnu Nair46babab2017-12-19 15:15:30 -080058 adb shell su root service call SurfaceFlinger 1025 i32 1 >/dev/null
59 echo "DONE"
60 trap stop_tracing EXIT
61}
Robert Delgado44892192019-07-29 13:03:34 -070062
Vishnu Nair46babab2017-12-19 15:15:30 -080063function stop_tracing() {
Robert Delgado44892192019-07-29 13:03:34 -070064 echo -n "Stopping transaction and surface recording..."
65 echo
66 adb shell su root service call SurfaceFlinger 1020 i32 0 >/dev/null
Vishnu Nair46babab2017-12-19 15:15:30 -080067 adb shell su root service call SurfaceFlinger 1025 i32 0 >/dev/null
68 echo "DONE"
69 trap - EXIT
70}
71
72which adb >/dev/null 2>/dev/null || { echo "ERROR: ADB not found."; exit 1; }
73adb get-state 2>/dev/null | grep -q device || { echo "ERROR: No device connected or device is unauthorized."; exit 1; }
74
Vishnu Nair46babab2017-12-19 15:15:30 -080075start_tracing
Robert Delgado44892192019-07-29 13:03:34 -070076read -p "Press ENTER to stop recording" -s x
Vishnu Nair46babab2017-12-19 15:15:30 -080077echo
78stop_tracing
Nataniel Borges2aa5a1d2021-07-20 21:19:53 +020079adb exec-out su root cat /data/misc/wmtrace/transaction_trace$WINSCOPE_EXT >"$outfileTrans"
80adb exec-out su root cat /data/misc/wmtrace/layers_trace$WINSCOPE_EXT >"$outfileSurf"
Vishnu Nair46babab2017-12-19 15:15:30 -080081
82echo
Robert Delgado44892192019-07-29 13:03:34 -070083echo "To view the trace, go to $WINSCOPE_URL, and open"
84echo "${outfileTrans_abs}"
85echo "${outfileSurf_abs}"