2021-04-30 22:14:51 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-02-10 00:04:19 +00:00
|
|
|
set -e
|
|
|
|
|
2021-04-30 22:14:51 +00:00
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
echo "usage: $0 <pid> <script>"
|
2021-07-05 13:23:39 +00:00
|
|
|
echo ""
|
|
|
|
echo "Environment variable BPF_OUTFILE can be set to save results to a file"
|
|
|
|
echo "rather than print to stdout."
|
2021-04-30 22:14:51 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
SCRIPTS_DIR=$(readlink -f $(dirname $0))
|
|
|
|
BIN_PATH=$(readlink -f /proc/$1/exe)
|
2021-02-10 00:04:19 +00:00
|
|
|
BPF_SCRIPT=$($SCRIPTS_DIR/bpf/gen_enums.sh)
|
|
|
|
BPF_SCRIPT+=$(sed "s#__EXE__#${BIN_PATH}#g" "${@:2}" | sed "s#__PID__#${1}#g")
|
|
|
|
if [ -n "$ECHO_SCRIPT" ]; then
|
|
|
|
echo "$BPF_SCRIPT"
|
|
|
|
fi
|
2021-07-05 13:23:39 +00:00
|
|
|
|
|
|
|
bpftrace -p $1 -e "$BPF_SCRIPT" ${BPF_OUTFILE:+-o "$BPF_OUTFILE"}
|