348ff890ad
Allow redirecting output to file. Using simple "if" for an environment variable, as script arguments number is variable and using getops seems like an overkill. Signed-off-by: Karol Latecki <karol.latecki@intel.com> Change-Id: I7e219bb1fd6377bc20c44b76cec3685b32e9316c Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8643 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
20 lines
540 B
Bash
Executable File
20 lines
540 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_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
|
|
|
|
bpftrace -p $1 -e "$BPF_SCRIPT" ${BPF_OUTFILE:+-o "$BPF_OUTFILE"}
|