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