numam-spdk/scripts/bpftrace.sh
Konrad Sztyber 143aa5cb1f scripts/bpftrace: use SO names in bpftrace scripts
If an USDT probe is defined within a shared object, bpftrace expects the
path to that shared object instead of an executable.  This means that we
need to replace __EXE__ in the bpftrace scripts differently, depending
on whether the application was linked statically or dynamically.

This is now done by the `scripts/bpf/gen.py` script.  It lists all
available probes, along with their locations, of a process.  Then, it
matches them to those described in a bpftrace script replacing the
__EXE__ markers with the listed location (either a path to the
executable or a shared library).  If a bpftrace script uses a probe that
isn't listed, its __EXE__ will be replaced by a path to the executable.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I7c323d5f7d948ea57cf8d4d3132e4d59a2de594f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9807
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2021-10-20 23:39:59 +00:00

20 lines
515 B
Bash
Executable File

#!/usr/bin/env bash
set -e
if [ $# -lt 2 ]; then
echo "usage: $0 <pid> <script>"
echo ""
echo "Environment variable BPF_OUTFILE can be set to save results to a file"
echo "rather than print to stdout."
exit 1
fi
SCRIPTS_DIR=$(readlink -f $(dirname $0))
BIN_PATH=$(readlink -f /proc/$1/exe)
BPF_SCRIPT=$($SCRIPTS_DIR/bpf/gen.py -p $1 "${@:2}")
BPF_SCRIPT+=$($SCRIPTS_DIR/bpf/gen_enums.sh)
if [ -n "$ECHO_SCRIPT" ]; then
echo "$BPF_SCRIPT"
fi
bpftrace -p $1 -e "$BPF_SCRIPT" ${BPF_OUTFILE:+-o "$BPF_OUTFILE"}