| #!/bin/bash |
| # Copyright (C) 2018 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| set -e |
| |
| function is_monolithic { |
| local out=$1 |
| gn args $out --list --short | grep 'monolithic_binaries = true' 2>&1 >/dev/null |
| return $? |
| } |
| |
| function is_android { |
| local out=$1 |
| gn args $out --list --short | grep 'target_os = "android"' 2>&1 >/dev/null |
| return $? |
| } |
| |
| function reset_tracing { |
| adb shell 'echo 0 > /d/tracing/tracing_on' |
| } |
| |
| function adb_supports_push_sync { |
| adb --help | grep 'push.*\[--sync\]' 2>&1 >/dev/null |
| } |
| |
| function traced_probes_cmd { |
| if is_android $OUT; then |
| echo "$PREFIX $DIR/traced_probes" |
| else |
| echo "sudo $PREFIX $DIR/traced_probes" |
| fi |
| } |
| |
| function push { |
| if is_android $OUT; then |
| local maybe_sync='' |
| if adb_supports_push_sync; then |
| maybe_sync='--sync ' |
| fi |
| echo adb push $maybe_sync $1 $DIR |
| adb push $maybe_sync $1 $DIR |
| else |
| echo cp $1 $DIR |
| cp $1 $DIR |
| fi |
| } |
| |
| function pull { |
| if is_android $OUT; then |
| echo adb pull $DIR/$1 $2 |
| adb pull $DIR/$1 $2 |
| else |
| echo cp $DIR/$1 $2 |
| cp $DIR/$1 $2 |
| fi |
| } |
| |
| # If not set guess the OUT dir using the latest directory. |
| if [ ! -f "$OUT/args.gn" ]; then |
| echo "OUT=$OUT doesn't look like an output directory." |
| echo "Please specify a directory by doing: export OUT=out/xxx" |
| exit 1 |
| fi |
| |
| # You can set the config to one of the files under test/configs e.g. |
| # CONFIG=ftrace.cfg or to :test. Defaults to :test. |
| CONFIG="${CONFIG:-:test}" |
| |
| if is_android $OUT ; then |
| DIR=/data/local/tmp |
| else |
| DIR=$(mktemp -d) |
| fi |
| |
| ninja -C $OUT traced traced_probes perfetto trace_to_text test/configs |
| |
| push $OUT/traced |
| push $OUT/traced_probes |
| push $OUT/perfetto |
| reset_tracing |
| |
| PREFIX="" |
| if ! is_monolithic $OUT; then |
| PREFIX="LD_LIBRARY_PATH=$DIR" |
| push $OUT/libtraced_shared.so |
| fi |
| |
| CONFIG_DEVICE_PATH=$CONFIG |
| if [[ "$CONFIG" != ":test" ]]; then |
| CONFIG_DEVICE_PATH=$DIR/$CONFIG.protobuf |
| CONFIG_PATH=$OUT/$CONFIG.protobuf; |
| if [[ ! -f $CONFIG_PATH ]]; then |
| echo 'Config "'$CONFIG_PATH'" not known.' |
| exit 1 |
| fi |
| push $CONFIG_PATH |
| fi |
| |
| if tmux has-session -t demo; then |
| tmux kill-session -t demo |
| fi |
| tmux -2 new-session -d -s demo |
| |
| if tmux -V | awk '{split($2, ver, "."); if (ver[1] < 2) exit 1 ; else if (ver[1] == 2 && ver[2] < 1) exit 1 }'; then |
| tmux set-option -g mouse on |
| else |
| tmux set-option -g mode-mouse on |
| tmux set-option -g mouse-resize-pane on |
| tmux set-option -g mouse-select-pane on |
| tmux set-option -g mouse-select-window on |
| fi |
| |
| tmux split-window -v |
| tmux split-window -v |
| |
| tmux select-layout even-vertical |
| |
| tmux select-pane -t 0 |
| tmux send-keys "clear" C-m |
| if is_android $OUT; then |
| tmux send-keys "adb shell" C-m |
| fi |
| |
| tmux select-pane -t 1 |
| tmux send-keys "clear" C-m |
| if is_android $OUT; then |
| tmux send-keys "adb shell" C-m |
| fi |
| |
| tmux select-pane -t 2 |
| tmux send-keys "clear" C-m |
| if is_android $OUT; then |
| tmux send-keys "adb shell" C-m |
| fi |
| |
| sleep 2 |
| |
| tmux select-pane -t 1 |
| tmux send-keys "$PREFIX $DIR/traced" Enter |
| |
| tmux select-pane -t 0 |
| tmux send-keys "$(traced_probes_cmd)" Enter |
| |
| tmux select-pane -t 2 |
| tmux send-keys "$PREFIX $DIR/perfetto -c $CONFIG_DEVICE_PATH -o $DIR/trace" |
| |
| # Select consumer pane. |
| tmux select-pane -t 2 |
| |
| tmux -2 attach-session -t demo |
| |
| TRACE=$HOME/Downloads/trace.json |
| echo -e "\n\x1b[32mPulling trace into $TRACE\x1b[0m" |
| pull trace /tmp/trace.protobuf |
| $OUT/trace_to_text systrace < /tmp/trace.protobuf > $TRACE |