Search

A technology, a device or an article

The instruction beside a perf sample is a place to investigate

Events, sample periods, skid and build identity determine what a hot instruction in a perf report actually tells an investigator.

Sparse silver points above fine marks on blue paper
AI-generated conceptual illustration. A metaphor for sampled observations within continuing work.ITNWS · Original ITNWS AI-generated conceptual editorial illustration

A profiler puts a large percentage beside one instruction. The line is short, the number is precise, and the natural interpretation is that the processor spent that percentage of its life doing exactly what the line says. That interpretation gives the sample more authority than it necessarily has. The research question is narrower and more interesting: what event caused an observation to be recorded, where was execution observed, and how did the tool associate that observation with a line of the program? Those questions determine whether the apparent hotspot is an explanation, a lead, or a misleadingly tidy presentation.

Linux exposes the measurement machinery through perf_event_open. It can count events and can request records when sampling conditions occur. These are different uses of an event source. A total count describes accumulated events within a scope. A sample adds information about a selected observation, potentially including instruction position, thread, time, or other requested fields. The presence of a percentage in a later report does not reveal which of those fields were recorded or how records were selected. The experimental design begins before the report is sorted.

The event supplies the question

A cycle event and a cache-related event ask different questions of the same program. Concentration of cycle samples around a function is not interchangeable with concentration of samples triggered by a particular miss event. The second distribution can emphasize locations associated with that event even if another part of the program dominates elapsed time. Calling both displays CPU usage hides the distinction. The event name, its supported hardware meaning, and the scope of counting belong beside an interpretation. A CPU model can also affect which events are available and what their documented encodings mean.

Imagine a teaching example with 1000 recorded samples, 600 attributed to function A. It is correct to say that A received 60% of the recorded observations under that experiment’s attribution rules. It is not automatically correct to say that A used 60% of wall-clock time. If sampling followed a selected event, the distribution concerns that event. If A appears as an ancestor in call chains, an inclusive presentation may give it observations whose interrupted instructions were elsewhere. The calculation is elementary; specifying the population and attribution is the real scientific work. These counts are invented and are not a benchmark result.

The sampling period states how much of the selected event should accumulate before another observation is requested. A period measured in events is not a duration measured in nanoseconds. When event density changes over execution, equal event intervals can correspond to unequal intervals of time. Frequency mode instead targets a sample rate and allows the kernel to adjust the event period. The perf record documentation describes these choices. Confusing period and frequency changes the interpretation of how the observations were distributed, even when the resulting file can be read by the same reporting command.

A diagram can show an event stream with a dense interval and a quiet interval. Selecting every fixed number of events places more observations in the dense interval. That is not evidence of a faulty sampler; it follows from the selected question. A time-oriented observation scheme would represent the interval differently. Neither illustration supplies a measured rate. The contrast makes the design visible: observations inherit a relationship to the event being counted. A graph that omits this relationship can invite a time-based conclusion from a population that was never selected as a simple collection of wall-clock moments.

Hypothetical events and fixed-event-period samples with unequal time gaps.
Hypothetical events and fixed-event-period samples with unequal time gaps. — ITNWS · Original ITNWS educational diagram

The recorded address has a history

An overflow interrupt is not guaranteed to stop a processor exactly at the instruction an observer wants to blame. Execution and interrupt delivery can separate the event from the recorded instruction position, a phenomenon commonly called skid. A neighboring instruction can consequently attract a sample even though assigning the underlying event solely to that instruction would be unjustified. The reporting tool may be faithfully printing the captured address. The problem lies in treating that address as an exact causal location without checking what precision the event source and recording mode can support.

The interface includes precise-event controls, but their existence does not make every event precise on every processor. Requests express levels of precision and interact with hardware support. A configuration can fail when the requested property is unavailable. It would be misleading to replace that failure with an ordinary event and continue reporting the stronger property. Conversely, a supported precise mechanism can improve attribution for the events it actually covers. The methodological point is to preserve the requested and achieved measurement conditions. A feature name is not a transferable guarantee that every record in every profile identifies its causal instruction without uncertainty.

Attribution then continues through the binary. The address needs to be related to the correct executable or library, with the relevant mappings and symbols. Optimization can inline a function, combine operations, remove source statements, or arrange machine instructions in an order that differs from a casual reading of source code. A highlighted source line is therefore an interpretation through debugging information, not a photograph of a high-level statement being executed. Comparing the profile with a different build can add another mismatch. Build identity and the actual generated instructions are substantive parts of the explanation.

Call chains introduce an additional research choice. A record of the interrupted instruction and a reconstruction of the calling context do not contain identical information. The chosen unwinding method has requirements and costs, while incomplete information can limit what the tool reconstructs. An inclusive view asks which calling contexts led to observations; an exclusive view asks about directly attributed locations under its own rules. A parent function with a large inclusive share need not be performing all the costly work inside its own body. Without stating the view, a ranking can be made to tell contradictory stories about the same execution.

Counting many events at once can require multiplexing when hardware cannot schedule them all simultaneously. The interface can report enabled time and running time so a tool can scale a count. The scale factor compensates arithmetically for incomplete running time; it does not prove that the measured intervals represented all phases of the application equally well. If the workload changes while events take turns on hardware, extrapolation requires interpretation. A neat scaled total is not equivalent to having continuously counted every event throughout the entire run. The times and the workload’s phase behavior explain how strong that comparison can be.

There is an asymmetry between correcting a count and recovering information that was never recorded. A tool can display a scaled count using reported timing, but cannot reconstruct the actual missing sequence of sample locations merely from that factor. Likewise, lost records can affect a sample population. If loss occurs preferentially during intense activity, normalizing the remaining observations to 100% does not erase the bias. The report will always be able to distribute its retained population among locations. The research question is whether that retained population supports the inference being made about the original execution.

Observation also has a cost. Interrupt handling, collecting extra fields, call-chain reconstruction, and writing records can change the execution being studied. Requesting more detailed information can be worthwhile, but detail is not free evidence. Comparing a lightly instrumented run with a heavily instrumented one may reveal a different experiment as well as a different application outcome. The relevant question is not whether overhead can be declared zero. It is whether the observation method is suitable for the scale of effect under discussion and whether a reported application time was collected under that same method.

Scope can move the meaning even when the event remains unchanged. Counting a selected thread, following its execution as the scheduler permits, is different from collecting CPU-wide activity on a chosen processor. The latter can include work belonging to other threads according to the selected filters. Kernel and user execution can also be included or excluded through configuration. A function appearing in one report may therefore reflect a different population from a similarly named function in another. Migration matters to this distinction: a thread-oriented observation and a fixed-CPU observation do not become equivalent merely because the thread often used that CPU. The report’s scope should be carried into its sentence about ownership of work. Otherwise a machine-level sample population can quietly become an application-level accusation, with no change to the numbers on the page.

A rare event makes interpretation difficult in a different way. A small number of observations can produce a large percentage change when one or two records move between categories. The arithmetic is still correct for the recorded population. The uncertainty concerns the stability of the result under repeated representative work. Samples may also be correlated through program structure, so treating every record as an independent random draw can be an unjustified statistical shortcut. This article supplies no confidence interval for an invented population. It instead preserves the distinction between a descriptive fraction and an inference about a continuing workload.

When a promising hotspot appears, the next intellectual move is to formulate a mechanism that could explain it. Perhaps a dependency delays useful execution, an access pattern creates additional traffic, or a particular path performs more work than expected. The profile can guide that hypothesis. Generated instructions, appropriate counters, and an application-level outcome can then provide different kinds of corroboration. A location with many samples is an excellent starting point for asking why. It is a weaker foundation for announcing a precise cause before the event semantics and attribution path have been considered.

This changes how a research report reads. Instead of presenting a solitary ranked list as the conclusion, it identifies the event, sampling choice, workload interval, binary, attribution mode, and limitations that affect the claim. The details are not an exhaustive inventory of every possible profiler option. They are the conditions that distinguish the actual observation from a stronger imagined one. A report about cycle-associated locations can be valuable on its own terms. It becomes less valuable when its language silently turns it into a measurement of every source statement’s share of wall-clock delay.

The highlighted instruction can keep its large number. What needs revision is the sentence surrounding it. The number describes a population produced by a defined measurement. The address identifies a recorded or reconstructed location with a defined degree of precision. Together they establish where investigation should become more focused. They do not end the investigation by themselves. A good profile makes the next question sharper: which mechanism could generate these observations under these conditions, and what further evidence would distinguish it from the alternatives that still fit the recorded data?

Sources checked on October 22, 2026. The sample counts and diagram are teaching examples; no application was profiled for this article.

Sources & documentation

  1. perf_event_open(2) ↗
  2. Linux perf record documentation ↗