Tracing and profiling tools
Quick answer
Tracing records selected events, while profiling summarizes where execution resources are spent. Choose the smallest authorized observation that can test a specific hypothesis.
Instrumentation adds overhead and may expose sensitive arguments or paths. Choose a short observation window and a private test workload, then compare with an uninstrumented baseline. A hot function in a profile is a clue, not automatically a defect.
Prepare the practice environment
Run python3 lab-fixtures/performance/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not change live monitoring or services. All supplied records are fictional; live read-only header checks do not retain measurements. Review the lab guide.
Prerequisites
Review: Network bottlenecks.
How it works
strace records system calls and signals of a process; -c summarizes counts and timing, and -e trace= limits selected calls. It can expose arguments and data and alter timing. perf stat collects aggregate event counts, such as task-clock, where kernel policy and hardware allow. Sampling with perf record is a different technique and may require symbols to interpret stacks. eBPF can instrument selected kernel or user-space events subject to kernel support and permissions; it is not inherently low overhead or unrestricted. Prefer a tiny child process in a disposable VM, not attaching to someone else’s process. Do not loosen ptrace or perf security settings to make examples work. Synthetic trace records are included for interpretation only. ENOENT on a single open call may be an expected search-path miss rather than a failure of the overall program.
Try the examples
The simulated open failed because the named path was missing; inspect subsequent calls before concluding the program failed.
Expected stdout:
openat(AT_FDCWD, "missing.txt", O_RDONLY) = -1 ENOENTOptional authorized VM only. This summarizes the child command, not unrelated processes. Output and timing vary, usually on stderr.
Manual example; not executed locally. Follow its stated environment restrictions.
Optional authorized VM; may be denied by policy. Do not change permission settings. The event measures scheduled task CPU time, not total elapsed wall time.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Do not use a trace as an unbiased timing benchmark. Do not collect secret-bearing arguments or trace unauthorized processes.
Practice
Given a suspected missing configuration file and a suspected CPU-heavy loop, choose one tool for each hypothesis. Explain the effect of tracing overhead and identify a privacy boundary.
Related references
Study: strace, perf. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Tracing and profiling tools — Knowledge Check
Apply performance-analysis concepts to synthetic fixtures and VM-only scenarios.
Which tool is appropriate for a missing-file syscall hypothesis?
What does perf stat primarily report?
What should you do if perf is denied?
Why can tracing alter measurements?