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 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame^] | 17 | function is_monolithic { |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 18 | local out=$1 |
| 19 | gn args $out --list --short | grep 'monolithic_binaries = true' > /dev/null |
| 20 | return $? |
| 21 | } |
| 22 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame^] | 23 | function adb_supports_push_sync { |
| 24 | adb --help | grep 'push.*\[--sync\]' |
| 25 | } |
| 26 | |
| 27 | function push { |
| 28 | local maybe_sync='' |
| 29 | if adb_supports_push_sync; then |
| 30 | maybe_sync='--sync ' |
| 31 | fi |
| 32 | echo adb push $maybe_sync $1 $2 |
| 33 | adb push $maybe_sync $1 $2 |
| 34 | } |
| 35 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 36 | # If not set guess the OUT dir using the latest directory. |
| 37 | if [ ! -f "$OUT/args.gn" ]; then |
| 38 | echo "OUT=$OUT doesn't look like an output directory." |
| 39 | echo "Please specify a directory by doing: export OUT=out/xxx" |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 43 | # You can set the config to one of the files under test/configs e.g. |
| 44 | # CONFIG=ftrace.cfg or to :test. Defaults to :test. |
| 45 | CONFIG="${CONFIG:-:test}" |
| 46 | |
| 47 | ninja -C $OUT traced traced_probes perfetto trace_to_text test/configs |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 48 | |
Hector Dearman | 9b89d47 | 2018-02-28 12:07:21 +0000 | [diff] [blame^] | 49 | push $OUT/traced /data/local/tmp/ |
| 50 | push $OUT/traced_probes /data/local/tmp/ |
| 51 | push $OUT/perfetto /data/local/tmp/ |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 52 | |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 53 | PREFIX="" |
| 54 | if ! is_monolithic $OUT; then |
| 55 | PREFIX="LD_LIBRARY_PATH=/data/local/tmp" |
| 56 | set -x |
| 57 | adb push $OUT/libtraced_shared.so /data/local/tmp/ |
| 58 | set +x |
| 59 | fi |
| 60 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 61 | CONFIG_DEVICE_PATH=$CONFIG |
| 62 | if [[ "$CONFIG" != ":test" ]]; then |
| 63 | CONFIG_DEVICE_PATH=/data/local/tmp/$CONFIG.protobuf |
| 64 | CONFIG_PATH=$OUT/$CONFIG.protobuf; |
| 65 | if [[ ! -f $CONFIG_PATH ]]; then |
| 66 | echo 'Config "'$CONFIG_PATH'" not known.' |
| 67 | exit 1 |
| 68 | fi |
| 69 | set -x |
| 70 | adb push $CONFIG_PATH /data/local/tmp/ |
| 71 | set +x |
| 72 | fi |
| 73 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 74 | if tmux has-session -t demo; then |
| 75 | tmux kill-session -t demo |
| 76 | fi |
| 77 | tmux -2 new-session -d -s demo |
| 78 | |
| 79 | if tmux -V | awk '{split($2, ver, "."); if (ver[1] < 2) exit 1 ; else if (ver[1] == 2 && ver[2] < 1) exit 1 }'; then |
| 80 | tmux set-option -g mouse on |
| 81 | else |
| 82 | tmux set-option -g mode-mouse on |
| 83 | tmux set-option -g mouse-resize-pane on |
| 84 | tmux set-option -g mouse-select-pane on |
| 85 | tmux set-option -g mouse-select-window on |
| 86 | fi |
| 87 | |
| 88 | tmux split-window -v |
| 89 | tmux split-window -v |
| 90 | |
| 91 | tmux select-layout even-vertical |
| 92 | |
| 93 | tmux select-pane -t 0 |
| 94 | tmux send-keys "clear" C-m |
| 95 | tmux send-keys "adb shell" C-m |
| 96 | |
| 97 | tmux select-pane -t 1 |
| 98 | tmux send-keys "clear" C-m |
| 99 | tmux send-keys "adb shell" C-m |
| 100 | |
| 101 | tmux select-pane -t 2 |
| 102 | tmux send-keys "clear" C-m |
| 103 | tmux send-keys "adb shell" C-m |
| 104 | |
Hector Dearman | c88a66d | 2018-02-01 14:07:14 +0000 | [diff] [blame] | 105 | sleep 2 |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 106 | |
| 107 | tmux select-pane -t 1 |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 108 | tmux send-keys "$PREFIX /data/local/tmp/traced" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 109 | |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 110 | tmux select-pane -t 0 |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 111 | tmux send-keys "$PREFIX /data/local/tmp/traced_probes" Enter |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 112 | |
| 113 | tmux select-pane -t 2 |
Hector Dearman | c9c183a | 2018-02-08 12:01:12 +0000 | [diff] [blame] | 114 | tmux send-keys "$PREFIX /data/local/tmp/perfetto -c $CONFIG_DEVICE_PATH -o /data/local/tmp/trace" |
Primiano Tucci | b7cca20 | 2018-01-29 16:30:47 +0000 | [diff] [blame] | 115 | |
| 116 | # Select consumer pane. |
| 117 | tmux select-pane -t 2 |
| 118 | |
| 119 | tmux -2 attach-session -t demo |
| 120 | |
| 121 | TRACE=$HOME/Downloads/trace.json |
| 122 | echo -e "\n\x1b[32mPulling trace into $TRACE\x1b[0m" |
| 123 | set -x |
| 124 | adb pull /data/local/tmp/trace /tmp/trace.protobuf |
| 125 | $OUT/trace_to_text systrace < /tmp/trace.protobuf > $TRACE |