@@ -33,8 +33,8 @@ What is statistical profiling?
3333
3434Statistical profiling builds a picture of program behavior by periodically
3535capturing snapshots of the call stack. Rather than instrumenting every function
36- call and return as deterministic profilers do, the sampling profiler interrupts
37- execution at regular intervals to record what code is currently running.
36+ call and return as deterministic profilers do, the sampling profiler reads the
37+ call stack at regular intervals to record what code is currently running.
3838
3939This approach rests on a simple principle: functions that consume significant
4040CPU time will appear frequently in the collected samples. By gathering thousands
@@ -53,7 +53,9 @@ and inferring your path from those snapshots.
5353
5454This external observation model is what makes sampling profiling practical for
5555production use. The profiled program runs at full speed because there is no
56- instrumentation code running inside it. You can attach to a live server,
56+ instrumentation code running inside it, and the target process is never stopped
57+ or paused during sampling---the profiler reads the call stack directly from the
58+ process's memory while it continues to run. You can attach to a live server,
5759collect data, and detach without the application ever knowing it was observed.
5860The trade-off is that very short-lived functions may be missed if they happen
5961to complete between samples.
@@ -262,6 +264,36 @@ if the profiler cannot keep up. The statistics help verify that profiling is
262264working correctly and that sufficient samples are being collected.
263265
264266
267+ .. _sampling-efficiency :
268+
269+ Sampling efficiency
270+ -------------------
271+
272+ Sampling efficiency metrics help assess the quality of the collected data.
273+ These metrics appear in the profiler's terminal output and in the flame graph
274+ sidebar.
275+
276+ **Sampling efficiency ** is the percentage of sample attempts that succeeded.
277+ Each sample attempt reads the target process's call stack from memory. An
278+ attempt can fail if the process is in an inconsistent state at the moment of
279+ reading, such as during a context switch or while the interpreter is updating
280+ its internal structures. A low efficiency may indicate that the profiler could
281+ not keep up with the requested sampling rate, often due to system load or an
282+ overly aggressive interval setting.
283+
284+ **Missed samples ** is the percentage of expected samples that were not
285+ collected. Based on the configured interval and duration, the profiler expects
286+ to collect a certain number of samples. Some samples may be missed if the
287+ profiler falls behind schedule, for example when the system is under heavy
288+ load. A small percentage of missed samples is normal and does not significantly
289+ affect the statistical accuracy of the profile.
290+
291+ Both metrics are informational. Even with some failed attempts or missed
292+ samples, the profile remains statistically valid as long as enough samples
293+ were collected. The profiler reports the actual number of samples captured,
294+ which you can use to judge whether the data is sufficient for your analysis.
295+
296+
265297Profiling modes
266298===============
267299
@@ -441,7 +473,7 @@ zooms into that portion of the call tree.
441473The flame graph interface includes:
442474
443475- A sidebar showing profile summary, thread statistics, sampling efficiency
444- metrics (error rate, missed samples ), and top hotspot functions
476+ metrics (see :ref: ` sampling-efficiency ` ), and top hotspot functions
445477- Search functionality supporting both function name matching and
446478 ``file.py:42 `` line patterns
447479- Per-thread filtering via dropdown
0 commit comments