blob: b10ff5e0e664b340147392369b022dc4a38e4692 [file] [log] [blame]
Primiano Tuccib7cca202018-01-29 16:30:47 +00001#!/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.
15set -e
16
Hector Dearman9b89d472018-02-28 12:07:21 +000017function is_monolithic {
Hector Dearmanc9c183a2018-02-08 12:01:12 +000018 local out=$1
19 gn args $out --list --short | grep 'monolithic_binaries = true' > /dev/null
20 return $?
21}
22
Hector Dearman9b89d472018-02-28 12:07:21 +000023function adb_supports_push_sync {
24 adb --help | grep 'push.*\[--sync\]'
25}
26
27function 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 Tuccib7cca202018-01-29 16:30:47 +000036# If not set guess the OUT dir using the latest directory.
37if [ ! -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
41fi
42
Hector Dearmanc88a66d2018-02-01 14:07:14 +000043# 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.
45CONFIG="${CONFIG:-:test}"
46
47ninja -C $OUT traced traced_probes perfetto trace_to_text test/configs
Primiano Tuccib7cca202018-01-29 16:30:47 +000048
Hector Dearman9b89d472018-02-28 12:07:21 +000049push $OUT/traced /data/local/tmp/
50push $OUT/traced_probes /data/local/tmp/
51push $OUT/perfetto /data/local/tmp/
Primiano Tuccib7cca202018-01-29 16:30:47 +000052
Hector Dearmanc9c183a2018-02-08 12:01:12 +000053PREFIX=""
54if ! 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
59fi
60
Hector Dearmanc88a66d2018-02-01 14:07:14 +000061CONFIG_DEVICE_PATH=$CONFIG
62if [[ "$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
72fi
73
Primiano Tuccib7cca202018-01-29 16:30:47 +000074if tmux has-session -t demo; then
75 tmux kill-session -t demo
76fi
77tmux -2 new-session -d -s demo
78
79if 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
81else
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
86fi
87
88tmux split-window -v
89tmux split-window -v
90
91tmux select-layout even-vertical
92
93tmux select-pane -t 0
94tmux send-keys "clear" C-m
95tmux send-keys "adb shell" C-m
96
97tmux select-pane -t 1
98tmux send-keys "clear" C-m
99tmux send-keys "adb shell" C-m
100
101tmux select-pane -t 2
102tmux send-keys "clear" C-m
103tmux send-keys "adb shell" C-m
104
Hector Dearmanc88a66d2018-02-01 14:07:14 +0000105sleep 2
Primiano Tuccib7cca202018-01-29 16:30:47 +0000106
107tmux select-pane -t 1
Hector Dearmanc9c183a2018-02-08 12:01:12 +0000108tmux send-keys "$PREFIX /data/local/tmp/traced" Enter
Primiano Tuccib7cca202018-01-29 16:30:47 +0000109
Primiano Tuccib7cca202018-01-29 16:30:47 +0000110tmux select-pane -t 0
Hector Dearmanc9c183a2018-02-08 12:01:12 +0000111tmux send-keys "$PREFIX /data/local/tmp/traced_probes" Enter
Primiano Tuccib7cca202018-01-29 16:30:47 +0000112
113tmux select-pane -t 2
Hector Dearmanc9c183a2018-02-08 12:01:12 +0000114tmux send-keys "$PREFIX /data/local/tmp/perfetto -c $CONFIG_DEVICE_PATH -o /data/local/tmp/trace"
Primiano Tuccib7cca202018-01-29 16:30:47 +0000115
116# Select consumer pane.
117tmux select-pane -t 2
118
119tmux -2 attach-session -t demo
120
121TRACE=$HOME/Downloads/trace.json
122echo -e "\n\x1b[32mPulling trace into $TRACE\x1b[0m"
123set -x
124adb pull /data/local/tmp/trace /tmp/trace.protobuf
125$OUT/trace_to_text systrace < /tmp/trace.protobuf > $TRACE