tools/perf/tests/shell/script_python.sh
Source file repositories/reference/linux-study-clean/tools/perf/tests/shell/script_python.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/shell/script_python.sh- Extension
.sh- Size
- 2916 bytes
- Lines
- 114
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function check_python_support
Annotated Snippet
#!/bin/bash
# perf script python 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/python/Perf-Trace-Util" ]; then
export PERF_EXEC_PATH=$perfdir
fi
perfdata=$(mktemp /tmp/__perf_test_script_python.perf.data.XXXXX)
generated_script=$(mktemp /tmp/__perf_test_script.XXXXX.py)
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_python_support() {
if perf check feature -q libpython; then
return 0
fi
echo "perf script python test [Skipped: no libpython 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. 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 python test [Skipped: failed to record $event_name]"
return 2
fi
echo "Generating python script..."
if ! perf script -i "${perfdata}" -g "${generated_script}"; then
echo "perf script python test [Failed: script generation for $event_name]"
return 1
fi
if [ ! -f "${generated_script}" ]; then
echo "perf script python test [Failed: script not generated for $event_name]"
return 1
fi
# Perf script -g python doesn't generate process_event for generic
# events so append it manually to test that the callback works.
if ! grep -q "def process_event" "${generated_script}"; then
cat <<EOF >> "${generated_script}"
def process_event(param_dict):
Annotation
- Detected declarations: `function check_python_support`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.