Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Linux Admins Difficulty: Advanced ClaudeChatGPT

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

More Linux Admins prompts & error guides

Browse every Linux Admins prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.