33.. _profiling-sampling :
44
55***************************************************
6- :mod: `profiling.sampling ` --- Statistical Profiler
6+ :mod: `profiling.sampling ` --- Statistical profiler
77***************************************************
88
99.. module :: profiling.sampling
@@ -28,7 +28,7 @@ process, overhead is virtually zero, making this profiler suitable for both
2828development and production environments.
2929
3030
31- What Is Statistical Profiling ?
31+ What is statistical profiling ?
3232==============================
3333
3434Statistical profiling builds a picture of program behavior by periodically
@@ -64,7 +64,7 @@ deterministic profiling overhead would be unacceptable. For exact call counts
6464and complete call graphs, use :mod: `profiling.tracing ` instead.
6565
6666
67- Quick Examples
67+ Quick examples
6868==============
6969
7070Profile a script and see the results immediately::
@@ -103,7 +103,7 @@ The profiler operates through two subcommands that determine how to obtain
103103the target process.
104104
105105
106- The ``run `` Command
106+ The ``run `` command
107107-------------------
108108
109109The ``run `` command launches a Python script or module and profiles it from
@@ -121,7 +121,7 @@ profiled program::
121121 python -m profiling.sampling run script.py --config settings.yaml
122122
123123
124- The ``attach `` Command
124+ The ``attach `` command
125125----------------------
126126
127127The ``attach `` command connects to an already-running Python process by its
@@ -138,7 +138,7 @@ On most systems, attaching to another process requires appropriate permissions.
138138On Linux, you may need to run as root or adjust the ``ptrace_scope `` setting.
139139
140140
141- Sampling Configuration
141+ Sampling configuration
142142======================
143143
144144Before exploring the various output formats and visualization options, it is
@@ -171,7 +171,7 @@ The default configuration works well for most use cases:
171171 - No live statistics display during profiling
172172
173173
174- Sampling Interval and Duration
174+ Sampling interval and duration
175175------------------------------
176176
177177The two most fundamental parameters are the sampling interval and duration.
@@ -200,7 +200,7 @@ a program that runs for a fixed time, you may want to set the duration to
200200match or exceed the expected runtime.
201201
202202
203- Thread Selection
203+ Thread selection
204204----------------
205205
206206Python programs often use multiple threads, whether explicitly through the
@@ -219,7 +219,7 @@ This option is particularly useful when investigating concurrency issues or
219219when work is distributed across a thread pool.
220220
221221
222- Special Frames
222+ Special frames
223223--------------
224224
225225The profiler can inject artificial frames into the captured stacks to provide
@@ -249,7 +249,7 @@ see substantial time in ``<GC>`` frames, consider investigating object
249249allocation rates or using object pooling.
250250
251251
252- Real-Time Statistics
252+ Real-time statistics
253253--------------------
254254
255255The ``--realtime-stats `` option displays sampling rate statistics during
@@ -262,15 +262,15 @@ if the profiler cannot keep up. The statistics help verify that profiling is
262262working correctly and that sufficient samples are being collected.
263263
264264
265- Profiling Modes
265+ Profiling modes
266266===============
267267
268268The sampling profiler supports three modes that control which samples are
269269recorded. The mode determines what the profile measures: total elapsed time,
270270CPU execution time, or time spent holding the Global Interpreter Lock.
271271
272272
273- Wall-Clock Mode
273+ Wall-clock mode
274274---------------
275275
276276Wall-clock mode (``--mode=wall ``) captures all samples regardless of what the
@@ -290,7 +290,7 @@ function. This is often exactly what you want when optimizing end-to-end
290290latency.
291291
292292
293- CPU Mode
293+ CPU mode
294294--------
295295
296296CPU mode (``--mode=cpu ``) records samples only when the thread is actually
@@ -308,7 +308,7 @@ and network calls, CPU mode reveals which computational sections are most
308308expensive.
309309
310310
311- GIL Mode
311+ GIL mode
312312--------
313313
314314GIL mode (``--mode=gil ``) records samples only when the thread holds Python's
@@ -327,15 +327,15 @@ single-threaded programs or for code that releases the GIL (such as many
327327NumPy operations or I/O calls).
328328
329329
330- Output Formats
330+ Output formats
331331==============
332332
333333The profiler produces output in several formats, each suited to different
334334analysis workflows. The format is selected with a command-line flag, and
335335output goes to stdout, a file, or a directory depending on the format.
336336
337337
338- pstats Format
338+ pstats format
339339-------------
340340
341341The pstats format (``--pstats ``) produces a text table similar to what
@@ -390,7 +390,7 @@ The ``--no-summary`` option suppresses the header summary that precedes the
390390statistics table.
391391
392392
393- Collapsed Stacks Format
393+ Collapsed stacks format
394394-----------------------
395395
396396Collapsed stacks format (``--collapsed ``) produces one line per unique call
@@ -418,7 +418,7 @@ The resulting SVG can be viewed in any web browser and provides an interactive
418418visualization where you can click to zoom into specific call paths.
419419
420420
421- Flame Graph Format
421+ Flame graph format
422422------------------
423423
424424Flame graph format (``--flamegraph ``) produces a self-contained HTML file with
@@ -452,7 +452,7 @@ at the top indicate functions that consume significant time either directly
452452or through their callees.
453453
454454
455- Gecko Format
455+ Gecko format
456456------------
457457
458458Gecko format (``--gecko ``) produces JSON output compatible with the Firefox
@@ -486,7 +486,7 @@ For this reason, the ``--mode`` option is not available with Gecko format;
486486all relevant data is captured automatically.
487487
488488
489- Heatmap Format
489+ Heatmap format
490490--------------
491491
492492Heatmap format (``--heatmap ``) generates an interactive HTML visualization
@@ -527,7 +527,7 @@ intuitive view that shows exactly where time is spent without requiring
527527interpretation of hierarchical visualizations.
528528
529529
530- Live Mode
530+ Live mode
531531=========
532532
533533Live mode (``--live ``) provides a terminal-based real-time view of profiling
@@ -584,7 +584,7 @@ Live mode is incompatible with output format options (``--collapsed``,
584584interface rather than producing file output.
585585
586586
587- Async-Aware Profiling
587+ Async-aware profiling
588588=====================
589589
590590For programs using :mod: `asyncio `, the profiler offers async-aware mode
@@ -623,7 +623,7 @@ Command Line Reference
623623The complete command-line interface for reference.
624624
625625
626- Global Options
626+ Global options
627627--------------
628628
629629.. option :: run
@@ -635,7 +635,7 @@ Global Options
635635 Attach to and profile a running process by PID.
636636
637637
638- Sampling Options
638+ Sampling options
639639----------------
640640
641641.. option :: -i <microseconds >, --interval <microseconds >
@@ -667,7 +667,7 @@ Sampling Options
667667 Enable async-aware profiling for asyncio programs.
668668
669669
670- Mode Options
670+ Mode options
671671------------
672672
673673.. option :: --mode <mode >
@@ -681,7 +681,7 @@ Mode Options
681681 Requires ``--async-aware ``.
682682
683683
684- Output Options
684+ Output options
685685--------------
686686
687687.. option :: --pstats
@@ -712,7 +712,7 @@ Output Options
712712 named ``heatmap_PID ``.
713713
714714
715- pstats Display Options
715+ pstats display options
716716----------------------
717717
718718These options apply only to pstats format output.
@@ -731,7 +731,7 @@ These options apply only to pstats format output.
731731 Omit the Legend and Summary of Interesting Functions sections from output.
732732
733733
734- Run Command Options
734+ Run command options
735735-------------------
736736
737737.. option :: -m , --module
0 commit comments