@@ -342,6 +342,8 @@ The default configuration works well for most use cases:
342342 - Disabled
343343 * - Default for ``--subprocesses ``
344344 - Disabled
345+ * - Default for ``--blocking ``
346+ - Disabled (non-blocking sampling)
345347
346348
347349Sampling interval and duration
@@ -392,6 +394,50 @@ This option is particularly useful when investigating concurrency issues or
392394when work is distributed across a thread pool.
393395
394396
397+ .. _blocking-mode :
398+
399+ Blocking mode
400+ -------------
401+
402+ By default, Tachyon reads the target process's memory without stopping it.
403+ This non-blocking approach is ideal for most profiling scenarios because it
404+ imposes virtually zero overhead on the target application: the profiled
405+ program runs at full speed and is unaware it is being observed.
406+
407+ However, non-blocking sampling can occasionally produce incomplete or
408+ inconsistent stack traces in applications with many generators or coroutines
409+ that rapidly switch between yield points, or in programs with very fast-changing
410+ call stacks where functions enter and exit between the start and end of a single
411+ stack read, resulting in reconstructed stacks that mix frames from different
412+ execution states or that never actually existed.
413+
414+ For these cases, the :option: `--blocking ` option stops the target process during
415+ each sample::
416+
417+ python -m profiling.sampling run --blocking script.py
418+ python -m profiling.sampling attach --blocking 12345
419+
420+ When blocking mode is enabled, the profiler suspends the target process,
421+ reads its stack, then resumes it. This guarantees that each captured stack
422+ represents a real, consistent snapshot of what the process was doing at that
423+ instant. The trade-off is that the target process runs slower because it is
424+ repeatedly paused.
425+
426+ .. warning ::
427+
428+ Do not use very high sample rates (low ``--interval `` values) with blocking
429+ mode. Suspending and resuming a process takes time, and if the sampling
430+ interval is too short, the target will spend more time stopped than running.
431+ For blocking mode, intervals of 1000 microseconds (1 millisecond) or higher
432+ are recommended. The default 100 microsecond interval may cause noticeable
433+ slowdown in the target application.
434+
435+ Use blocking mode only when you observe inconsistent stacks in your profiles,
436+ particularly with generator-heavy or coroutine-heavy code. For most
437+ applications, the default non-blocking mode provides accurate results with
438+ zero impact on the target process.
439+
440+
395441Special frames
396442--------------
397443
@@ -1383,6 +1429,13 @@ Sampling options
13831429 Also profile subprocesses. Each subprocess gets its own profiler
13841430 instance and output file. Incompatible with ``--live ``.
13851431
1432+ .. option :: --blocking
1433+
1434+ Pause the target process during each sample. This ensures consistent
1435+ stack traces at the cost of slowing down the target. Use with longer
1436+ intervals (1000 µs or higher) to minimize impact. See :ref: `blocking-mode `
1437+ for details.
1438+
13861439
13871440Mode options
13881441------------
0 commit comments