perfetto: Install and start perfetto-traced.service

This is so that we can have a long-running `traced` that applications
can connect to, even from boot.
This commit is contained in:
Elliot Saba committed 2025-08-08 08:11:34 -07:00
1 parent 07a51266d6
commit 86a976d1bd
2 files changed
+37 -6

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
[Unit]
Description=perfetto traced service
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/tracebox traced --set-socket-permissions=perf:0660:perf:0660
[Install]
WantedBy=multi-user.target
+26 -6
View File
@@ -21,19 +21,39 @@ if [[ -z "$(which tracebox)" ]]; then
sudo pacman -Sy perfetto
fi
# Ensure traced service is running, warn if not
if ! systemctl is-active perfetto-traced; then
echo "WARN: perfetto-traced service was not running, attempting to auto-install:" >&2
sudo ln -sv ${SCRIPT_DIR}/perfetto-traced.service /etc/systemd/system/perfetto-traced.service
sudo systemctl enable --now perfetto-traced
echo "NOTE: Workloads that were already started may not connect to perfetto correctly, you may need to restart them." >&2
echo " The perfetto-traced service will automatically start upon boot, so this will persist through a reboot." >&2
fi
# Automatically timestamp the trace name
TRACE_PATH="/tmp/perfetto-${CONFIG}-$(date '+%s').pftrace"
CLEANUP_PIDS=()
function cleanup()
{
for PID in "${CLEANUP_PIDS[@]}"; do
kill "${PID}"
done
}
trap "cleanup" EXIT
# Start pps-producer so that we get GPU events
sudo pps-producer &
PPS_PRODUCER_PID="$!"
trap "kill -9 ${PPS_PRODUCER_PID}" EXIT
CLEANUP_PIDS+=( "$!" )
# Start tracebox in --system-sockets mode so pps-producer can connect
sudo tracebox --system-sockets --txt -c "${SCRIPT_DIR}/configs/${CONFIG}" -o "${TRACE_PATH}"
du -sh "${TRACE_PATH}"
# Start traced_probes so we get all our system-level events (CPU scheduling, memory, etc....)
sudo tracebox traced_probes &
CLEANUP_PIDS+=( "$!" )
sudo tracebox perfetto --txt -c "${SCRIPT_DIR}/configs/${CONFIG}" -o "${TRACE_PATH}"
sudo chown "$(id -u):$(id -g)" "${TRACE_PATH}"
du -sh "${TRACE_PATH}"
# Cleanup
kill -9 "${PPS_PRODUCER_PID}"
trap "-" EXIT
cleanup