• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
15set -e
16
17if [ "$TMPDIR" == "" ]; then
18  TMPDIR=/tmp
19fi
20
21function is_monolithic {
22  local out=$1
23  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
30  return $?
31}
32
33function reset_tracing {
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
44}
45
46function adb_supports_push_sync {
47  adb --help | grep 'push.*\[--sync\]' 2>&1 >/dev/null
48}
49
50function push {
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
61  fi
62}
63
64function pull {
65  if is_android $OUT; then
66    echo adb pull $DIR/$1 $2
67    adb pull $DIR/$1 $2
68  else
69    echo mv $DIR/$1 $2
70    mv $DIR/$1 $2
71  fi
72}
73
74# 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
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.
83CONFIG="${CONFIG:-:test}"
84
85if is_android $OUT ; then
86  DIR=/data/local/tmp
87else
88  DIR=$(mktemp -p $TMPDIR -d perfetto.XXXXXX)
89fi
90
91tools/ninja -C $OUT traced traced_probes perfetto trace_to_text test/configs
92
93push $OUT/traced
94push $OUT/traced_probes
95push $OUT/perfetto
96reset_tracing
97
98if 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
106if ! is_monolithic $OUT; then
107  PREFIX="$PREFIX LD_LIBRARY_PATH=$DIR"
108  push $OUT/libtraced_shared.so
109fi
110
111CONFIG_DEVICE_PATH=$CONFIG
112if [[ "$CONFIG" != ":test" ]]; then
113  CONFIG_DEVICE_PATH=$DIR/$CONFIG.protobuf
114  CONFIG_PATH=$OUT/$CONFIG.protobuf;
115  if [[ ! -f $CONFIG_PATH ]]; then
116    echo 'Config "'$CONFIG_PATH'" not known.'
117    exit 1
118  fi
119  push $CONFIG_PATH
120fi
121
122if 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
143if is_android $OUT; then
144  tmux send-keys "adb shell" C-m
145fi
146
147tmux select-pane -t 1
148tmux send-keys "clear" C-m
149if is_android $OUT; then
150  tmux send-keys "adb shell" C-m
151fi
152
153tmux select-pane -t 2
154tmux send-keys "clear" C-m
155if is_android $OUT; then
156  tmux send-keys "adb shell" C-m
157fi
158
159sleep 2
160
161tmux select-pane -t 1
162tmux send-keys "$PREFIX $DIR/traced" Enter
163
164tmux select-pane -t 0
165tmux send-keys "$PREFIX $DIR/traced_probes" Enter
166
167tmux select-pane -t 2
168tmux send-keys "$PREFIX $DIR/perfetto -c $CONFIG_DEVICE_PATH -o $DIR/trace"
169
170# Select consumer pane.
171tmux select-pane -t 2
172
173tmux -2 attach-session -t demo
174
175reset_tracing
176
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
183