blob: 3f5008d15e5b3fa687e2b5b873fc9ae570f5a4ca [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
Robert Delgado44892192019-07-29 13:03:34 -070033outfileTrans=${outfile}_transactiontrace.pb
34outfileSurf=${outfile}_layerstrace.pb
35
36outfileTrans_abs="$(cd "$(dirname "$outfileTrans")"; pwd)/$(basename "$outfileTrans")"
37outfileSurf_abs="$(cd "$(dirname "$outfileSurf")"; pwd)/$(basename "$outfileSurf")"
38
Vishnu Nair46babab2017-12-19 15:15:30 -080039if [ "$help" != "" ]; then
40 echo "usage: $0 [-h | --help] [OUTFILE]"
41 echo
Robert Delgado44892192019-07-29 13:03:34 -070042 echo "Records Transaction traces (default transactiontrace.pb)."
43 echo "Records Surface traces (default layerstrace.pb)."
Vishnu Nair46babab2017-12-19 15:15:30 -080044 echo "To view the traces, use $WINSCOPE_URL."
Vishnu Nair46babab2017-12-19 15:15:30 -080045 exit 1
46fi
47
48function log_error() {
49 echo "FAILED"
50}
51trap log_error ERR
52
Vishnu Nair46babab2017-12-19 15:15:30 -080053function start_tracing() {
Robert Delgado44892192019-07-29 13:03:34 -070054 echo -n "Starting transaction and surface recording..."
55 echo
56 adb shell su root service call SurfaceFlinger 1020 i32 1 >/dev/null
Vishnu Nair46babab2017-12-19 15:15:30 -080057 adb shell su root service call SurfaceFlinger 1025 i32 1 >/dev/null
58 echo "DONE"
59 trap stop_tracing EXIT
60}
Robert Delgado44892192019-07-29 13:03:34 -070061
Vishnu Nair46babab2017-12-19 15:15:30 -080062function stop_tracing() {
Robert Delgado44892192019-07-29 13:03:34 -070063 echo -n "Stopping transaction and surface recording..."
64 echo
65 adb shell su root service call SurfaceFlinger 1020 i32 0 >/dev/null
Vishnu Nair46babab2017-12-19 15:15:30 -080066 adb shell su root service call SurfaceFlinger 1025 i32 0 >/dev/null
67 echo "DONE"
68 trap - EXIT
69}
70
71which adb >/dev/null 2>/dev/null || { echo "ERROR: ADB not found."; exit 1; }
72adb get-state 2>/dev/null | grep -q device || { echo "ERROR: No device connected or device is unauthorized."; exit 1; }
73
Vishnu Nair46babab2017-12-19 15:15:30 -080074start_tracing
Robert Delgado44892192019-07-29 13:03:34 -070075read -p "Press ENTER to stop recording" -s x
Vishnu Nair46babab2017-12-19 15:15:30 -080076echo
77stop_tracing
Robert Delgado44892192019-07-29 13:03:34 -070078adb exec-out su root cat /data/misc/wmtrace/transaction_trace.pb >"$outfileTrans"
79adb exec-out su root cat /data/misc/wmtrace/layers_trace.pb >"$outfileSurf"
Vishnu Nair46babab2017-12-19 15:15:30 -080080
81echo
Robert Delgado44892192019-07-29 13:03:34 -070082echo "To view the trace, go to $WINSCOPE_URL, and open"
83echo "${outfileTrans_abs}"
84echo "${outfileSurf_abs}"