tools/perf/tests/shell/script_perl.sh

Source file repositories/reference/linux-study-clean/tools/perf/tests/shell/script_perl.sh

File Facts

System
Linux kernel
Corpus path
tools/perf/tests/shell/script_perl.sh
Extension
.sh
Size
2631 bytes
Lines
103
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# perf script perl tests
# SPDX-License-Identifier: GPL-2.0

set -e

# set PERF_EXEC_PATH to find scripts in the source directory
perfdir=$(dirname "$0")/../..
if [ -e "$perfdir/scripts/perl/Perf-Trace-Util" ]; then
  export PERF_EXEC_PATH=$perfdir
fi


perfdata=$(mktemp /tmp/__perf_test_script_perl.perf.data.XXXXX)
generated_script=$(mktemp /tmp/__perf_test_script.XXXXX.pl)

cleanup() {
  rm -f "${perfdata}"
  rm -f "${generated_script}"
  trap - EXIT TERM INT
}

trap_cleanup() {
  echo "Unexpected signal in ${FUNCNAME[1]}"
  cleanup
  exit 1
}
trap trap_cleanup TERM INT
trap cleanup EXIT

check_perl_support() {
	if perf check feature -q libperl; then
		return 0
	fi
	echo "perf script perl test [Skipped: no libperl support]"
	return 2
}

test_script() {
	local event_name=$1
	local expected_output=$2
	local record_opts=$3

	echo "Testing event: $event_name"

	# Try to record. If this fails, it might be permissions or lack of support.
	# We return 2 to indicate "skip this event" rather than "fail test".
	if ! perf record -o "${perfdata}" -e "$event_name" $record_opts -- perf test -w thloop > /dev/null 2>&1; then
		echo "perf script perl test [Skipped: failed to record $event_name]"
		return 2
	fi

	echo "Generating perl script..."
	if ! perf script -i "${perfdata}" -g "${generated_script}"; then
		echo "perf script perl test [Failed: script generation for $event_name]"
		return 1
	fi

	if [ ! -f "${generated_script}" ]; then
		echo "perf script perl test [Failed: script not generated for $event_name]"
		return 1
	fi

	echo "Executing perl script..."
	output=$(perf script -i "${perfdata}" -s "${generated_script}" 2>&1)

	if echo "$output" | grep -q "$expected_output"; then
		echo "perf script perl test [Success: $event_name triggered $expected_output]"
		return 0
	else

Annotation

Implementation Notes