1#!/bin/bash 2# 3# SPDX-License-Identifier: Apache-2.0 4# Copyright (C) 2018 IBM Corp. 5 6set -eou pipefail 7 8if [ $# -lt 2 ] 9then 10 echo Usage: $0 [USER@]HOST EVENTSET [EVENTSET...] 11 echo 12 echo Valid EVENTSETs: fsi, occ, sbefifo, timer, sched 13 exit 1 14fi 15 16TRACE_TARGET="$1" 17shift 1 18TRACE_EVENT_SET="$@" 19 20TRACESCRIPT_PATH="$(mktemp obmc-fsi-trace.XXXXXX)" 21TRACESCRIPT="$(basename "${TRACESCRIPT_PATH}")" 22 23function on_exit() { 24 rm -f "${TRACESCRIPT_PATH}" 25} 26 27trap on_exit EXIT 28 29cat > "${TRACESCRIPT_PATH}" <<-EOF 30set -eou pipefail 31 32set -x 33 34# Look Ma! Associative arrays in ash! 35EVENT_fsi="fsi fsi_master_gpio" 36EVENT_occ="occ hwmon_occ" 37EVENT_sbefifo="sbefifo" 38EVENT_timer="timer/timer_start timer/timer_cancel timer/timer_expire_entry timer/timer_expire_exit" 39EVENT_sched="sched/sched_switch sched/sched_wakeup sched/sched_wakeup_new sched/sched_waking" 40 41on_exit() { 42for elem in ${TRACE_EVENT_SET} 43do 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 51done 52 echo 0 > /sys/kernel/debug/tracing/tracing_on 53} 54 55trap on_exit EXIT 56 57cat /sys/kernel/debug/tracing/per_cpu/cpu0/trace_pipe & 58CAT_PID=\$! 59 60for elem in ${TRACE_EVENT_SET} 61do 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 68done 69echo 1 > /sys/kernel/debug/tracing/tracing_on 70 71read 72 73kill \${CAT_PID} 74EOF 75 76scp "${TRACESCRIPT_PATH}" "${TRACE_TARGET}":/tmp/"${TRACESCRIPT}" 77ssh "${TRACE_TARGET}" "/bin/sh -x /tmp/'${TRACESCRIPT}'" 78