From b5ab357a312cbac0a804c94af8510bcade21c2a8 Mon Sep 17 00:00:00 2001 From: dodoazzurro Date: Sat, 20 Jun 2026 10:21:52 +0000 Subject: [PATCH] feat(demo): open tmux log pane automatically When running inside a tmux session, demo scripts now split a pane on the right and tail the relevant log source for the active tracing mode: - kernel mode: /sys/kernel/debug/tracing/trace_pipe - userspace mode: ~/.bpftime/runtime.log (ready for future demos) Logic is factored into demo/lib/log-pane.sh so adding new demos is a one-liner. The pane is killed cleanly on exit via teardown_log_pane in each script's cleanup trap. No-op when not inside tmux. --- demo/basic/demo.sh | 5 +++++ demo/debugfile/demo.sh | 5 +++++ demo/lib/log-pane.sh | 30 ++++++++++++++++++++++++++++++ demo/stripped/demo.sh | 5 +++++ 4 files changed, 45 insertions(+) create mode 100644 demo/lib/log-pane.sh diff --git a/demo/basic/demo.sh b/demo/basic/demo.sh index 57e961b1..2c9477fe 100755 --- a/demo/basic/demo.sh +++ b/demo/basic/demo.sh @@ -9,7 +9,11 @@ DEMO_APP="./demo-app" XCOVER="${SCRIPT_DIR}/../../xcover" SLEEP="${SLEEP:-2}" +# shellcheck source=../lib/log-pane.sh +source "${SCRIPT_DIR}/../lib/log-pane.sh" + function cleanup() { + teardown_log_pane ${XCOVER} stop 2>/dev/null || true pkill -f "${XCOVER} run" 2>/dev/null || true rm -f $DEMO_APP @@ -25,6 +29,7 @@ function main() { exit 1 fi + setup_log_pane kernel clear runCmd "# === xcover: Functional Test Coverage Profiler ===" runCmd "# Profile coverage without instrumenting your binaries!" diff --git a/demo/debugfile/demo.sh b/demo/debugfile/demo.sh index fa016d11..79d8461f 100755 --- a/demo/debugfile/demo.sh +++ b/demo/debugfile/demo.sh @@ -12,7 +12,11 @@ DEBUG_FILE="./demo-app.debug" XCOVER="${SCRIPT_DIR}/../../xcover" SLEEP="${SLEEP:-2}" +# shellcheck source=../lib/log-pane.sh +source "${SCRIPT_DIR}/../lib/log-pane.sh" + function cleanup() { + teardown_log_pane ${XCOVER} stop 2>/dev/null || true pkill -f "${XCOVER} run" 2>/dev/null || true rm -f $DEMO_APP $DEBUG_FILE @@ -28,6 +32,7 @@ function main() { exit 1 fi + setup_log_pane kernel clear runCmd "# === xcover: Coverage with a separate debug file ===" runCmd "# Strip the binary for production. Keep the debug file for profiling." diff --git a/demo/lib/log-pane.sh b/demo/lib/log-pane.sh new file mode 100644 index 00000000..87035ca8 --- /dev/null +++ b/demo/lib/log-pane.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# log-pane.sh — tmux log pane helper for xcover demos. +# +# Usage: +# source "$(dirname "${BASH_SOURCE[0]}")/../lib/log-pane.sh" +# +# setup_log_pane kernel # tail /sys/kernel/debug/tracing/trace_pipe +# setup_log_pane userspace # tail ~/.bpftime/runtime.log +# +# Call teardown_log_pane in your cleanup() function. + +LOG_PANE="" + +function setup_log_pane() { + [ -z "${TMUX:-}" ] && return + local mode="${1:-kernel}" + local log_cmd + if [ "$mode" = "userspace" ]; then + log_cmd="tail -f ~/.bpftime/runtime.log" + else + log_cmd="cat /sys/kernel/debug/tracing/trace_pipe" + fi + LOG_PANE=$(tmux split-window -h -P -F "#{pane_id}" "$log_cmd") + tmux select-pane -L +} + +function teardown_log_pane() { + [ -n "${LOG_PANE:-}" ] && tmux kill-pane -t "$LOG_PANE" 2>/dev/null || true + LOG_PANE="" +} diff --git a/demo/stripped/demo.sh b/demo/stripped/demo.sh index e8b01ad5..6ce57efe 100755 --- a/demo/stripped/demo.sh +++ b/demo/stripped/demo.sh @@ -10,7 +10,11 @@ DEMO_APP="./demo-app" XCOVER="${SCRIPT_DIR}/../../xcover" SLEEP="${SLEEP:-2}" +# shellcheck source=../lib/log-pane.sh +source "${SCRIPT_DIR}/../lib/log-pane.sh" + function cleanup() { + teardown_log_pane ${XCOVER} stop 2>/dev/null || true pkill -f "${XCOVER} run" 2>/dev/null || true rm -f $DEMO_APP @@ -26,6 +30,7 @@ function main() { exit 1 fi + setup_log_pane kernel clear runCmd "# === xcover: Coverage on stripped binaries ===" runCmd "# No source instrumentation. No debug info. Just the binary."