tools/perf/tests/shell/jitdump-python.sh
Source file repositories/reference/linux-study-clean/tools/perf/tests/shell/jitdump-python.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/shell/jitdump-python.sh- Extension
.sh- Size
- 1905 bytes
- Lines
- 82
- 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
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/bin/bash
# python profiling with jitdump
# SPDX-License-Identifier: GPL-2.0
SHELLDIR=$(dirname $0)
# shellcheck source=lib/setup_python.sh
. "${SHELLDIR}"/lib/setup_python.sh
OUTPUT=$(${PYTHON} -Xperf_jit -c 'import os, sys; print(os.getpid(), sys.is_stack_trampoline_active())' 2> /dev/null)
PID=${OUTPUT% *}
HAS_PERF_JIT=${OUTPUT#* }
rm -f /tmp/jit-${PID}.dump 2> /dev/null
if [ "${HAS_PERF_JIT}" != "True" ]; then
echo "SKIP: python JIT dump is not available"
exit 2
fi
PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXXX)
cleanup() {
echo "Cleaning up files..."
rm -f ${PERF_DATA} ${PERF_DATA}.jit /tmp/jit-${PID}.dump /tmp/jitted-${PID}-*.so 2> /dev/null
trap - EXIT TERM INT
}
trap_cleanup() {
echo "Unexpected termination"
cleanup
exit 1
}
trap trap_cleanup EXIT TERM INT
echo "Run python with -Xperf_jit"
cat <<EOF | perf record -k 1 -g --call-graph dwarf -o "${PERF_DATA}" \
-- ${PYTHON} -Xperf_jit
def foo(n):
result = 0
for _ in range(n):
result += 1
return result
def bar(n):
foo(n)
def baz(n):
bar(n)
if __name__ == "__main__":
baz(1000000)
EOF
# extract PID of the target process from the data
_PID=$(perf report -i "${PERF_DATA}" -F pid -q -g none | cut -d: -f1 -s)
PID=$(echo -n $_PID) # remove newlines
echo "Generate JIT-ed DSOs using perf inject"
DEBUGINFOD_URLS='' perf inject -i "${PERF_DATA}" -j -o "${PERF_DATA}.jit"
echo "Add JIT-ed DSOs to the build-ID cache"
for F in /tmp/jitted-${PID}-*.so; do
perf buildid-cache -a "${F}"
done
echo "Check the symbol containing the function/module name"
NUM=$(perf report -i "${PERF_DATA}.jit" -s sym | grep -cE 'py::(foo|bar|baz):<stdin>')
echo "Found ${NUM} matching lines"
Annotation
- 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.