blob: 9a14356a4bc9cf9c51ba6e59f1e402992bb16d0c [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
Primiano Tucci2ffd1a52018-03-27 01:01:30 +010017if [ "$TMPDIR" == "" ]; then
18 TMPDIR=/tmp
19fi
20
Hector Dearman9b89d472018-02-28 12:07:21 +000021function is_monolithic {
Hector Dearmanc9c183a2018-02-08 12:01:12 +000022 local out=$1
Hector Dearmanc067d412018-03-16 17:01:41 +000023 gn args $out --list --short | grep 'monolithic_binaries = true' 2>&1 >/dev/null
24 return $?
25}
26
27function is_android {
28 local out=$1
29 gn args $out --list --short | grep 'target_os = "android"' 2>&1 >/dev/null
Hector Dearmanc9c183a2018-02-08 12:01:12 +000030 return $?
31}
32
Hector Dearman0ff07c72018-03-15 09:54:46 +000033function reset_tracing {
Primiano Tucci2ffd1a52018-03-27 01:01:30 +010034 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 Dearman0ff07c72018-03-15 09:54:46 +000044}
45
Hector Dearman9b89d472018-02-28 12:07:21 +000046function adb_supports_push_sync {
Hector Dearmanc067d412018-03-16 17:01:41 +000047 adb --help | grep 'push.*\[--sync\]' 2>&1 >/dev/null
48}
49
Hector Dearman9b89d472018-02-28 12:07:21 +000050function push {
Hector Dearmanc067d412018-03-16 17:01:41 +000051 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 Dearman9b89d472018-02-28 12:07:21 +000061 fi
Hector Dearmanc067d412018-03-16 17:01:41 +000062}
63
64function pull {
65 if is_android $OUT; then
66 echo adb pull $DIR/$1 $2
67 adb pull $DIR/$1 $2
68 else
Primiano Tucci2ffd1a52018-03-27 01:01:30 +010069 echo mv $DIR/$1 $2
70 mv $DIR/$1 $2
Hector Dearmanc067d412018-03-16 17:01:41 +000071 fi
Hector Dearman9b89d472018-02-28 12:07:21 +000072}
73
Primiano Tuccib7cca202018-01-29 16:30:47 +000074# If not set guess the OUT dir using the latest directory.
75if [ ! -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
79fi
80
Hector Dearmanc88a66d2018-02-01 14:07:14 +000081# 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.
83CONFIG="${CONFIG:-:test}"
84
Hector Dearmanc067d412018-03-16 17:01:41 +000085if is_android $OUT ; then
86 DIR=/data/local/tmp
87else
Primiano Tucci2ffd1a52018-03-27 01:01:30 +010088 DIR=$(mktemp -p $TMPDIR -d perfetto.XXXXXX)
Hector Dearmanc067d412018-03-16 17:01:41 +000089fi
90
Lalit Magantic27975c2018-04-10 21:42:18 +010091tools/ninja -C $OUT traced traced_probes perfetto trace_to_text test/configs
Primiano Tuccib7cca202018-01-29 16:30:47 +000092
Hector Dearmanc067d412018-03-16 17:01:41 +000093push $OUT/traced
94push $OUT/traced_probes
95push $OUT/perfetto
Hector Dearman0ff07c72018-03-15 09:54:46 +000096reset_tracing
Primiano Tuccib7cca202018-01-29 16:30:47 +000097
Florian Mayerb0f00712018-04-04 16:35:45 +010098if is_android $OUT; then
99 PREFIX="
100PERFETTO_CONSUMER_SOCK_NAME=/data/misc/perfetto-traces/test_consumer_socket
101PERFETTO_PRODUCER_SOCK_NAME=/data/misc/perfetto-traces/test_producer_socket"
102else
103 PREFIX=""
104fi
105
Hector Dearmanc067d412018-03-16 17:01:41 +0000106if ! is_monolithic $OUT; then
Florian Mayerb0f00712018-04-04 16:35:45 +0100107 PREFIX="$PREFIX LD_LIBRARY_PATH=$DIR"
Hector Dearmanc067d412018-03-16 17:01:41 +0000108 push $OUT/libtraced_shared.so
Hector Dearmanc9c183a2018-02-08 12:01:12 +0000109fi
110
Hector Dearmanc88a66d2018-02-01 14:07:14 +0000111CONFIG_DEVICE_PATH=$CONFIG
112if [[ "$CONFIG" != ":test" ]]; then
Hector Dearmanc067d412018-03-16 17:01:41 +0000113 CONFIG_DEVICE_PATH=$DIR/$CONFIG.protobuf
Hector Dearmanc88a66d2018-02-01 14:07:14 +0000114 CONFIG_PATH=$OUT/$CONFIG.protobuf;
115 if [[ ! -f $CONFIG_PATH ]]; then
116 echo 'Config "'$CONFIG_PATH'" not known.'
117 exit 1
118 fi
Hector Dearmanc067d412018-03-16 17:01:41 +0000119 push $CONFIG_PATH
Hector Dearmanc88a66d2018-02-01 14:07:14 +0000120fi
121
Primiano Tuccib7cca202018-01-29 16:30:47 +0000122if tmux has-session -t demo; then
123 tmux kill-session -t demo
124fi
125tmux -2 new-session -d -s demo
126
127if 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
129else
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
134fi
135
136tmux split-window -v
137tmux split-window -v
138
139tmux select-layout even-vertical
140
141tmux select-pane -t 0
142tmux send-keys "clear" C-m
Hector Dearmanc067d412018-03-16 17:01:41 +0000143if is_android $OUT; then
144 tmux send-keys "adb shell" C-m
145fi
Primiano Tuccib7cca202018-01-29 16:30:47 +0000146
147tmux select-pane -t 1
148tmux send-keys "clear" C-m
Hector Dearmanc067d412018-03-16 17:01:41 +0000149if is_android $OUT; then
150 tmux send-keys "adb shell" C-m
151fi
Primiano Tuccib7cca202018-01-29 16:30:47 +0000152
153tmux select-pane -t 2
154tmux send-keys "clear" C-m
Hector Dearmanc067d412018-03-16 17:01:41 +0000155if is_android $OUT; then
156 tmux send-keys "adb shell" C-m
157fi
Primiano Tuccib7cca202018-01-29 16:30:47 +0000158
Hector Dearmanc88a66d2018-02-01 14:07:14 +0000159sleep 2
Primiano Tuccib7cca202018-01-29 16:30:47 +0000160
161tmux select-pane -t 1
Hector Dearmanc067d412018-03-16 17:01:41 +0000162tmux send-keys "$PREFIX $DIR/traced" Enter
Primiano Tuccib7cca202018-01-29 16:30:47 +0000163
Primiano Tuccib7cca202018-01-29 16:30:47 +0000164tmux select-pane -t 0
Primiano Tucci2ffd1a52018-03-27 01:01:30 +0100165tmux send-keys "$PREFIX $DIR/traced_probes" Enter
Primiano Tuccib7cca202018-01-29 16:30:47 +0000166
167tmux select-pane -t 2
Hector Dearmanc067d412018-03-16 17:01:41 +0000168tmux send-keys "$PREFIX $DIR/perfetto -c $CONFIG_DEVICE_PATH -o $DIR/trace"
Primiano Tuccib7cca202018-01-29 16:30:47 +0000169
170# Select consumer pane.
171tmux select-pane -t 2
172
173tmux -2 attach-session -t demo
Hector Dearmana7c04f82018-03-29 11:31:24 +0100174
Hector Dearman3c4e5c22018-03-29 11:31:55 +0100175reset_tracing
Hector Dearmana7c04f82018-03-29 11:31:24 +0100176
177TRACE=$HOME/Downloads/trace
178pull trace /tmp/trace.protobuf
179echo -e "\n\x1b[32mPulling trace into $TRACE.pbtext\x1b[0m"
180$OUT/trace_to_text text < /tmp/trace.protobuf > $TRACE.pbtext
181echo -e "\n\x1b[32mPulling trace into $TRACE.json\x1b[0m"
182$OUT/trace_to_text systrace < /tmp/trace.protobuf > $TRACE.json