Measure the system and the cost of observing it
Build bounded tracing experiments, align measurement windows, account for missing events, and quantify instrumentation cost.
On this page
The question for today
What you’ll understand
- Turn a performance question into a bounded, filtered trace experiment.
- Interpret clocks, missing events, and mismatched aggregation windows before claiming causality.
- Estimate instrumentation overhead and distinguish a sampled absence from proof that an event never happened.
A trace is an observation produced by code running on the system being observed. Recording every function can make a delay easier to see while also creating a different delay. Good tracing therefore couples a precise hypothesis with a measurement plan and an explicit uncertainty budget. We will choose event boundaries, account for buffer loss and clock domains, and calculate whether the instrumentation cost is small enough to support the conclusion we want to draw.
Start with a question and a bounded observation plan
Suppose a worker reports a long request latency. “Trace everything” is not yet a hypothesis. Ask instead whether the worker spent the interval runnable but off CPU, blocked waiting for a resource, or running expensive kernel work. Each possibility needs different evidence and boundaries. A scheduler wakeup and later scheduling-in event can help examine runnable delay; a request marker ties that interval to the application’s own operation. Choose the relevant task identity, CPUs, event classes, and time window before collecting. Record the kernel configuration and enabled tracer because event availability and field meanings are interfaces to inspect, not assumptions to import from a different machine.
Tracepoints provide named event records; function tracing follows selected function execution, and sampling observes selected moments or counted events. These methods answer different questions. A sample-heavy function may consume much CPU time without being the cause of one rare stalled request. Conversely, an event sequence can establish that a wakeup preceded execution while saying little about work outside the captured interval. Apply filters and bounded capture duration so evidence remains interpretable and cost stays proportional to the question. Check that filters actually installed as intended, especially when setting subsystem-wide filters whose fields may not exist on every event. Retain collection settings alongside the trace so another person can reproduce the experiment.
Absence, order, and window boundaries need evidence
Kernel tracing commonly writes into finite buffers. A producer can outpace a reader, and an overwrite mode may discard old records. A trace with missing events can resemble a logically impossible lifecycle or hide exactly the burst you wanted to study. Inspect the appropriate overrun and lost-record indicators, buffer mode, and capture boundaries before treating an absent event as proof of absence. Enlarging a buffer can buy time but does not remove sustained overload; reducing enabled events or applying effective filters attacks the production rate. Lost-event metadata and collection interruptions belong in the result, even if the remaining trace looks persuasive.
Clock choice also affects interpretation across CPUs. A fast local trace clock may not provide comparable timestamps across all CPUs on every system. Select a clock suitable for the ordering claim, understand its cost, and avoid subtracting raw timestamps from unrelated domains. Align application markers, trace intervals, and aggregate metrics to the same measurement window. If a throughput counter covers sixty seconds but a trace covers only the final two, their averages cannot be directly combined as if both described the same workload. Warmup, retries, background jobs, and migrated tasks can change the population. Preserve those distinctions rather than smoothing them away with a single average.
Measure the observer and narrow the conclusion
Estimate first-order recording cost as event rate multiplied by average per-event CPU cost. The units cancel into CPU-seconds per wall-second, which can be expressed as a fraction of one CPU. This budget includes only the cost represented by that measurement: stack collection, symbolization, data copying, reader wakeups, storage, and cache effects can contribute elsewhere. Compare equivalent workload runs with tracing off and on, repeat them, and inspect latency as well as throughput. A negligible average CPU increase does not prove that rare interrupt-sensitive paths are unaffected. Conversely, a measured slowdown is not evidence that every individual traced function is intrinsically expensive.
Sampling reduces volume but introduces detection uncertainty. Under a deliberately simplified model where each of n opportunities independently retains a relevant event with constant probability p, the probability of no retained observations is (1−p) raised to n. Real time-based sampling can alias periodic activity, and observations often correlate, so the model is a reasoning aid rather than an automatic confidence certificate. Finish with a conclusion matched to the evidence: the selected worker experienced a measured runnable interval in the captured window, or a sampled run suggests a hotspot worth a targeted follow-up. Preserve the capture settings and missing-event caveats. A small, reproducible experiment usually supports a stronger engineering decision than a massive trace with unexamined collection failure.
Work it through
Budget the recording path
A targeted trace records 50,000 events per second. A controlled benchmark estimates an incremental recording cost of 0.4 microseconds per event. Assume a constant representative average and ignore reader and storage costs for this first estimate. What fraction of one CPU does recording consume?
Convert the per-event cost: 0.4 microseconds is 0.4 × 10⁻⁶ CPU-seconds per event.
Multiply by the event rate: 50,000 events per wall-second × 0.4 × 10⁻⁶ CPU-seconds per event = 0.020 CPU-seconds per wall-second.
Relative to one CPU delivering one CPU-second per wall-second, the estimate is 0.020, or 2%. Separately measure reader, storage, and workload effects before claiming total trace overhead is 2%.
The estimated recording path costs 2% of one CPU. It is a component estimate rather than a complete end-to-end overhead measurement.
The living notebook
Explore the model
Interactive lab · probability
A zero-count trace can still miss real opportunities
Use Success probability p as the hypothetical independent retention probability for a relevant event and Trials n as the number of event opportunities. Predict the zero-retained-events probability before changing n, then inspect the binomial bar at zero. The diagram shows an exact distribution, not newly sampled measurements.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forIndependent retention gives P(K=0)=(1−p)^n. This is not a kernel tracing implementation or an assurance that real sampling is independent; periodic aliasing, correlated losses, and filtering can invalidate that detection model.
Pause & reason
Check your understanding
Your turn
Try it yourself
In the illustrative independent-retention model, five relevant event opportunities each have retention probability 0.2. What is the probability of retaining none? Does retaining none prove the workload never generated those events?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Multiply the five independent miss probabilities, each equal to 0.8. Then separate a conditional model probability from a claim about the real system.
Compare with the solution
The zero-retention probability is 0.8⁵ = 0.32768, about 32.8%. Zero records therefore does not prove there were no generated events. Real tracing can additionally violate independence through burst loss, filtering, or periodic sampling aliasing.
Keep the idea
Take it with you
- A useful trace begins with a hypothesis, selected boundaries, and reproducible collection settings.
- Clocks, buffer loss, and aligned windows determine which ordering and rate claims are defensible.
- Quantify observer cost and state sampling assumptions before interpreting missing records or apparent hotspots.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.