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