Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2018 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | set -e |
Ryan | 960da79 | 2020-05-05 15:43:20 +0100 | [diff] [blame] | 16 | SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" |
Joel Fernandes | 16e8610 | 2019-03-19 13:42:48 -0400 | [diff] [blame] | 17 | |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 18 | if [ "$TMPDIR" == "" ]; then |
| 19 | TMPDIR=/tmp |
| 20 | fi |
| 21 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 22 | function get_gn_value() { |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 23 | local out=$1 |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 24 | local key=$2 |
Hector Dearman | b58022c | 2020-06-10 10:33:13 +0100 | [diff] [blame] | 25 | "$SCRIPT_DIR/gn" args "$out" --list=$key --short | awk '{print $3}' \ |
| 26 | | tr -d '"' |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 29 | function is_monolithic() { |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 30 | local out=$1 |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 31 | value=$(get_gn_value "$out" "monolithic_binaries") |
| 32 | test "$value" == "true" |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 35 | function is_android() { |
| 36 | local out=$1 |
| 37 | value=$(get_gn_value "$out" "target_os") |
| 38 | test "$value" == "android" |
| 39 | } |
| 40 | |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 41 | function is_ssh_target() { |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 42 | [[ -n "$SSH_TARGET" ]] |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | function is_mac() { |
Matthew Clarkson | 83987d2 | 2019-10-03 17:30:53 +0100 | [diff] [blame] | 46 | # shellcheck disable=2251 |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 47 | ! test -d /proc |
| 48 | return $? |
| 49 | } |
| 50 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 51 | function tmux_ensure_bash() { |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame] | 52 | if [[ $SHELL == *"fish" ]]; then |
| 53 | tmux send-keys "bash" Enter |
| 54 | fi |
| 55 | } |
| 56 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 57 | function reset_tracing() { |
| 58 | if is_android "$OUT"; then |
Lalit Maganti | db22f37 | 2021-11-02 20:18:00 +0000 | [diff] [blame] | 59 | # Newer versions of Android don't have debugfs mounted at all |
| 60 | # anymore so use /sys/kernel/tracing if /d/tracing doesn't exist |
Lalit Maganti | 7030e78 | 2021-11-08 13:12:42 +0000 | [diff] [blame] | 61 | adb shell 'test -d /sys/kernel/tracing && echo 0 > /sys/kernel/tracing/tracing_on || echo 0 > /sys/kernel/debug/tracing/tracing_on' |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 62 | elif ! is_mac; then |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 63 | # shellcheck disable=SC2016 |
| 64 | local script=' |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 65 | if [ ! -w /sys/kernel/debug ]; then |
| 66 | echo "debugfs not accessible, try sudo chown -R $USER /sys/kernel/debug" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 67 | sudo chown -R "$USER" /sys/kernel/debug |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 68 | fi |
| 69 | |
| 70 | echo 0 > /sys/kernel/debug/tracing/tracing_on |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 71 | ' |
| 72 | |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 73 | if is_ssh_target; then |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 74 | # shellcheck disable=SC2029 |
Matthew Clarkson | 83987d2 | 2019-10-03 17:30:53 +0100 | [diff] [blame] | 75 | ssh -t "$SSH_TARGET" "sh -c '$script'" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 76 | else |
| 77 | sh -c "$script" |
| 78 | fi |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 79 | fi |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 82 | function adb_supports_push_sync() { |
| 83 | adb --help 2>&1 | grep 'push.*\[--sync\]' >/dev/null 2>&1 |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 86 | function push() { |
| 87 | if is_android "$OUT"; then |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 88 | local maybe_sync='' |
| 89 | if adb_supports_push_sync; then |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 90 | maybe_sync='--sync' |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 91 | fi |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 92 | echo adb push $maybe_sync "$1" "$DIR" |
| 93 | adb push $maybe_sync "$1" "$DIR" |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 94 | elif is_ssh_target; then |
| 95 | echo scp "$1" "$SSH_TARGET:$DIR" |
| 96 | scp "$1" "$SSH_TARGET:$DIR" |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 97 | else |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 98 | echo cp "$1" "$DIR" |
| 99 | cp "$1" "$DIR" |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 100 | fi |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 103 | function pull() { |
| 104 | if is_android "$OUT"; then |
| 105 | echo adb pull "$DIR/$1" "$2" |
| 106 | adb pull "$DIR/$1" "$2" |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 107 | elif is_ssh_target; then |
| 108 | echo scp "$SSH_TARGET:$DIR/$1" "$2" |
| 109 | scp "$SSH_TARGET:$DIR/$1" "$2" |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 110 | else |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 111 | echo mv "$DIR/$1" "$2" |
| 112 | mv "$DIR/$1" "$2" |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 113 | fi |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 116 | BACKGROUND=0 |
| 117 | SKIP_CONVERTERS=0 |
| 118 | TMUX_LAYOUT="even-vertical" |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 119 | CPU_MASK="" |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 120 | |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 121 | while getopts "bl:nt:c:C:z:s:" o; do |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 122 | case "$o" in |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 123 | b) BACKGROUND=1 ;; |
| 124 | l) TMUX_LAYOUT=${OPTARG} ;; |
| 125 | n) SKIP_CONVERTERS=1 ;; |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 126 | t) SSH_TARGET=${OPTARG} ;; |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 127 | c) CONFIG=${OPTARG} ;; |
| 128 | C) OUT=${OPTARG} ;; |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 129 | z) CPU_MASK=${OPTARG} ;; |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 130 | s) SCRIPT=${OPTARG} ;; |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 131 | *) |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 132 | echo >&2 "Invalid option $o" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 133 | exit |
| 134 | ;; |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 135 | esac |
| 136 | done |
| 137 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 138 | # Allow out to be passed as argument |
| 139 | shift $((OPTIND - 1)) |
| 140 | OUT="${OUT:-$1}" |
| 141 | |
Matthew Clarkson | 83987d2 | 2019-10-03 17:30:53 +0100 | [diff] [blame] | 142 | # Provide useful usage information |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 143 | if [ -z "$OUT" ]; then |
| 144 | echo "Usage: $0 [OPTION]... [OUTPUT]" |
| 145 | echo "" |
| 146 | echo "Options:" |
| 147 | echo " -b run in the background" |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 148 | echo " -l LAYOUT tmux pane layout" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 149 | echo " -n skip post-trace convertors" |
| 150 | echo " -t TARGET SSH device target" |
| 151 | echo " -c CONFIG trace configuration file" |
| 152 | echo " -C OUTPUT output directory" |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 153 | echo " -z MASK constrain binaries to given cpu mask (taskset syntax)" |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 154 | echo " -s SCRIPT a script to put into a tmux pane" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 155 | echo "" |
| 156 | echo "Environment variables:" |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 157 | echo " SSH_TARGET SSH device target" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 158 | echo " CONFIG trace configuration file" |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 159 | echo " OUT output directory" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 160 | exit 1 |
| 161 | fi |
| 162 | |
| 163 | # Warn about invalid output directories |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 164 | if [ ! -f "$OUT/args.gn" ]; then |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 165 | echo >&2 "OUT=$OUT doesn't look like an output directory." |
| 166 | echo >&2 "Please specify a directory by doing:" |
| 167 | echo >&2 " export OUT=out/xxx $0" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 168 | exit 1 |
| 169 | fi |
| 170 | |
Matthew Clarkson | 83987d2 | 2019-10-03 17:30:53 +0100 | [diff] [blame] | 171 | # Check SSH target is valid |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 172 | if is_ssh_target && ! ssh -q "$SSH_TARGET" exit; then |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 173 | echo >&2 "SSH_TARGET=$SSH_TARGET doesn't look like a valid SSH target." |
| 174 | echo >&2 "Please specify a SSH cross-compilation target by doing:" |
| 175 | echo >&2 " export SSH_TARGET=<user>@<host> $0" |
Matthew Clarkson | 83987d2 | 2019-10-03 17:30:53 +0100 | [diff] [blame] | 176 | exit 1 |
| 177 | fi |
| 178 | |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 179 | if ! builtin type -P tmux &>/dev/null; then |
| 180 | echo >&2 "tmux not found" |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 181 | exit 1 |
| 182 | fi |
| 183 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 184 | # You can set the config to one of the files under test/configs e.g. |
| 185 | # CONFIG=ftrace.cfg or to :test. Defaults to :test. |
| 186 | CONFIG="${CONFIG:-:test}" |
| 187 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 188 | if is_android "$OUT"; then |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 189 | DIR=/data/local/tmp |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 190 | elif is_ssh_target; then |
| 191 | DIR=$(ssh "$SSH_TARGET" mktemp -d $TMPDIR/perfetto.XXXXXX) |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 192 | elif is_mac; then |
| 193 | DIR=$(mktemp -d $TMPDIR/perfetto.XXXXXX) |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 194 | else |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 195 | DIR=$(mktemp -p $TMPDIR -d perfetto.XXXXXX) |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 196 | fi |
| 197 | |
Ryan | 960da79 | 2020-05-05 15:43:20 +0100 | [diff] [blame] | 198 | # (re)build the binaries |
| 199 | BUILD_TARGETS=(traced traced_probes perfetto test/configs) |
| 200 | if [[ SKIP_CONVERTERS -eq 0 ]]; then |
| 201 | BUILD_TARGETS+=(trace_to_text) |
| 202 | fi |
| 203 | |
| 204 | "$SCRIPT_DIR/ninja" -C "$OUT" ${BUILD_TARGETS[*]} |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 205 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 206 | push "$OUT/traced" |
| 207 | push "$OUT/traced_probes" |
| 208 | push "$OUT/perfetto" |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 209 | reset_tracing |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 210 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 211 | if is_android "$OUT"; then |
Primiano Tucci | 301175d | 2019-01-11 10:10:21 +0000 | [diff] [blame] | 212 | PREFIX="PERFETTO_CONSUMER_SOCK_NAME=@perfetto_test_consumer PERFETTO_PRODUCER_SOCK_NAME=@perfetto_test_producer" |
Florian Mayer | b0f0071 | 2018-04-04 16:35:45 +0100 | [diff] [blame] | 213 | else |
| 214 | PREFIX="" |
| 215 | fi |
| 216 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 217 | if ! is_monolithic "$OUT"; then |
Florian Mayer | b0f0071 | 2018-04-04 16:35:45 +0100 | [diff] [blame] | 218 | PREFIX="$PREFIX LD_LIBRARY_PATH=$DIR" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 219 | push "$OUT/libperfetto.so" |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 220 | fi |
| 221 | |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 222 | CONFIG_DEVICE_PATH="$CONFIG" |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 223 | CMD_OPTS="" |
Ryan | 960da79 | 2020-05-05 15:43:20 +0100 | [diff] [blame] | 224 | # Shorthand for using serialized test configs. |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 225 | if [[ "$CONFIG" == *.protobuf ]]; then |
Hector Dearman | 696ff77 | 2019-04-23 18:38:53 +0100 | [diff] [blame] | 226 | CONFIG_DEVICE_PATH="$CONFIG" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 227 | CONFIG_PATH=$OUT/$CONFIG |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 228 | if [[ ! -f $CONFIG_PATH ]]; then |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 229 | echo >&2 "Config \"$CONFIG_PATH\" not known." |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 230 | exit 1 |
| 231 | fi |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 232 | push "$CONFIG_PATH" |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 233 | elif [[ "$CONFIG" != ":test" ]]; then |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 234 | CONFIG_DEVICE_PATH="$(basename "$CONFIG")" |
Ryan | 960da79 | 2020-05-05 15:43:20 +0100 | [diff] [blame] | 235 | CONFIG_PATH=$CONFIG |
| 236 | # If path isn't valid, assume it's a name of a test config. |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 237 | if [[ ! -f $CONFIG_PATH ]]; then |
Ryan | 960da79 | 2020-05-05 15:43:20 +0100 | [diff] [blame] | 238 | CONFIG_PATH=test/configs/$CONFIG |
Ioannis Ilkos | 482264e | 2019-01-15 10:46:11 +0000 | [diff] [blame] | 239 | if [[ ! -f $CONFIG_PATH ]]; then |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 240 | echo >&2 "Config \"$CONFIG\" not known." |
Ioannis Ilkos | 482264e | 2019-01-15 10:46:11 +0000 | [diff] [blame] | 241 | exit 1 |
| 242 | fi |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 243 | fi |
| 244 | CMD_OPTS="--txt $CMD_OPTS" |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 245 | push "$CONFIG_PATH" |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 246 | fi |
| 247 | |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 248 | if [[ -f "$SCRIPT" ]]; then |
| 249 | push "$SCRIPT" |
| 250 | fi |
| 251 | |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 252 | POSTFIX="" |
| 253 | |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 254 | if [[ -n "$CPU_MASK" ]]; then |
| 255 | PREFIX="$PREFIX taskset $CPU_MASK" |
| 256 | fi |
| 257 | |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 258 | if [[ BACKGROUND -eq 1 ]]; then |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 259 | PREFIX="$PREFIX nohup" |
| 260 | POSTFIX=" &> /dev/null &" |
| 261 | fi |
| 262 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 263 | if tmux has-session -t demo; then |
| 264 | tmux kill-session -t demo |
| 265 | fi |
| 266 | tmux -2 new-session -d -s demo |
| 267 | |
Hector Dearman | 28583e2 | 2020-06-08 19:22:45 +0100 | [diff] [blame] | 268 | if [ ! -z "$ANDROID_ADB_SERVER_PORT" ]; then |
| 269 | tmux set-environment -t demo ANDROID_ADB_SERVER_PORT $ANDROID_ADB_SERVER_PORT |
| 270 | fi |
| 271 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 272 | if tmux -V | awk '{split($2, ver, "."); if (ver[1] < 2) exit 1 ; else if (ver[1] == 2 && ver[2] < 1) exit 1 }'; then |
| 273 | tmux set-option -g mouse on |
| 274 | else |
| 275 | tmux set-option -g mode-mouse on |
| 276 | tmux set-option -g mouse-resize-pane on |
| 277 | tmux set-option -g mouse-select-pane on |
| 278 | tmux set-option -g mouse-select-window on |
| 279 | fi |
| 280 | |
| 281 | tmux split-window -v |
| 282 | tmux split-window -v |
| 283 | |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 284 | if [[ -n "$SCRIPT" ]]; then |
| 285 | tmux split-window -v |
| 286 | fi |
| 287 | |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 288 | tmux select-layout "${TMUX_LAYOUT}" |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 289 | |
| 290 | tmux select-pane -t 0 |
| 291 | tmux send-keys "clear" C-m |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 292 | if is_android "$OUT"; then |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 293 | tmux send-keys "adb shell" C-m |
| 294 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 295 | |
| 296 | tmux select-pane -t 1 |
| 297 | tmux send-keys "clear" C-m |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 298 | if is_android "$OUT"; then |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 299 | tmux send-keys "adb shell" C-m |
| 300 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 301 | |
| 302 | tmux select-pane -t 2 |
| 303 | tmux send-keys "clear" C-m |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 304 | if is_android "$OUT"; then |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 305 | tmux send-keys "adb shell" C-m |
| 306 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 307 | |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 308 | if [[ -n "$SCRIPT" ]]; then |
| 309 | tmux select-pane -t 3 |
| 310 | tmux send-keys "clear" C-m |
Matthew Clarkson | f8e6110 | 2019-10-28 13:26:50 +0000 | [diff] [blame] | 311 | if is_android "$OUT"; then |
| 312 | tmux send-keys "adb shell" C-m |
| 313 | fi |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 314 | fi |
| 315 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 316 | sleep 2 |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 317 | |
| 318 | tmux select-pane -t 1 |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 319 | if is_ssh_target; then |
| 320 | tmux send-keys "ssh $SSH_TARGET" Enter |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 321 | fi |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame] | 322 | tmux_ensure_bash |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 323 | tmux send-keys "PS1='[traced]$ '" Enter |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 324 | tmux send-keys "cd $DIR" Enter |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 325 | tmux send-keys "clear" C-m |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 326 | tmux send-keys "$PREFIX ./traced $POSTFIX" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 327 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 328 | tmux select-pane -t 0 |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 329 | if is_ssh_target; then |
| 330 | tmux send-keys "ssh $SSH_TARGET" Enter |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 331 | fi |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame] | 332 | tmux_ensure_bash |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 333 | tmux send-keys "PS1='[traced_probes]$ '" Enter |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 334 | tmux send-keys "cd $DIR" Enter |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 335 | tmux send-keys "clear" C-m |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 336 | tmux send-keys "$PREFIX ./traced_probes $POSTFIX" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 337 | |
| 338 | tmux select-pane -t 2 |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 339 | if is_ssh_target; then |
| 340 | tmux send-keys "ssh $SSH_TARGET" Enter |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 341 | fi |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame] | 342 | tmux_ensure_bash |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 343 | tmux send-keys "PS1='[consumer]$ '" Enter |
| 344 | tmux send-keys "cd $DIR" Enter |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 345 | tmux send-keys "clear" C-m |
Ryan Savitski | 6cadb87 | 2019-09-06 17:25:15 +0100 | [diff] [blame] | 346 | tmux send-keys "$PREFIX ./perfetto $CMD_OPTS -c $CONFIG_DEVICE_PATH -o trace $POSTFIX" |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 347 | |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 348 | if [[ -n "$SCRIPT" ]]; then |
| 349 | tmux select-pane -t 3 |
| 350 | if is_ssh_target; then |
| 351 | tmux send-keys "ssh $SSH_TARGET" Enter |
| 352 | fi |
| 353 | tmux_ensure_bash |
| 354 | tmux send-keys "PS1='[script]$ '" Enter |
| 355 | tmux send-keys "cd $DIR" Enter |
| 356 | tmux send-keys "clear" C-m |
Matthew Clarkson | f8e6110 | 2019-10-28 13:26:50 +0000 | [diff] [blame] | 357 | if [[ -f "$SCRIPT" ]]; then |
| 358 | tmux send-keys "./$(basename "$SCRIPT")" |
| 359 | else |
| 360 | tmux send-keys "$SCRIPT" |
| 361 | fi |
Matthew Clarkson | 9bace99 | 2019-10-17 10:30:27 +0100 | [diff] [blame] | 362 | fi |
| 363 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 364 | # Select consumer pane. |
| 365 | tmux select-pane -t 2 |
| 366 | |
| 367 | tmux -2 attach-session -t demo |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 368 | if [[ BACKGROUND -eq 1 ]]; then |
Matthew Clarkson | 7a2a3bd | 2019-09-04 12:27:17 +0100 | [diff] [blame] | 369 | exit 0 |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 370 | fi |
Hector Dearman | a7c04f8 | 2018-03-29 11:31:24 +0100 | [diff] [blame] | 371 | |
Hector Dearman | 3c4e5c2 | 2018-03-29 11:31:55 +0100 | [diff] [blame] | 372 | reset_tracing |
Hector Dearman | a7c04f8 | 2018-03-29 11:31:24 +0100 | [diff] [blame] | 373 | |
Ryan | 960da79 | 2020-05-05 15:43:20 +0100 | [diff] [blame] | 374 | TRACE=$TMPDIR/trace |
Primiano Tucci | 03ad8aa | 2021-06-30 09:55:37 +0100 | [diff] [blame] | 375 | echo -e "\n\x1b[32mPulling trace into $TRACE.perfetto-trace\x1b[0m" |
| 376 | pull trace "$TRACE.perfetto-trace" |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 377 | |
| 378 | if [[ SKIP_CONVERTERS -eq 0 ]]; then |
| 379 | echo -e "\n\x1b[32mPulling trace into $TRACE.pbtext\x1b[0m" |
Primiano Tucci | 03ad8aa | 2021-06-30 09:55:37 +0100 | [diff] [blame] | 380 | "$OUT/trace_to_text" text <"$TRACE.perfetto-trace" >"$TRACE.pbtext" |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 381 | echo -e "\n\x1b[32mPulling trace into $TRACE.json\x1b[0m" |
Primiano Tucci | 03ad8aa | 2021-06-30 09:55:37 +0100 | [diff] [blame] | 382 | "$OUT/trace_to_text" systrace <"$TRACE.perfetto-trace" >"$TRACE.json" |
Ryan Savitski | bf67d30 | 2019-07-29 14:00:43 +0100 | [diff] [blame] | 383 | # Keep this last so it can fail. |
| 384 | fi |