perf build: Add shellcheck to tools/perf scripts
Address shell check errors/warnings in perf-archive.sh and perf-completion.sh. Reviewed-by: James Clark <james.clark@arm.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Oliver Upton <oliver.upton@linux.dev> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Link: https://lore.kernel.org/r/20240409023216.2342032-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
20b0027ca1
commit
646e22eb87
@ -59,3 +59,17 @@ perf-y += ui/
|
|||||||
perf-y += scripts/
|
perf-y += scripts/
|
||||||
|
|
||||||
gtk-y += ui/gtk/
|
gtk-y += ui/gtk/
|
||||||
|
|
||||||
|
ifdef SHELLCHECK
|
||||||
|
SHELL_TESTS := $(wildcard *.sh)
|
||||||
|
TEST_LOGS := $(SHELL_TESTS:%=%.shellcheck_log)
|
||||||
|
else
|
||||||
|
SHELL_TESTS :=
|
||||||
|
TEST_LOGS :=
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(OUTPUT)%.shellcheck_log: %
|
||||||
|
$(call rule_mkdir)
|
||||||
|
$(Q)$(call echo-cmd,test)shellcheck -s bash -a -S warning "$<" > $@ || (cat $@ && rm $@ && false)
|
||||||
|
|
||||||
|
perf-y += $(TEST_LOGS)
|
||||||
|
@ -34,7 +34,7 @@ if [ $UNPACK -eq 1 ]; then
|
|||||||
TARGET=`find . -regex "\./perf.*\.tar\.bz2"`
|
TARGET=`find . -regex "\./perf.*\.tar\.bz2"`
|
||||||
TARGET_NUM=`echo -n "$TARGET" | grep -c '^'`
|
TARGET_NUM=`echo -n "$TARGET" | grep -c '^'`
|
||||||
|
|
||||||
if [ -z "$TARGET" -o $TARGET_NUM -gt 1 ]; then
|
if [ -z "$TARGET" ] || [ $TARGET_NUM -gt 1 ]; then
|
||||||
echo -e "Error: $TARGET_NUM files found for unpacking:\n$TARGET"
|
echo -e "Error: $TARGET_NUM files found for unpacking:\n$TARGET"
|
||||||
echo "Provide the requested file as an argument"
|
echo "Provide the requested file as an argument"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -108,6 +108,8 @@ __perf__ltrim_colon_completions()
|
|||||||
|
|
||||||
__perfcomp ()
|
__perfcomp ()
|
||||||
{
|
{
|
||||||
|
# Expansion of spaces to array is deliberate.
|
||||||
|
# shellcheck disable=SC2207
|
||||||
COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
|
COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,13 +129,13 @@ __perf_prev_skip_opts ()
|
|||||||
|
|
||||||
let i=cword-1
|
let i=cword-1
|
||||||
cmds_=$($cmd $1 --list-cmds)
|
cmds_=$($cmd $1 --list-cmds)
|
||||||
prev_skip_opts=()
|
prev_skip_opts=""
|
||||||
while [ $i -ge 0 ]; do
|
while [ $i -ge 0 ]; do
|
||||||
if [[ ${words[i]} == $1 ]]; then
|
if [[ ${words[i]} == "$1" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
for cmd_ in $cmds_; do
|
for cmd_ in $cmds_; do
|
||||||
if [[ ${words[i]} == $cmd_ ]]; then
|
if [[ ${words[i]} == "$cmd_" ]]; then
|
||||||
prev_skip_opts=${words[i]}
|
prev_skip_opts=${words[i]}
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -164,9 +166,10 @@ __perf_main ()
|
|||||||
$prev_skip_opts == @(record|stat|top) ]]; then
|
$prev_skip_opts == @(record|stat|top) ]]; then
|
||||||
|
|
||||||
local cur1=${COMP_WORDS[COMP_CWORD]}
|
local cur1=${COMP_WORDS[COMP_CWORD]}
|
||||||
local raw_evts=$($cmd list --raw-dump hw sw cache tracepoint pmu sdt)
|
local raw_evts
|
||||||
local arr s tmp result cpu_evts
|
local arr s tmp result cpu_evts
|
||||||
|
|
||||||
|
raw_evts=$($cmd list --raw-dump hw sw cache tracepoint pmu sdt)
|
||||||
# aarch64 doesn't have /sys/bus/event_source/devices/cpu/events
|
# aarch64 doesn't have /sys/bus/event_source/devices/cpu/events
|
||||||
if [[ `uname -m` != aarch64 ]]; then
|
if [[ `uname -m` != aarch64 ]]; then
|
||||||
cpu_evts=$(ls /sys/bus/event_source/devices/cpu/events)
|
cpu_evts=$(ls /sys/bus/event_source/devices/cpu/events)
|
||||||
@ -175,10 +178,12 @@ __perf_main ()
|
|||||||
if [[ "$cur1" == */* && ${cur1#*/} =~ ^[A-Z] ]]; then
|
if [[ "$cur1" == */* && ${cur1#*/} =~ ^[A-Z] ]]; then
|
||||||
OLD_IFS="$IFS"
|
OLD_IFS="$IFS"
|
||||||
IFS=" "
|
IFS=" "
|
||||||
|
# Expansion of spaces to array is deliberate.
|
||||||
|
# shellcheck disable=SC2206
|
||||||
arr=($raw_evts)
|
arr=($raw_evts)
|
||||||
IFS="$OLD_IFS"
|
IFS="$OLD_IFS"
|
||||||
|
|
||||||
for s in ${arr[@]}
|
for s in "${arr[@]}"
|
||||||
do
|
do
|
||||||
if [[ "$s" == *cpu/* ]]; then
|
if [[ "$s" == *cpu/* ]]; then
|
||||||
tmp=${s#*cpu/}
|
tmp=${s#*cpu/}
|
||||||
@ -200,11 +205,13 @@ __perf_main ()
|
|||||||
fi
|
fi
|
||||||
elif [[ $prev == @("--pfm-events") &&
|
elif [[ $prev == @("--pfm-events") &&
|
||||||
$prev_skip_opts == @(record|stat|top) ]]; then
|
$prev_skip_opts == @(record|stat|top) ]]; then
|
||||||
local evts=$($cmd list --raw-dump pfm)
|
local evts
|
||||||
|
evts=$($cmd list --raw-dump pfm)
|
||||||
__perfcomp "$evts" "$cur"
|
__perfcomp "$evts" "$cur"
|
||||||
elif [[ $prev == @("-M"|"--metrics") &&
|
elif [[ $prev == @("-M"|"--metrics") &&
|
||||||
$prev_skip_opts == @(stat) ]]; then
|
$prev_skip_opts == @(stat) ]]; then
|
||||||
local metrics=$($cmd list --raw-dump metric metricgroup)
|
local metrics
|
||||||
|
metrics=$($cmd list --raw-dump metric metricgroup)
|
||||||
__perfcomp "$metrics" "$cur"
|
__perfcomp "$metrics" "$cur"
|
||||||
else
|
else
|
||||||
# List subcommands for perf commands
|
# List subcommands for perf commands
|
||||||
@ -278,6 +285,8 @@ if [[ -n ${ZSH_VERSION-} ]]; then
|
|||||||
let cword=CURRENT-1
|
let cword=CURRENT-1
|
||||||
emulate ksh -c __perf_main
|
emulate ksh -c __perf_main
|
||||||
let _ret && _default && _ret=0
|
let _ret && _default && _ret=0
|
||||||
|
# _ret is only assigned 0 or 1, disable inaccurate analysis.
|
||||||
|
# shellcheck disable=SC2152
|
||||||
return _ret
|
return _ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user