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 |
| 16 | |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 17 | if [ "$TMPDIR" == "" ]; then |
| 18 | TMPDIR=/tmp |
| 19 | fi |
| 20 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 21 | function is_monolithic { |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 22 | local out=$1 |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 23 | gn args $out --list --short | grep 'monolithic_binaries = true' 2>&1 >/dev/null |
| 24 | return $? |
| 25 | } |
| 26 | |
| 27 | function is_android { |
| 28 | local out=$1 |
| 29 | 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] | 30 | return $? |
| 31 | } |
| 32 | |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 33 | function reset_tracing { |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 34 | if is_android $OUT; then |
| 35 | adb shell 'echo 0 > /d/tracing/tracing_on' |
| 36 | else |
| 37 | if [ ! -w /sys/kernel/debug ]; then |
| 38 | echo "debugfs not accessible, try sudo chown -R $USER /sys/kernel/debug" |
| 39 | sudo chown -R $USER /sys/kernel/debug |
| 40 | fi |
| 41 | |
| 42 | echo 0 > /sys/kernel/debug/tracing/tracing_on |
| 43 | fi |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 46 | function adb_supports_push_sync { |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 47 | adb --help | grep 'push.*\[--sync\]' 2>&1 >/dev/null |
| 48 | } |
| 49 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 50 | function push { |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 51 | if is_android $OUT; then |
| 52 | local maybe_sync='' |
| 53 | if adb_supports_push_sync; then |
| 54 | maybe_sync='--sync ' |
| 55 | fi |
| 56 | echo adb push $maybe_sync $1 $DIR |
| 57 | adb push $maybe_sync $1 $DIR |
| 58 | else |
| 59 | echo cp $1 $DIR |
| 60 | cp $1 $DIR |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 61 | fi |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | function pull { |
| 65 | if is_android $OUT; then |
| 66 | echo adb pull $DIR/$1 $2 |
| 67 | adb pull $DIR/$1 $2 |
| 68 | else |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 69 | echo mv $DIR/$1 $2 |
| 70 | mv $DIR/$1 $2 |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 71 | fi |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 74 | # If not set guess the OUT dir using the latest directory. |
| 75 | if [ ! -f "$OUT/args.gn" ]; then |
| 76 | echo "OUT=$OUT doesn't look like an output directory." |
| 77 | echo "Please specify a directory by doing: export OUT=out/xxx" |
| 78 | exit 1 |
| 79 | fi |
| 80 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 81 | # You can set the config to one of the files under test/configs e.g. |
| 82 | # CONFIG=ftrace.cfg or to :test. Defaults to :test. |
| 83 | CONFIG="${CONFIG:-:test}" |
| 84 | |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 85 | if is_android $OUT ; then |
| 86 | DIR=/data/local/tmp |
| 87 | else |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 88 | DIR=$(mktemp -p $TMPDIR -d perfetto.XXXXXX) |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 89 | fi |
| 90 | |
Lalit Maganti | c27975c | 2018-04-10 21:42:18 +0100 | [diff] [blame] | 91 | 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] | 92 | |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 93 | push $OUT/traced |
| 94 | push $OUT/traced_probes |
| 95 | push $OUT/perfetto |
Hector Dearman | 0ff07c7 | 2018-03-15 09:54:46 +0000 | [diff] [blame] | 96 | reset_tracing |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 97 | |
Florian Mayer | b0f0071 | 2018-04-04 16:35:45 +0100 | [diff] [blame] | 98 | if is_android $OUT; then |
| 99 | PREFIX=" |
| 100 | PERFETTO_CONSUMER_SOCK_NAME=/data/misc/perfetto-traces/test_consumer_socket |
| 101 | PERFETTO_PRODUCER_SOCK_NAME=/data/misc/perfetto-traces/test_producer_socket" |
| 102 | else |
| 103 | PREFIX="" |
| 104 | fi |
| 105 | |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 106 | if ! is_monolithic $OUT; then |
Florian Mayer | b0f0071 | 2018-04-04 16:35:45 +0100 | [diff] [blame] | 107 | PREFIX="$PREFIX LD_LIBRARY_PATH=$DIR" |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 108 | push $OUT/libtraced_shared.so |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 109 | fi |
| 110 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 111 | CONFIG_DEVICE_PATH=$CONFIG |
| 112 | if [[ "$CONFIG" != ":test" ]]; then |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 113 | CONFIG_DEVICE_PATH=$DIR/$CONFIG.protobuf |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 114 | CONFIG_PATH=$OUT/$CONFIG.protobuf; |
| 115 | if [[ ! -f $CONFIG_PATH ]]; then |
| 116 | echo 'Config "'$CONFIG_PATH'" not known.' |
| 117 | exit 1 |
| 118 | fi |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 119 | push $CONFIG_PATH |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 120 | fi |
| 121 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 122 | if tmux has-session -t demo; then |
| 123 | tmux kill-session -t demo |
| 124 | fi |
| 125 | tmux -2 new-session -d -s demo |
| 126 | |
| 127 | if tmux -V | awk '{split($2, ver, "."); if (ver[1] < 2) exit 1 ; else if (ver[1] == 2 && ver[2] < 1) exit 1 }'; then |
| 128 | tmux set-option -g mouse on |
| 129 | else |
| 130 | tmux set-option -g mode-mouse on |
| 131 | tmux set-option -g mouse-resize-pane on |
| 132 | tmux set-option -g mouse-select-pane on |
| 133 | tmux set-option -g mouse-select-window on |
| 134 | fi |
| 135 | |
| 136 | tmux split-window -v |
| 137 | tmux split-window -v |
| 138 | |
| 139 | tmux select-layout even-vertical |
| 140 | |
| 141 | tmux select-pane -t 0 |
| 142 | tmux send-keys "clear" C-m |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 143 | if is_android $OUT; then |
| 144 | tmux send-keys "adb shell" C-m |
| 145 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 146 | |
| 147 | tmux select-pane -t 1 |
| 148 | tmux send-keys "clear" C-m |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 149 | if is_android $OUT; then |
| 150 | tmux send-keys "adb shell" C-m |
| 151 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 152 | |
| 153 | tmux select-pane -t 2 |
| 154 | tmux send-keys "clear" C-m |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 155 | if is_android $OUT; then |
| 156 | tmux send-keys "adb shell" C-m |
| 157 | fi |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 158 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 159 | sleep 2 |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 160 | |
| 161 | tmux select-pane -t 1 |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 162 | tmux send-keys "$PREFIX $DIR/traced" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 163 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 164 | tmux select-pane -t 0 |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 165 | tmux send-keys "$PREFIX $DIR/traced_probes" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 166 | |
| 167 | tmux select-pane -t 2 |
Hector Dearman | c067d41 | 2018-03-16 17:01:41 +0000 | [diff] [blame] | 168 | tmux send-keys "$PREFIX $DIR/perfetto -c $CONFIG_DEVICE_PATH -o $DIR/trace" |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 169 | |
| 170 | # Select consumer pane. |
| 171 | tmux select-pane -t 2 |
| 172 | |
| 173 | tmux -2 attach-session -t demo |
Hector Dearman | a7c04f8 | 2018-03-29 11:31:24 +0100 | [diff] [blame] | 174 | |
Hector Dearman | 3c4e5c2 | 2018-03-29 11:31:55 +0100 | [diff] [blame] | 175 | reset_tracing |
Hector Dearman | a7c04f8 | 2018-03-29 11:31:24 +0100 | [diff] [blame] | 176 | |
| 177 | TRACE=$HOME/Downloads/trace |
| 178 | pull trace /tmp/trace.protobuf |
| 179 | echo -e "\n\x1b[32mPulling trace into $TRACE.pbtext\x1b[0m" |
| 180 | $OUT/trace_to_text text < /tmp/trace.protobuf > $TRACE.pbtext |
| 181 | echo -e "\n\x1b[32mPulling trace into $TRACE.json\x1b[0m" |
| 182 | $OUT/trace_to_text systrace < /tmp/trace.protobuf > $TRACE.json |