Skip to content

Commit e9ffe17

Browse files
AA-Turnerlkollar
authored andcommitted
pythongh-138122: Use profiling.sampling in the documentation (PEP 799) (python#138389)
1 parent 3c4e363 commit e9ffe17

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

Doc/library/profile.rst

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The Python standard library provides three different profiling implementations:
2828

2929
**Statistical Profiler:**
3030

31-
1. :mod:`profile.sample` provides statistical profiling of running Python processes
31+
1. :mod:`!profiling.sampling` provides statistical profiling of running Python processes
3232
using periodic stack sampling. It can attach to any running Python process without
3333
requiring code modification or restart, making it ideal for production debugging.
3434

@@ -55,26 +55,26 @@ The Python standard library provides three different profiling implementations:
5555

5656
**Profiler Comparison:**
5757

58-
+-------------------+----------------------+----------------------+----------------------+
59-
| Feature | Statistical | Deterministic | Deterministic |
60-
| | (``profile.sample``) | (``cProfile``) | (``profile``) |
61-
+===================+======================+======================+======================+
62-
| **Target** | Running process | Code you run | Code you run |
63-
+-------------------+----------------------+----------------------+----------------------+
64-
| **Overhead** | Virtually none | Moderate | High |
65-
+-------------------+----------------------+----------------------+----------------------+
66-
| **Accuracy** | Statistical approx. | Exact call counts | Exact call counts |
67-
+-------------------+----------------------+----------------------+----------------------+
68-
| **Setup** | Attach to any PID | Instrument code | Instrument code |
69-
+-------------------+----------------------+----------------------+----------------------+
70-
| **Use Case** | Production debugging | Development/testing | Profiler extension |
71-
+-------------------+----------------------+----------------------+----------------------+
72-
| **Implementation**| C extension | C extension | Pure Python |
73-
+-------------------+----------------------+----------------------+----------------------+
58+
+-------------------+--------------------------+----------------------+----------------------+
59+
| Feature | Statistical | Deterministic | Deterministic |
60+
| | (``profiling.sampling``) | (``cProfile``) | (``profile``) |
61+
+===================+==========================+======================+======================+
62+
| **Target** | Running process | Code you run | Code you run |
63+
+-------------------+--------------------------+----------------------+----------------------+
64+
| **Overhead** | Virtually none | Moderate | High |
65+
+-------------------+--------------------------+----------------------+----------------------+
66+
| **Accuracy** | Statistical approx. | Exact call counts | Exact call counts |
67+
+-------------------+--------------------------+----------------------+----------------------+
68+
| **Setup** | Attach to any PID | Instrument code | Instrument code |
69+
+-------------------+--------------------------+----------------------+----------------------+
70+
| **Use Case** | Production debugging | Development/testing | Profiler extension |
71+
+-------------------+--------------------------+----------------------+----------------------+
72+
| **Implementation**| C extension | C extension | Pure Python |
73+
+-------------------+--------------------------+----------------------+----------------------+
7474

7575
.. note::
7676

77-
The statistical profiler (:mod:`profile.sample`) is recommended for most production
77+
The statistical profiler (:mod:`!profiling.sampling`) is recommended for most production
7878
use cases due to its extremely low overhead and ability to profile running processes
7979
without modification. It can attach to any Python process and collect performance
8080
data with minimal impact on execution speed, making it ideal for debugging
@@ -138,11 +138,11 @@ on an existing application.
138138

139139
To profile an existing running process::
140140

141-
python -m profile.sample 1234
141+
python -m profiling.sampling 1234
142142

143143
To profile with custom settings::
144144

145-
python -m profile.sample -i 50 -d 30 1234
145+
python -m profiling.sampling -i 50 -d 30 1234
146146

147147
**Deterministic Profiling (Development/Testing):**
148148

@@ -218,34 +218,34 @@ them in various ways.
218218
Statistical Profiler Command Line Interface
219219
===========================================
220220

221-
.. program:: profile.sample
221+
.. program:: profiling.sampling
222222

223-
The :mod:`profile.sample` module can be invoked as a script to profile running processes::
223+
The :mod:`!profiling.sampling` module can be invoked as a script to profile running processes::
224224

225-
python -m profile.sample [options] PID
225+
python -m profiling.sampling [options] PID
226226

227227
**Basic Usage Examples:**
228228

229229
Profile process 1234 for 10 seconds with default settings::
230230

231-
python -m profile.sample 1234
231+
python -m profiling.sampling 1234
232232

233233
Profile with custom interval and duration, save to file::
234234

235-
python -m profile.sample -i 50 -d 30 -o profile.stats 1234
235+
python -m profiling.sampling -i 50 -d 30 -o profile.stats 1234
236236

237237
Generate collapsed stacks to use with tools like `flamegraph.pl
238238
<https://github.com/brendangregg/FlameGraph>`_::
239239

240-
python -m profile.sample --collapsed 1234
240+
python -m profiling.sampling --collapsed 1234
241241

242242
Profile all threads, sort by total time::
243243

244-
python -m profile.sample -a --sort-tottime 1234
244+
python -m profiling.sampling -a --sort-tottime 1234
245245

246246
Profile with real-time sampling statistics::
247247

248-
python -m profile.sample --realtime-stats 1234
248+
python -m profiling.sampling --realtime-stats 1234
249249

250250
**Command Line Options:**
251251

@@ -339,13 +339,13 @@ The statistical profiler produces output similar to deterministic profilers but
339339

340340
.. _profile-cli:
341341

342-
:mod:`profile.sample` Module Reference
342+
:mod:`!profiling.sampling` Module Reference
343343
=======================================================
344344

345-
.. module:: profile.sample
345+
.. module:: profiling.sampling
346346
:synopsis: Python statistical profiler.
347347

348-
This section documents the programmatic interface for the :mod:`profile.sample` module.
348+
This section documents the programmatic interface for the :mod:`!profiling.sampling` module.
349349
For command-line usage, see :ref:`sampling-profiler-cli`. For conceptual information
350350
about statistical profiling, see :ref:`statistical-profiling`
351351

@@ -373,14 +373,14 @@ about statistical profiling, see :ref:`statistical-profiling`
373373
Examples::
374374

375375
# Basic usage - profile process 1234 for 10 seconds
376-
import profile.sample
377-
profile.sample.sample(1234)
376+
import profiling.sampling
377+
profiling.sampling.sample(1234)
378378

379379
# Profile with custom settings
380-
profile.sample.sample(1234, duration_sec=30, sample_interval_usec=50, all_threads=True)
380+
profiling.sampling.sample(1234, duration_sec=30, sample_interval_usec=50, all_threads=True)
381381

382382
# Generate collapsed stack traces for flamegraph.pl
383-
profile.sample.sample(1234, output_format='collapsed', filename='profile.collapsed')
383+
profiling.sampling.sample(1234, output_format='collapsed', filename='profile.collapsed')
384384

385385
.. class:: SampleProfiler(pid, sample_interval_usec, all_threads)
386386

@@ -856,7 +856,7 @@ What Is Deterministic Profiling?
856856
call*, *function return*, and *exception* events are monitored, and precise
857857
timings are made for the intervals between these events (during which time the
858858
user's code is executing). In contrast, :dfn:`statistical profiling` (which is
859-
provided by the :mod:`profile.sample` module) periodically samples the effective instruction pointer, and
859+
provided by the :mod:`!profiling.sampling` module) periodically samples the effective instruction pointer, and
860860
deduces where time is being spent. The latter technique traditionally involves
861861
less overhead (as the code does not need to be instrumented), but provides only
862862
relative indications of where time is being spent.

Doc/whatsnew/3.15.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ New features
7575
High frequency statistical sampling profiler
7676
--------------------------------------------
7777

78-
A new statistical sampling profiler has been added to the :mod:`profile` module as
79-
:mod:`profile.sample`. This profiler enables low-overhead performance analysis of
78+
A new statistical sampling profiler has been added to the new :mod:`!profiling` module as
79+
:mod:`!profiling.sampling`. This profiler enables low-overhead performance analysis of
8080
running Python processes without requiring code modification or process restart.
8181

8282
Unlike deterministic profilers (:mod:`cProfile` and :mod:`profile`) that instrument
@@ -97,19 +97,19 @@ Key features include:
9797

9898
Profile process 1234 for 10 seconds with default settings::
9999

100-
python -m profile.sample 1234
100+
python -m profiling.sampling 1234
101101

102102
Profile with custom interval and duration, save to file::
103103

104-
python -m profile.sample -i 50 -d 30 -o profile.stats 1234
104+
python -m profiling.sampling -i 50 -d 30 -o profile.stats 1234
105105

106106
Generate collapsed stacks for flamegraph::
107107

108-
python -m profile.sample --collapsed 1234
108+
python -m profiling.sampling --collapsed 1234
109109

110110
Profile all threads and sort by total time::
111111

112-
python -m profile.sample -a --sort-tottime 1234
112+
python -m profiling.sampling -a --sort-tottime 1234
113113

114114
The profiler generates statistical estimates of where time is spent::
115115

0 commit comments

Comments
 (0)