summaryrefslogtreecommitdiff
path: root/tools/perf/tests/shell/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/shell/lib')
-rw-r--r--tools/perf/tests/shell/lib/coresight.sh134
-rw-r--r--tools/perf/tests/shell/lib/perf_metric_validation.py11
-rw-r--r--tools/perf/tests/shell/lib/perf_record.sh58
-rw-r--r--tools/perf/tests/shell/lib/setup_python.sh13
4 files changed, 78 insertions, 138 deletions
diff --git a/tools/perf/tests/shell/lib/coresight.sh b/tools/perf/tests/shell/lib/coresight.sh
deleted file mode 100644
index 184d62e7e5bd..000000000000
--- a/tools/perf/tests/shell/lib/coresight.sh
+++ /dev/null
@@ -1,134 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-# Carsten Haitzler <carsten.haitzler@arm.com>, 2021
-
-# This is sourced from a driver script so no need for #!/bin... etc. at the
-# top - the assumption below is that it runs as part of sourcing after the
-# test sets up some basic env vars to say what it is.
-
-# This currently works with ETMv4 / ETF not any other packet types at thi
-# point. This will need changes if that changes.
-
-# perf record options for the perf tests to use
-PERFRECMEM="-m ,16M"
-PERFRECOPT="$PERFRECMEM -e cs_etm//u"
-
-TOOLS=$(dirname $0)
-DIR="$TOOLS/$TEST"
-BIN="$DIR/$TEST"
-# If the test tool/binary does not exist and is executable then skip the test
-if ! test -x "$BIN"; then exit 2; fi
-# If CoreSight is not available, skip the test
-perf list pmu | grep -q cs_etm || exit 2
-DATD="."
-# If the data dir env is set then make the data dir use that instead of ./
-if test -n "$PERF_TEST_CORESIGHT_DATADIR"; then
- DATD="$PERF_TEST_CORESIGHT_DATADIR";
-fi
-# If the stat dir env is set then make the data dir use that instead of ./
-STATD="."
-if test -n "$PERF_TEST_CORESIGHT_STATDIR"; then
- STATD="$PERF_TEST_CORESIGHT_STATDIR";
-fi
-
-# Called if the test fails - error code 1
-err() {
- echo "$1"
- exit 1
-}
-
-# Check that some statistics from our perf
-check_val_min() {
- STATF="$4"
- if test "$2" -lt "$3"; then
- echo ", FAILED" >> "$STATF"
- err "Sanity check number of $1 is too low ($2 < $3)"
- fi
-}
-
-perf_dump_aux_verify() {
- # Some basic checking that the AUX chunk contains some sensible data
- # to see that we are recording something and at least a minimum
- # amount of it. We should almost always see Fn packets in just about
- # anything but certainly we will see some trace info and async
- # packets
- DUMP="$DATD/perf-tmp-aux-dump.txt"
- perf report --stdio --dump -i "$1" | \
- grep -o -e I_ATOM_F -e I_ASYNC -e I_TRACE_INFO > "$DUMP"
- # Simply count how many of these packets we find to see that we are
- # producing a reasonable amount of data - exact checks are not sane
- # as this is a lossy process where we may lose some blocks and the
- # compiler may produce different code depending on the compiler and
- # optimization options, so this is rough just to see if we're
- # either missing almost all the data or all of it
- ATOM_FX_NUM=$(grep -c I_ATOM_F "$DUMP")
- ASYNC_NUM=$(grep -c I_ASYNC "$DUMP")
- TRACE_INFO_NUM=$(grep -c I_TRACE_INFO "$DUMP")
- rm -f "$DUMP"
-
- # Arguments provide minimums for a pass
- CHECK_FX_MIN="$2"
- CHECK_ASYNC_MIN="$3"
- CHECK_TRACE_INFO_MIN="$4"
-
- # Write out statistics, so over time you can track results to see if
- # there is a pattern - for example we have less "noisy" results that
- # produce more consistent amounts of data each run, to see if over
- # time any techinques to minimize data loss are having an effect or
- # not
- STATF="$STATD/stats-$TEST-$DATV.csv"
- if ! test -f "$STATF"; then
- echo "ATOM Fx Count, Minimum, ASYNC Count, Minimum, TRACE INFO Count, Minimum" > "$STATF"
- fi
- echo -n "$ATOM_FX_NUM, $CHECK_FX_MIN, $ASYNC_NUM, $CHECK_ASYNC_MIN, $TRACE_INFO_NUM, $CHECK_TRACE_INFO_MIN" >> "$STATF"
-
- # Actually check to see if we passed or failed.
- check_val_min "ATOM_FX" "$ATOM_FX_NUM" "$CHECK_FX_MIN" "$STATF"
- check_val_min "ASYNC" "$ASYNC_NUM" "$CHECK_ASYNC_MIN" "$STATF"
- check_val_min "TRACE_INFO" "$TRACE_INFO_NUM" "$CHECK_TRACE_INFO_MIN" "$STATF"
- echo ", Ok" >> "$STATF"
-}
-
-perf_dump_aux_tid_verify() {
- # Specifically crafted test will produce a list of Tread ID's to
- # stdout that need to be checked to see that they have had trace
- # info collected in AUX blocks in the perf data. This will go
- # through all the TID's that are listed as CID=0xabcdef and see
- # that all the Thread IDs the test tool reports are in the perf
- # data AUX chunks
-
- # The TID test tools will print a TID per stdout line that are being
- # tested
- TIDS=$(cat "$2")
- # Scan the perf report to find the TIDs that are actually CID in hex
- # and build a list of the ones found
- FOUND_TIDS=$(perf report --stdio --dump -i "$1" | \
- grep -o "CID=0x[0-9a-z]\+" | sed 's/CID=//g' | \
- uniq | sort | uniq)
- # No CID=xxx found - maybe your kernel is reporting these as
- # VMID=xxx so look there
- if test -z "$FOUND_TIDS"; then
- FOUND_TIDS=$(perf report --stdio --dump -i "$1" | \
- grep -o "VMID=0x[0-9a-z]\+" | sed 's/VMID=//g' | \
- uniq | sort | uniq)
- fi
-
- # Iterate over the list of TIDs that the test says it has and find
- # them in the TIDs found in the perf report
- MISSING=""
- for TID2 in $TIDS; do
- FOUND=""
- for TIDHEX in $FOUND_TIDS; do
- TID=$(printf "%i" $TIDHEX)
- if test "$TID" -eq "$TID2"; then
- FOUND="y"
- break
- fi
- done
- if test -z "$FOUND"; then
- MISSING="$MISSING $TID"
- fi
- done
- if test -n "$MISSING"; then
- err "Thread IDs $MISSING not found in perf AUX data"
- fi
-}
diff --git a/tools/perf/tests/shell/lib/perf_metric_validation.py b/tools/perf/tests/shell/lib/perf_metric_validation.py
index dea8ef1977bf..3d52f94f22b9 100644
--- a/tools/perf/tests/shell/lib/perf_metric_validation.py
+++ b/tools/perf/tests/shell/lib/perf_metric_validation.py
@@ -383,10 +383,13 @@ class Validator:
wl = workload.split()
command.extend(wl)
print(" ".join(command))
- cmd = subprocess.run(command, stderr=subprocess.PIPE, encoding='utf-8')
- data = [x+'}' for x in cmd.stderr.split('}\n') if x]
- if data[0][0] != '{':
- data[0] = data[0][data[0].find('{'):]
+ cmd = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8')
+ lines = cmd.stderr.splitlines() + cmd.stdout.splitlines()
+ data = []
+ for line in lines:
+ line = line.strip()
+ if line.startswith('{') and line.endswith('}'):
+ data.append(line)
return data
def collect_perf(self, workload: str):
diff --git a/tools/perf/tests/shell/lib/perf_record.sh b/tools/perf/tests/shell/lib/perf_record.sh
new file mode 100644
index 000000000000..2b9e11b66dc7
--- /dev/null
+++ b/tools/perf/tests/shell/lib/perf_record.sh
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: GPL-2.0
+
+PERF_RECORD_LOGS=()
+
+perf_record_with_retry() {
+ local perfdata="$1"
+ local check_cmd="$2"
+ local testprog_base="$3"
+ shift 3
+
+ local logfile
+ logfile=$(mktemp /tmp/__perf_record_retry.XXXXXX)
+ PERF_RECORD_LOGS+=("$logfile")
+
+ # Save the e flag state and disable it
+ local save_e
+ if [[ $- == *e* ]]; then
+ save_e="set -e"
+ else
+ save_e="set +e"
+ fi
+ set +e
+
+ local duration
+ local first_run=true
+ local ret=1
+ local cmd_prefix="perf record"
+ if [ -n "${PERF_RECORD_CMD}" ]; then
+ cmd_prefix="${PERF_RECORD_CMD}"
+ fi
+
+ for duration in 0.01 0.1 0.3 1.0 2.0; do
+ rm -f "${perfdata}".old
+ ${cmd_prefix} "$@" -o "${perfdata}" ${testprog_base} ${duration} > "$logfile" 2>&1
+ local record_exit=$?
+
+ if [ "$first_run" = true ] && [ $record_exit -ne 0 ]; then
+ ret=2
+ break
+ fi
+ first_run=false
+
+ if [ -e "${perfdata}" ] && eval "${check_cmd}"; then
+ ret=0
+ break
+ fi
+ done
+
+ eval "$save_e"
+ return $ret
+}
+
+perf_record_cleanup() {
+ for logfile in "${PERF_RECORD_LOGS[@]}"; do
+ rm -f "$logfile"
+ done
+ PERF_RECORD_LOGS=()
+}
diff --git a/tools/perf/tests/shell/lib/setup_python.sh b/tools/perf/tests/shell/lib/setup_python.sh
index a58e5536f2ed..2173215a0517 100644
--- a/tools/perf/tests/shell/lib/setup_python.sh
+++ b/tools/perf/tests/shell/lib/setup_python.sh
@@ -14,3 +14,16 @@ then
echo Skipping test, python not detected please set environment variable PYTHON.
exit 2
fi
+
+# Set PYTHONPATH to find the in-tree built perf.so first, avoiding system-wide perf.so
+if [ -n "$PERF_EXEC_PATH" ] && [ -d "$PERF_EXEC_PATH/python" ]; then
+ PYTHONPATH_DIR="$PERF_EXEC_PATH/python"
+elif [ -d "$(dirname "$0")/../../python" ]; then
+ PYTHONPATH_DIR="$(dirname "$0")/../../python"
+elif [ -d "$(dirname "$0")/../python" ]; then
+ PYTHONPATH_DIR="$(dirname "$0")/../python"
+fi
+
+if [ -n "$PYTHONPATH_DIR" ]; then
+ export PYTHONPATH="$PYTHONPATH_DIR${PYTHONPATH:+:$PYTHONPATH}"
+fi