libevl/utils/evl-trace

158 lines
3.2 KiB
Bash
Executable File

#! /bin/sh
# SPDX-License-Identifier: MIT
usage() {
echo >&2 "usage: $(basename $1) [-e[<trace_group>]] [-E<tracepoint_file>] [-t] [-s<buffer_size>]] [-d] [-p] [-f] [-h] [-c<cpu>]"
}
args=$(getopt -n $(basename $0) 'e::E:s:dc:pfht@' "$@")
if [ $? -ne 0 ]; then
usage $0
exit 1
fi
enable=false
disable=false
print=true
bufsz=128
pcpu=
help=false
run_or_trace="eval "
tracepoint_file=
trace_groups=
event_list=
set -- $args
for opt
do
case "$opt" in
-e) enable=true
disable=false
group=$(eval echo $2)
if test x$group = x; then
trace_groups="all"
else
trace_groups="$trace_groups $group"
shift
fi
shift
;;
-E) enable=true
disable=false
tracepoint_file=$(eval echo $2)
shift
;;
-s) bufsz=$(eval echo $2)
shift
shift
;;
-d) enable=false
disable=true
shift
;;
-p) print=true
shift
;;
-f) trace_groups=all
shift
;;
-c) pcpu=per_cpu/cpu$(eval echo $2)/
shift
shift
;;
-t) run_or_trace="echo ";
shift
;;
-h) help=true;
shift
;;
-@) echo "ftrace control front-end for EVL"
exit 0;;
--) shift;
break
;;
esac
done
if test x$help = xtrue; then
usage $0
exit 0
fi
if test \! -d $EVL_TRACEDIR; then
echo >&2 "no kernel support for tracing"
exit 2
fi
if test \! -d $EVL_TRACEDIR/events/evl; then
echo >&2 "no EVL core in kernel"
exit 2
fi
for group in $trace_groups
do
if test $group = all; then
event_list=""
break
fi
if test \! -r $EVL_CMDDIR/trace.$group; then
echo >&2 "no trace group '$group'"
exit 1
fi
event_list="$event_list $(cat $EVL_CMDDIR/trace.$group)"
done
if test \! x$tracepoint_file = x; then
if test \! -r $tracepoint_file; then
echo >&2 "cannot read tracepoint file '$tracepoint_file'"
exit 1
fi
event_list="$event_list $(cat $tracepoint_file)"
fi
cd $EVL_TRACEDIR
if test x$enable = xtrue; then
echo nop > current_tracer
test -r snapshot && echo 0 > snapshot
echo $bufsz > ${pcpu}buffer_size_kb
if test \! x"$event_list" = x; then
for event in $event_list
do
if test -r events/$event; then
$run_or_trace "echo 1 > events/$event/enable"
fi
done
elif cat available_tracers | grep -qw function; then
$run_or_trace "echo function > current_tracer"
$run_or_trace "echo 1 > events/enable"
else
echo >&2 "kernel function tracer is not available"
exit 2
fi
warn=
if test -r ${pcpu}snapshot; then
$run_or_trace "echo 1 > ${pcpu}snapshot"
$run_or_trace "echo \!snapshot > events/evl/evl_trigger/trigger"
$run_or_trace "echo snapshot > events/evl/evl_trigger/trigger"
else
warn=" (no snapshot)"
fi
$run_or_trace "echo 1 > tracing_on"
echo "tracing enabled$warn"
print=false
elif test x$disable = xtrue; then
echo 0 > tracing_on
echo 0 > events/enable
echo nop > current_tracer
test -r snapshot && echo 0 > snapshot
echo "tracing disabled"
print=false
fi
if test x$print = xtrue; then
test -r ${pcpu}snapshot && cat ${pcpu}snapshot || echo "no snapshot."
fi
exit 0