xref: /openbmc/openbmc-tools/tracing/trace (revision cf3c1e67)
1*cf3c1e67SAndrew Jeffery#!/bin/bash
2*cf3c1e67SAndrew Jeffery#
3*cf3c1e67SAndrew Jeffery# SPDX-License-Identifier: Apache-2.0
4*cf3c1e67SAndrew Jeffery# Copyright (C) 2018 IBM Corp.
5*cf3c1e67SAndrew Jeffery
6*cf3c1e67SAndrew Jefferyset -eou pipefail
7*cf3c1e67SAndrew Jeffery
8*cf3c1e67SAndrew Jefferyif [ $# -lt 2 ]
9*cf3c1e67SAndrew Jefferythen
10*cf3c1e67SAndrew Jeffery	echo Usage: $0 [USER@]HOST EVENTSET [EVENTSET...]
11*cf3c1e67SAndrew Jeffery	echo
12*cf3c1e67SAndrew Jeffery	echo Valid EVENTSETs: fsi, occ, sbefifo, timer, sched
13*cf3c1e67SAndrew Jeffery	exit 1
14*cf3c1e67SAndrew Jefferyfi
15*cf3c1e67SAndrew Jeffery
16*cf3c1e67SAndrew JefferyTRACE_TARGET="$1"
17*cf3c1e67SAndrew Jefferyshift 1
18*cf3c1e67SAndrew JefferyTRACE_EVENT_SET="$@"
19*cf3c1e67SAndrew Jeffery
20*cf3c1e67SAndrew JefferyTRACESCRIPT_PATH="$(mktemp obmc-fsi-trace.XXXXXX)"
21*cf3c1e67SAndrew JefferyTRACESCRIPT="$(basename "${TRACESCRIPT_PATH}")"
22*cf3c1e67SAndrew Jeffery
23*cf3c1e67SAndrew Jefferyon_exit() {
24*cf3c1e67SAndrew Jeffery	rm -f "${TRACESCRIPT_PATH}"
25*cf3c1e67SAndrew Jeffery}
26*cf3c1e67SAndrew Jeffery
27*cf3c1e67SAndrew Jefferytrap on_exit EXIT
28*cf3c1e67SAndrew Jeffery
29*cf3c1e67SAndrew Jefferycat > "${TRACESCRIPT_PATH}" <<-EOF
30*cf3c1e67SAndrew Jefferyset -eou pipefail
31*cf3c1e67SAndrew Jeffery
32*cf3c1e67SAndrew Jefferyset -x
33*cf3c1e67SAndrew Jeffery
34*cf3c1e67SAndrew Jeffery# Look Ma! Associative arrays in ash!
35*cf3c1e67SAndrew JefferyEVENT_fsi="fsi fsi_master_gpio"
36*cf3c1e67SAndrew JefferyEVENT_occ="occ hwmon_occ"
37*cf3c1e67SAndrew JefferyEVENT_sbefifo="sbefifo"
38*cf3c1e67SAndrew JefferyEVENT_timer="timer/timer_start timer/timer_cancel timer/timer_expire_entry timer/timer_expire_exit"
39*cf3c1e67SAndrew JefferyEVENT_sched="sched/sched_switch sched/sched_wakeup sched/sched_wakeup_new sched/sched_waking"
40*cf3c1e67SAndrew Jeffery
41*cf3c1e67SAndrew Jefferyon_exit() {
42*cf3c1e67SAndrew Jefferyfor elem in ${TRACE_EVENT_SET}
43*cf3c1e67SAndrew Jefferydo
44*cf3c1e67SAndrew Jeffery	# Abuse eval(1) to extract the list of tracepoints to enable from our
45*cf3c1e67SAndrew Jeffery	# fake associative arrays
46*cf3c1e67SAndrew Jeffery	eval 'trace=\\\${EVENT_\${elem}}'
47*cf3c1e67SAndrew Jeffery	for event in \$(eval echo \${trace})
48*cf3c1e67SAndrew Jeffery	do
49*cf3c1e67SAndrew Jeffery		echo 0 > /sys/kernel/debug/tracing/events/\${event}/enable
50*cf3c1e67SAndrew Jeffery	done
51*cf3c1e67SAndrew Jefferydone
52*cf3c1e67SAndrew Jeffery	echo 0 > /sys/kernel/debug/tracing/tracing_on
53*cf3c1e67SAndrew Jeffery}
54*cf3c1e67SAndrew Jeffery
55*cf3c1e67SAndrew Jefferytrap on_exit EXIT
56*cf3c1e67SAndrew Jeffery
57*cf3c1e67SAndrew Jefferycat /sys/kernel/debug/tracing/per_cpu/cpu0/trace_pipe &
58*cf3c1e67SAndrew JefferyCAT_PID=\$!
59*cf3c1e67SAndrew Jeffery
60*cf3c1e67SAndrew Jefferyfor elem in ${TRACE_EVENT_SET}
61*cf3c1e67SAndrew Jefferydo
62*cf3c1e67SAndrew Jeffery	# See comment in the disable path
63*cf3c1e67SAndrew Jeffery	eval 'trace=\\\${EVENT_\${elem}}'
64*cf3c1e67SAndrew Jeffery	for event in \$(eval echo \${trace})
65*cf3c1e67SAndrew Jeffery	do
66*cf3c1e67SAndrew Jeffery		echo 1 > /sys/kernel/debug/tracing/events/\${event}/enable
67*cf3c1e67SAndrew Jeffery	done
68*cf3c1e67SAndrew Jefferydone
69*cf3c1e67SAndrew Jefferyecho 1 > /sys/kernel/debug/tracing/tracing_on
70*cf3c1e67SAndrew Jeffery
71*cf3c1e67SAndrew Jefferyread
72*cf3c1e67SAndrew Jeffery
73*cf3c1e67SAndrew Jefferykill \${CAT_PID}
74*cf3c1e67SAndrew JefferyEOF
75*cf3c1e67SAndrew Jeffery
76*cf3c1e67SAndrew Jefferyscp "${TRACESCRIPT_PATH}" "${TRACE_TARGET}":/tmp/"${TRACESCRIPT}"
77*cf3c1e67SAndrew Jefferyssh "${TRACE_TARGET}" "/bin/sh -x /tmp/'${TRACESCRIPT}'"
78