numam-spdk/scripts/bpf/gen_enums.sh
Jim Harris 3a0f624499 nvmf: add USDT probes for subsystem state changes
Also add scripts/bpf/nvmf.bt to enable and log these
probes.

This patch also adds a script that can generate
a bpftrace script snippet with string maps for
needed enumerations (currently nvmf_tgt_state and
spdk_nvmf_subsystem_state).  This allows us to
dynamically generate this from the source code, and
can be extended for other enums we may want to
add in the future.

Thanks to Michal Berger for converting my original
gen_enums.py script into gen_enums.sh!

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Signed-off-by: Michal Berger <michalx.berger@intel.com>
Change-Id: Iff34a6218aef40055ac14932eea5fc00e1c8bcf5
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7194
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
2021-06-08 08:27:15 +00:00

53 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
rootdir=$(git rev-parse --show-toplevel)
_print_enums() {
local enum_type=$1 enum_string=$2 enum_prefix=$3 enum output
output=$(< "$rootdir/$(git -C "$rootdir" grep -l "$enum_string" -- lib module)")
# Isolate the enum block
output=${output#*$enum_string$'\n'} output=${output%%$'\n'\};*}
# Fold it onto an array
IFS="," read -ra output <<< "${output//[[:space:]]/}"
# Drop the assignments
output=("${output[@]/=*/}")
for enum in "${!output[@]}"; do
if [[ ${output[enum]} != "$enum_prefix"* ]]; then
printf 'enum name %s does not start with expected prefix %s\n' "${output[enum]}" "$enum_prefix"
return 1
fi >&2
printf ' @%s[%d] = "%s";\n' "$enum_type" "$enum" "${output[enum]#$enum_prefix}"
done
}
print_enums() {
for state in "${!state_enums[@]}"; do
_print_enums "$state" "${state_enums["$state"]}" "${state_prefix["$state"]}"
done
}
print_clear() { printf ' clear(@%s);\n' "${!state_enums[@]}"; }
declare -A state_enums=() state_prefix=()
state_enums["target"]="enum nvmf_tgt_state {"
state_enums["subsystem"]="enum spdk_nvmf_subsystem_state {"
state_prefix["target"]=NVMF_TGT_
state_prefix["subsystem"]=SPDK_NVMF_SUBSYSTEM_
enums=$(print_enums)
clear=$(print_clear)
cat <<- ENUM
BEGIN {
$enums
}
END {
$clear
}
ENUM