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