What is Probe effect?

The phenomenon in which adding a measurement mechanism changes the behavior of the program being measured.

Field: Performance Analysis

Japanese name: プローブ効果

Why it happens

Measuring a program requires adding some mechanism, such as log output, code that records times or a debugger. The mechanism itself uses CPU time, memory and cache. As a result the timing of the processing changes and the program behaves differently from when it is not measured. This phenomenon is called the probe effect. A probe is an instrument inserted in order to measure. Because observing changes the thing observed, it is also called the observer effect.

Effect on performance measurement

In instrumentation, which inserts recording code at the entry and exit of functions, the shorter the function, the larger the effect. If 40 ns of recording per call is added to a function that really takes 10 ns, the measured time is 50 ns. The function appears to take 5 times its true time. The recording code also displaces cache contents, so surrounding code can slow down as well. Sampling, which records the state at regular intervals, is a method with a comparatively small effect.

Debugging concurrent programs

In programs with several threads, some bugs change the result through slight differences in timing. A data race is the typical example. Adding log output or a debugger changes the order in which the threads run. The bug may then stop appearing or, conversely, appear more readily. A bug that vanishes when one tries to observe it is sometimes called a heisenbug. To reduce the effect, keep the recording light and check whether the result changes with and without measurement.

Try it: questions about Probe effect

A function f that finishes in 20 ns per call is called millions of times. It is measured with an instrumentation profiler that inserts recording code at the entry and exit of functions. If the recording takes 60 ns in total per call and all of that time is counted as time in f, how many times its true time does the measured time of f become?

  1. A3 times
  2. B4 times
  3. CUnchanged (1 time)
Show answer and explanation

Answer: B. 4 times

Each measured call of f takes the true 20 ns plus 60 ns of recording, or 80 ns, and8020=480 ÷ 20 = 4times. This phenomenon, in which the mechanism for measuring changes the very behavior being measured, is called the probe effect. Recording also replaces cache contents, so in practice the slowdown can be even larger. For programs with many small functions, measure the time breakdown with a sampling profiler, or subtract the measurement overhead itself.

FAQ

Can the probe effect be eliminated?

It is hard to eliminate completely as long as the measurement is done in software. Choose a method with a small effect and estimate the cost of the measurement itself by measuring it separately. Mechanisms that do not modify the program, such as hardware performance counters, have a smaller effect.

The bug stopped appearing after I added logging. Is it fixed?

Not necessarily. The logging may have changed the timing so that the condition for the bug has merely become less likely. If the logging is removed without the cause being identified, the bug may return.

Books on Performance Analysis Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary