tools/perf/tests/shell/kvm.sh

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

File Facts

System
Linux kernel
Corpus path
tools/perf/tests/shell/kvm.sh
Extension
.sh
Size
4492 bytes
Lines
183
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 kvm tests
# SPDX-License-Identifier: GPL-2.0

set -e

err=0
perfdata=$(mktemp /tmp/__perf_kvm_test.perf.data.XXXXX)
qemu_pid_file=$(mktemp /tmp/__perf_kvm_test.qemu.pid.XXXXX)
log_file=$(mktemp /tmp/__perf_kvm_test.live_log.XXXXX)

cleanup() {
	rm -f "${perfdata}" "${log_file}"
	if [ -f "${qemu_pid_file}" ]; then
		if [ -s "${qemu_pid_file}" ]; then
			qemu_pid=$(cat "${qemu_pid_file}")
			if [ -n "${qemu_pid}" ]; then
				kill "${qemu_pid}" 2>/dev/null || true
			fi
		fi
		rm -f "${qemu_pid_file}"
	fi
	trap - EXIT TERM INT
}

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

skip() {
	echo "Skip: $1"
	cleanup
	exit 2
}

test_kvm_stat() {
	echo "Testing perf kvm stat"

	echo "Recording kvm events for pid ${qemu_pid}..."
	if ! perf kvm stat record -p "${qemu_pid}" -o "${perfdata}" sleep 1; then
		echo "Failed to record kvm events"
		err=1
		return
	fi

	echo "Reporting kvm events..."
	if ! perf kvm -i "${perfdata}" stat report 2>&1 | grep -q "VM-EXIT"; then
		echo "Failed to find VM-EXIT in report"
		perf kvm -i "${perfdata}" stat report 2>&1
		err=1
		return
	fi

	echo "perf kvm stat test [Success]"
}

test_kvm_record_report() {
	echo "Testing perf kvm record/report"

	echo "Recording kvm profile for pid ${qemu_pid}..."
	# Use --host to avoid needing guest symbols/mounts for this simple test
	# We just want to verify the command runs and produces data
	# We run in background and kill it because 'perf kvm record' appends options
	# after the command, which breaks 'sleep' (e.g. it gets '-e cycles').
	perf kvm --host record -p "${qemu_pid}" -o "${perfdata}" &
	rec_pid=$!
	sleep 1

Annotation

Implementation Notes