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 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 24 | function is_monolithic { |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 25 | local out=$1 |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 26 | gn args $out --list --short | grep 'monolithic_binaries = true' 2>&1 >/dev/null |
| 27 | return $? |
| 28 | } |
| 29 | |
| 30 | function is_android { |
| 31 | local out=$1 |
| 32 | gn args $out --list --short | grep 'target_os = "android"' 2>&1 >/dev/null |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 33 | return $? |
| 34 | } |
| 35 | |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 36 | function is_mac { |
| 37 | ! test -d /proc |
| 38 | return $? |
| 39 | } |
| 40 | |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame^] | 41 | function tmux_ensure_bash { |
| 42 | if [[ $SHELL == *"fish" ]]; then |
| 43 | tmux send-keys "bash" Enter |
| 44 | fi |
| 45 | } |
| 46 | |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 47 | function reset_tracing { |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 48 | if is_android $OUT; then |
| 49 | adb shell 'echo 0 > /d/tracing/tracing_on' |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 50 | elif ! is_mac; then |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 51 | if [ ! -w /sys/kernel/debug ]; then |
| 52 | echo "debugfs not accessible, try sudo chown -R $USER /sys/kernel/debug" |
| 53 | sudo chown -R $USER /sys/kernel/debug |
| 54 | fi |
| 55 | |
| 56 | echo 0 > /sys/kernel/debug/tracing/tracing_on |
| 57 | fi |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 60 | function adb_supports_push_sync { |
Primiano Tucci | fd8240d | 2018-08-01 09:34:54 +0100 | [diff] [blame] | 61 | adb --help 2>&1 | grep 'push.*\[--sync\]' 2>&1 >/dev/null |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 64 | function push { |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 65 | if is_android $OUT; then |
| 66 | local maybe_sync='' |
| 67 | if adb_supports_push_sync; then |
| 68 | maybe_sync='--sync ' |
| 69 | fi |
| 70 | echo adb push $maybe_sync $1 $DIR |
| 71 | adb push $maybe_sync $1 $DIR |
| 72 | else |
| 73 | echo cp $1 $DIR |
| 74 | cp $1 $DIR |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 75 | fi |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | function pull { |
| 79 | if is_android $OUT; then |
| 80 | echo adb pull $DIR/$1 $2 |
| 81 | adb pull $DIR/$1 $2 |
| 82 | else |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 83 | echo mv $DIR/$1 $2 |
| 84 | mv $DIR/$1 $2 |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 85 | fi |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 88 | background=0 |
| 89 | |
| 90 | while getopts b o; do |
| 91 | case "$o" in |
| 92 | b) background=1;; |
| 93 | *) echo "Invalid option $o"; exit;; |
| 94 | esac |
| 95 | done |
| 96 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 97 | # If not set guess the OUT dir using the latest directory. |
| 98 | if [ ! -f "$OUT/args.gn" ]; then |
| 99 | echo "OUT=$OUT doesn't look like an output directory." |
| 100 | echo "Please specify a directory by doing: export OUT=out/xxx" |
| 101 | exit 1 |
| 102 | fi |
| 103 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 104 | # You can set the config to one of the files under test/configs e.g. |
| 105 | # CONFIG=ftrace.cfg or to :test. Defaults to :test. |
| 106 | CONFIG="${CONFIG:-:test}" |
| 107 | |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 108 | if is_android $OUT ; then |
| 109 | DIR=/data/local/tmp |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 110 | elif is_mac; then |
| 111 | DIR=$(mktemp -d $TMPDIR/perfetto.XXXXXX) |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 112 | else |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 113 | DIR=$(mktemp -p $TMPDIR -d perfetto.XXXXXX) |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 114 | fi |
| 115 | |
Lalit Maganti | c27975c | 2018-04-10 21:42:18 +0100 | [diff] [blame] | 116 | tools/ninja -C $OUT traced traced_probes perfetto trace_to_text test/configs |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 117 | |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 118 | push $OUT/traced |
| 119 | push $OUT/traced_probes |
| 120 | push $OUT/perfetto |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 121 | reset_tracing |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 122 | |
Florian Mayer | b0f0071 | 2018-04-04 16:35:45 +0100 | [diff] [blame] | 123 | if is_android $OUT; then |
Primiano Tucci | 301175d | 2019-01-11 10:10:21 +0000 | [diff] [blame] | 124 | 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] | 125 | else |
| 126 | PREFIX="" |
| 127 | fi |
| 128 | |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 129 | if ! is_monolithic $OUT; then |
Florian Mayer | b0f0071 | 2018-04-04 16:35:45 +0100 | [diff] [blame] | 130 | PREFIX="$PREFIX LD_LIBRARY_PATH=$DIR" |
Primiano Tucci | bdb2a59 | 2018-10-11 15:59:29 +0100 | [diff] [blame] | 131 | push $OUT/libperfetto.so |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 132 | fi |
| 133 | |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 134 | CONFIG_DEVICE_PATH="$CONFIG" |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 135 | CMD_OPTS="" |
| 136 | if [[ "$CONFIG" == *.protobuf ]]; then |
Hector Dearman | 696ff77 | 2019-04-23 18:38:53 +0100 | [diff] [blame] | 137 | CONFIG_DEVICE_PATH="$CONFIG" |
| 138 | CONFIG_PATH=$OUT/$CONFIG; |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 139 | if [[ ! -f $CONFIG_PATH ]]; then |
| 140 | echo 'Config "'$CONFIG_PATH'" not known.' |
| 141 | exit 1 |
| 142 | fi |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 143 | push $CONFIG_PATH |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 144 | elif [[ "$CONFIG" != ":test" ]]; then |
Ioannis Ilkos | 482264e | 2019-01-15 10:46:11 +0000 | [diff] [blame] | 145 | CONFIG_DEVICE_PATH="$(basename $CONFIG)" |
| 146 | CONFIG_PATH=test/configs/$CONFIG |
| 147 | # Check if this is a valid absolute path |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 148 | if [[ ! -f $CONFIG_PATH ]]; then |
Ioannis Ilkos | 482264e | 2019-01-15 10:46:11 +0000 | [diff] [blame] | 149 | CONFIG_PATH=$CONFIG |
| 150 | if [[ ! -f $CONFIG_PATH ]]; then |
| 151 | echo 'Config "'$CONFIG'" not known.' |
| 152 | exit 1 |
| 153 | fi |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 154 | fi |
| 155 | CMD_OPTS="--txt $CMD_OPTS" |
| 156 | push $CONFIG_PATH |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 157 | fi |
| 158 | |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 159 | POSTFIX="" |
| 160 | |
| 161 | if [[ background -eq 1 ]]; then |
| 162 | PREFIX="$PREFIX nohup" |
| 163 | POSTFIX=" &> /dev/null &" |
| 164 | fi |
| 165 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 166 | if tmux has-session -t demo; then |
| 167 | tmux kill-session -t demo |
| 168 | fi |
| 169 | tmux -2 new-session -d -s demo |
| 170 | |
| 171 | if tmux -V | awk '{split($2, ver, "."); if (ver[1] < 2) exit 1 ; else if (ver[1] == 2 && ver[2] < 1) exit 1 }'; then |
| 172 | tmux set-option -g mouse on |
| 173 | else |
| 174 | tmux set-option -g mode-mouse on |
| 175 | tmux set-option -g mouse-resize-pane on |
| 176 | tmux set-option -g mouse-select-pane on |
| 177 | tmux set-option -g mouse-select-window on |
| 178 | fi |
| 179 | |
| 180 | tmux split-window -v |
| 181 | tmux split-window -v |
| 182 | |
| 183 | tmux select-layout even-vertical |
| 184 | |
| 185 | tmux select-pane -t 0 |
| 186 | tmux send-keys "clear" C-m |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 187 | if is_android $OUT; then |
| 188 | tmux send-keys "adb shell" C-m |
| 189 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 190 | |
| 191 | tmux select-pane -t 1 |
| 192 | tmux send-keys "clear" C-m |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 193 | if is_android $OUT; then |
| 194 | tmux send-keys "adb shell" C-m |
| 195 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 196 | |
| 197 | tmux select-pane -t 2 |
| 198 | tmux send-keys "clear" C-m |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 199 | if is_android $OUT; then |
| 200 | tmux send-keys "adb shell" C-m |
| 201 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 202 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 203 | sleep 2 |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 204 | |
| 205 | tmux select-pane -t 1 |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame^] | 206 | tmux_ensure_bash |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 207 | tmux send-keys "PS1='[traced_probes]$ '" Enter |
| 208 | tmux send-keys "cd $DIR" Enter |
| 209 | tmux send-keys "$PREFIX ./traced $POSTFIX" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 210 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 211 | tmux select-pane -t 0 |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame^] | 212 | tmux_ensure_bash |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 213 | tmux send-keys "PS1='[traced]$ '" Enter |
| 214 | tmux send-keys "cd $DIR" Enter |
| 215 | tmux send-keys "$PREFIX PERFETTO_METATRACE_FILE=mtrace ./traced_probes $POSTFIX" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 216 | |
| 217 | tmux select-pane -t 2 |
Hector Dearman | 2407cdd | 2019-06-04 13:21:34 +0100 | [diff] [blame^] | 218 | tmux_ensure_bash |
Primiano Tucci | 9ba1d84 | 2018-12-20 17:31:04 +0100 | [diff] [blame] | 219 | tmux send-keys "PS1='[consumer]$ '" Enter |
| 220 | tmux send-keys "cd $DIR" Enter |
| 221 | 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] | 222 | |
| 223 | # Select consumer pane. |
| 224 | tmux select-pane -t 2 |
| 225 | |
| 226 | tmux -2 attach-session -t demo |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 227 | if [[ background -eq 1 ]]; then |
| 228 | exit 0; |
| 229 | fi |
Hector Dearman | a7c04f8 | 2018-03-29 11:31:24 +0100 | [diff] [blame] | 230 | |
Hector Dearman | 3c4e5c2 | 2018-03-29 11:31:55 +0100 | [diff] [blame] | 231 | reset_tracing |
Hector Dearman | a7c04f8 | 2018-03-29 11:31:24 +0100 | [diff] [blame] | 232 | |
| 233 | TRACE=$HOME/Downloads/trace |
| 234 | pull trace /tmp/trace.protobuf |
Florian Mayer | b843322 | 2018-05-15 11:29:18 +0100 | [diff] [blame] | 235 | echo -e "\n\x1b[32mPulling trace into $TRACE.pbtext\x1b[0m" |
| 236 | $OUT/trace_to_text text < /tmp/trace.protobuf > $TRACE.pbtext |
| 237 | echo -e "\n\x1b[32mPulling trace into $TRACE.json\x1b[0m" |
| 238 | $OUT/trace_to_text systrace < /tmp/trace.protobuf > $TRACE.json |
| 239 | # Keep this last so it can fail. |
Florian Mayer | 236ba47 | 2018-05-09 15:47:53 +0100 | [diff] [blame] | 240 | pull mtrace /tmp/mtrace.json |
| 241 | # Add [ to beginning of file and replace trailing , with ] to turn into valid |
| 242 | # JSON array. |
Primiano Tucci | 89d1ad2 | 2018-10-31 21:42:36 -0700 | [diff] [blame] | 243 | sed -i -e '$ s/.$/]/' /tmp/mtrace.json |
| 244 | sed -i -e '1s/^/[/' /tmp/mtrace.json |