File Index
Files and directories
Sign in
FILE

stat+std_output.sh

File preview with syntax highlighting.

linux-6.19.14/tools/perf/tests/shell/stat+std_output.sh BASH
  1#!/bin/bash
  2# perf stat STD output linter
  3# SPDX-License-Identifier: GPL-2.0
  4# Tests various perf stat STD output commands for
  5# default event and metricgroup
  6
  7set -e
  8
  9# shellcheck source=lib/stat_output.sh
 10. "$(dirname $0)"/lib/stat_output.sh
 11
 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" "cs/sec" "migrations/sec" "faults/sec" "frontend_cycles_idle" "backend_cycles_idle" "GHz" "insn_per_cycle" "/sec" "branch_miss_rate")
 16skip_metric=("tma_" "TopdownL1")
 17
 18cleanup() {
 19  rm -f "${stat_output}"
 20
 21  trap - EXIT TERM INT
 22}
 23
 24trap_cleanup() {
 25  cleanup
 26  exit 1
 27}
 28trap trap_cleanup EXIT TERM INT
 29
 30function commachecker()
 31{
 32	local prefix=1
 33	local -i metric_only=0
 34
 35	case "$1"
 36	in "--interval")	prefix=2
 37	;; "--per-thread")	prefix=2
 38	;; "--system-wide-no-aggr")	prefix=2
 39	;; "--per-core")	prefix=3
 40	;; "--per-socket")	prefix=3
 41	;; "--per-node")	prefix=3
 42	;; "--per-die")		prefix=3
 43	;; "--per-cache")	prefix=3
 44	;; "--per-cluster")	prefix=3
 45	;; "--metric-only")	metric_only=1
 46	esac
 47
 48	while read line
 49	do
 50		# Ignore initial "started on" comment.
 51		x=${line:0:1}
 52		[ "$x" = "#" ] && continue
 53		# Ignore initial blank line.
 54		[ "$line" = "" ] && continue
 55		# Ignore "Performance counter stats"
 56		x=${line:0:25}
 57		[ "$x" = "Performance counter stats" ] && continue
 58		# Ignore "seconds time elapsed" and break
 59		[[ "$line" == *"time elapsed"* ]] && break
 60
 61		main_body=$(echo $line | cut -d' ' -f$prefix-)
 62		x=${main_body%#*}
 63		[ "$x" = "" ] && continue
 64
 65		# Check metric only - if it has a non-empty result
 66		[ $metric_only -eq 1 ] && return 0
 67
 68		# Skip metrics without event name
 69		y=${main_body#*#}
 70		for i in "${!skip_metric[@]}"; do
 71			[[ "$y" == *"${skip_metric[$i]}"* ]] && break
 72		done
 73		[[ "$y" == *"${skip_metric[$i]}"* ]] && continue
 74
 75		# Check default event
 76		for i in "${!event_name[@]}"; do
 77			[[ "$x" == *"${event_name[$i]}"* ]] && break
 78		done
 79
 80		[[ ! "$x" == *"${event_name[$i]}"* ]] && {
 81			echo "Unknown event name in $line" 1>&2
 82			exit 1;
 83		}
 84
 85		# Check event metric if it exists
 86		[[ ! "$main_body" == *"#"* ]] && continue
 87		[[ ! "$main_body" == *"${event_metric[$i]}"* ]] && {
 88			echo "wrong event metric. expected ${event_metric[$i]} in $line" 1>&2
 89			exit 1;
 90		}
 91	done < "${stat_output}"
 92
 93	if [ $metric_only -ne 1 ]
 94	then
 95		echo "Missing metric only output in:"
 96		cat "${stat_output}"
 97	fi
 98	return 0
 99}
100
101perf_cmd="-o ${stat_output}"
102
103skip_test=$(check_for_topology)
104check_no_args "STD" "$perf_cmd"
105check_system_wide "STD" "$perf_cmd"
106check_interval "STD" "$perf_cmd"
107check_per_thread "STD" "$perf_cmd"
108check_per_node "STD" "$perf_cmd"
109check_metric_only "STD" "$perf_cmd"
110if [ $skip_test -ne 1 ]
111then
112	check_system_wide_no_aggr "STD" "$perf_cmd"
113	check_per_core "STD" "$perf_cmd"
114	check_per_cache_instance "STD" "$perf_cmd"
115	check_per_cluster "STD" "$perf_cmd"
116	check_per_die "STD" "$perf_cmd"
117	check_per_socket "STD" "$perf_cmd"
118else
119	echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die and per_socket since socket id exposed via topology is invalid"
120fi
121cleanup
122exit 0
~/ Read-only file preview.