This commit is contained in:
VCB Ferreira
2026-08-02 16:49:15 +02:00
parent 27a0a85e2b
commit 1760c39ade
+1 -18
View File
@@ -1,14 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# profile_flamegraph.sh
#
# Runs ./build/nufi_poisson under `perf record`, then converts the # Runs ./build/nufi_poisson under `perf record`, then converts the
# result into a flamegraph. Run this from the project root ("."). # result into a flamegraph. Run this from the project root (".").
# #
# All profiling artifacts are written to ./results/perf/ so they don't # All profiling artifacts are written to ./results/perf/
# collide with the simulation's own output files in ./results/
# (nufi_poisson clears regular files in "results/" at the start of
# main(), see main.cc's clear_results_directory()).
set -euo pipefail set -euo pipefail
@@ -34,12 +29,6 @@ if ! command -v perf >/dev/null 2>&1; then
exit 1 exit 1
fi fi
# perf needs kernel.perf_event_paranoid low enough to record kernel symbols
# and full call graphs. -1 is fully open; most distros default to 1-4.
# This only sets it for the current boot (same effect as writing directly
# to /proc/sys/kernel/perf_event_paranoid) -- it does NOT persist, and does
# NOT touch /etc/sysctl.conf. Override the target with:
# PERF_EVENT_PARANOID=0 ./profile_flamegraph.sh
PARANOID_PATH="/proc/sys/kernel/perf_event_paranoid" PARANOID_PATH="/proc/sys/kernel/perf_event_paranoid"
DESIRED_PARANOID="${PERF_EVENT_PARANOID:--1}" DESIRED_PARANOID="${PERF_EVENT_PARANOID:--1}"
@@ -65,12 +54,6 @@ FLAMEGRAPH_OUT="${OUT_DIR}/flamegraph.svg"
echo "==> Recording with perf (-F ${PERF_FREQ}) ..." echo "==> Recording with perf (-F ${PERF_FREQ}) ..."
echo " (Ctrl+C stops the binary early and still runs the rest of the pipeline)" echo " (Ctrl+C stops the binary early and still runs the rest of the pipeline)"
# perf record catches SIGINT itself, finalizes perf.data, and exits -- but
# bash's default non-interactive behavior is to terminate the *script* the
# moment it sees SIGINT, and `set -e` would abort on perf record's non-zero
# exit status anyway. Temporarily ignore SIGINT at the script level and
# capture the exit code manually so an early Ctrl+C just moves on to
# generating the flamegraph from whatever was captured.
set +e set +e
trap '' SIGINT trap '' SIGINT
perf record -F "${PERF_FREQ}" -g -o "${PERF_DATA}" -- "${BINARY}" perf record -F "${PERF_FREQ}" -g -o "${PERF_DATA}" -- "${BINARY}"