Andrew Jeffery | 5d96e7c | 2018-02-08 10:37:03 +1030 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # Copyright (C) 2018 IBM Corp. |
| 5 | |
| 6 | set -eou pipefail |
| 7 | |
| 8 | if [ $# -lt 2 ] |
| 9 | then |
| 10 | echo Usage: $0 [USER@]HOST EVENTSET [EVENTSET...] |
| 11 | echo |
| 12 | echo Valid EVENTSETs: fsi, occ, sbefifo, timer, sched |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | TRACE_TARGET="$1" |
| 17 | shift 1 |
| 18 | TRACE_EVENT_SET="$@" |
| 19 | |
| 20 | TRACESCRIPT_PATH="$(mktemp obmc-fsi-trace.XXXXXX)" |
| 21 | TRACESCRIPT="$(basename "${TRACESCRIPT_PATH}")" |
| 22 | |
| 23 | on_exit() { |
| 24 | rm -f "${TRACESCRIPT_PATH}" |
| 25 | } |
| 26 | |
| 27 | trap on_exit EXIT |
| 28 | |
| 29 | cat > "${TRACESCRIPT_PATH}" <<-EOF |
| 30 | set -eou pipefail |
| 31 | |
| 32 | set -x |
| 33 | |
| 34 | # Look Ma! Associative arrays in ash! |
| 35 | EVENT_fsi="fsi fsi_master_gpio" |
| 36 | EVENT_occ="occ hwmon_occ" |
| 37 | EVENT_sbefifo="sbefifo" |
| 38 | EVENT_timer="timer/timer_start timer/timer_cancel timer/timer_expire_entry timer/timer_expire_exit" |
| 39 | EVENT_sched="sched/sched_switch sched/sched_wakeup sched/sched_wakeup_new sched/sched_waking" |
| 40 | |
| 41 | on_exit() { |
| 42 | for elem in ${TRACE_EVENT_SET} |
| 43 | do |
| 44 | # Abuse eval(1) to extract the list of tracepoints to enable from our |
| 45 | # fake associative arrays |
| 46 | eval 'trace=\\\${EVENT_\${elem}}' |
| 47 | for event in \$(eval echo \${trace}) |
| 48 | do |
| 49 | echo 0 > /sys/kernel/debug/tracing/events/\${event}/enable |
| 50 | done |
| 51 | done |
| 52 | echo 0 > /sys/kernel/debug/tracing/tracing_on |
| 53 | } |
| 54 | |
| 55 | trap on_exit EXIT |
| 56 | |
| 57 | cat /sys/kernel/debug/tracing/per_cpu/cpu0/trace_pipe & |
| 58 | CAT_PID=\$! |
| 59 | |
| 60 | for elem in ${TRACE_EVENT_SET} |
| 61 | do |
| 62 | # See comment in the disable path |
| 63 | eval 'trace=\\\${EVENT_\${elem}}' |
| 64 | for event in \$(eval echo \${trace}) |
| 65 | do |
| 66 | echo 1 > /sys/kernel/debug/tracing/events/\${event}/enable |
| 67 | done |
| 68 | done |
| 69 | echo 1 > /sys/kernel/debug/tracing/tracing_on |
| 70 | |
| 71 | read |
| 72 | |
| 73 | kill \${CAT_PID} |
| 74 | EOF |
| 75 | |
| 76 | scp "${TRACESCRIPT_PATH}" "${TRACE_TARGET}":/tmp/"${TRACESCRIPT}" |
| 77 | ssh "${TRACE_TARGET}" "/bin/sh -x /tmp/'${TRACESCRIPT}'" |