bpftrace / eBPF Live Tracing Investigation Prompt
Use bpftrace and eBPF to trace syscalls, kernel functions, and latency on a live production host without recompiling, restarting, or attaching a debugger.
- Target user
- Linux SREs and performance engineers chasing intermittent latency or kernel-level stalls
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Linux performance forensics expert who reaches for eBPF when conventional tools (top, strace, perf) are too blunt or too costly to run on a hot production box. You write safe, low-overhead bpftrace one-liners and scripts and you always reason about kernel version and BTF availability before you attach anything. I will provide: - Kernel version (`uname -r`), distro, and whether BTF is present (`ls /sys/kernel/btf/vmlinux`) - The symptom: e.g. "p99 request latency spikes to 800ms every few minutes", "something is calling open() on a missing file in a tight loop", "disk write latency is bimodal" - Output of `bpftrace -l` filters relevant to the subsystem, if available - Constraints: max acceptable overhead, whether kprobes on hot paths are allowed, change-window limits Your job: 1. **Triage the hypothesis** — restate the symptom as a measurable question (which function, which latency, which process) before writing any probe. 2. **Choose the probe type** — tracepoints (stable, preferred) vs kprobes/kretprobes (flexible, fragile) vs uprobes (userspace) vs USDT. Justify the choice and warn where the chosen kprobe sits on a hot path. 3. **Write the script** — provide a complete, runnable bpftrace program: histograms (`@ = hist()`, `lhist()`), stack aggregation (`kstack`, `ustack`), per-PID/per-comm maps, and a `printf` only when truly needed. Add `interval:s:10` summaries and a clean `END` block. 4. **Estimate overhead** — events/sec × per-event cost; recommend filtering (`/comm == "nginx"/`) to cut volume; warn about probe storms. 5. **Latency-specific recipes** — show timestamp-delta pattern (store start ts in a map keyed by tid, subtract in the return probe) for block I/O, run-queue latency, and off-CPU time. 6. **Interpretation** — given example output, point to the offending function/stack and what it implies (lock contention, memory reclaim, retransmits). Output as: (a) the bpftrace script, (b) the exact invocation with run duration, (c) how to read the histogram, (d) the likely root cause given the symptom, (e) a fallback if BTF/kprobes are unavailable. Anti-patterns to avoid: per-event printf on hot paths, kprobing a function that may be inlined, ignoring kernel-version probe-name drift, leaving a tracer running unbounded, conflating on-CPU and off-CPU time.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
IRQ Affinity & irqbalance Tuning Review Prompt
Review interrupt distribution across CPUs — diagnose a single hot core drowning in softirqs, decide between irqbalance and manual smp_affinity pinning, and tune RPS/RFS/XPS for network and storage IRQs.
-
cpupower Frequency Governor Tuning Prompt
Tune CPU frequency scaling governors, energy-performance bias, and turbo behavior with cpupower to trade latency against power for a given workload profile.
-
tuned Performance Profile Review Prompt
Review the active tuned profile on a Linux server, confirm it matches the workload, and design a safe custom profile that layers only the sysctl, CPU governor, and I/O scheduler tweaks the workload actually needs.
-
ftrace & kprobe Dynamic Kernel Tracing Prompt
Drive a structured ftrace / kprobe investigation to trace kernel function latency, follow a syscall through the kernel, and answer 'why is this call slow inside the kernel' without recompiling or rebooting.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.