111 lines · bash
1#!/bin/bash2# perf stat STD output linter3# SPDX-License-Identifier: GPL-2.04# Tests various perf stat STD output commands for5# default event and metricgroup6 7set -e8 9# shellcheck source=lib/stat_output.sh10. "$(dirname $0)"/lib/stat_output.sh11 12stat_output=$(mktemp /tmp/__perf_test.stat_output.std.XXXXX)13 14event_name=(cpu-clock task-clock context-switches cpu-migrations page-faults stalled-cycles-frontend stalled-cycles-backend cycles instructions branches branch-misses)15event_metric=("CPUs utilized" "CPUs utilized" "/sec" "/sec" "/sec" "frontend cycles idle" "backend cycles idle" "GHz" "insn per cycle" "/sec" "of all branches")16skip_metric=("stalled cycles per insn" "tma_" "retiring" "frontend_bound" "bad_speculation" "backend_bound")17 18cleanup() {19 rm -f "${stat_output}"20 21 trap - EXIT TERM INT22}23 24trap_cleanup() {25 cleanup26 exit 127}28trap trap_cleanup EXIT TERM INT29 30function commachecker()31{32 local prefix=133 34 case "$1"35 in "--interval") prefix=236 ;; "--per-thread") prefix=237 ;; "--system-wide-no-aggr") prefix=238 ;; "--per-core") prefix=339 ;; "--per-socket") prefix=340 ;; "--per-node") prefix=341 ;; "--per-die") prefix=342 ;; "--per-cache") prefix=343 ;; "--per-cluster") prefix=344 esac45 46 while read line47 do48 # Ignore initial "started on" comment.49 x=${line:0:1}50 [ "$x" = "#" ] && continue51 # Ignore initial blank line.52 [ "$line" = "" ] && continue53 # Ignore "Performance counter stats"54 x=${line:0:25}55 [ "$x" = "Performance counter stats" ] && continue56 # Ignore "seconds time elapsed" and break57 [[ "$line" == *"time elapsed"* ]] && break58 59 main_body=$(echo $line | cut -d' ' -f$prefix-)60 x=${main_body%#*}61 [ "$x" = "" ] && continue62 63 # Skip metrics without event name64 y=${main_body#*#}65 for i in "${!skip_metric[@]}"; do66 [[ "$y" == *"${skip_metric[$i]}"* ]] && break67 done68 [[ "$y" == *"${skip_metric[$i]}"* ]] && continue69 70 # Check default event71 for i in "${!event_name[@]}"; do72 [[ "$x" == *"${event_name[$i]}"* ]] && break73 done74 75 [[ ! "$x" == *"${event_name[$i]}"* ]] && {76 echo "Unknown event name in $line" 1>&277 exit 1;78 }79 80 # Check event metric if it exists81 [[ ! "$main_body" == *"#"* ]] && continue82 [[ ! "$main_body" == *"${event_metric[$i]}"* ]] && {83 echo "wrong event metric. expected ${event_metric[$i]} in $line" 1>&284 exit 1;85 }86 done < "${stat_output}"87 return 088}89 90perf_cmd="-o ${stat_output}"91 92skip_test=$(check_for_topology)93check_no_args "STD" "$perf_cmd"94check_system_wide "STD" "$perf_cmd"95check_interval "STD" "$perf_cmd"96check_per_thread "STD" "$perf_cmd"97check_per_node "STD" "$perf_cmd"98if [ $skip_test -ne 1 ]99then100 check_system_wide_no_aggr "STD" "$perf_cmd"101 check_per_core "STD" "$perf_cmd"102 check_per_cache_instance "STD" "$perf_cmd"103 check_per_cluster "STD" "$perf_cmd"104 check_per_die "STD" "$perf_cmd"105 check_per_socket "STD" "$perf_cmd"106else107 echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die and per_socket since socket id exposed via topology is invalid"108fi109cleanup110exit 0111