@@ -28,7 +28,7 @@ The Python standard library provides three different profiling implementations:
28
28
29
29
**Statistical Profiler: **
30
30
31
- 1. :mod: `profile.sample ` provides statistical profiling of running Python processes
31
+ 1. :mod: `!profiling.sampling ` provides statistical profiling of running Python processes
32
32
using periodic stack sampling. It can attach to any running Python process without
33
33
requiring code modification or restart, making it ideal for production debugging.
34
34
@@ -55,26 +55,26 @@ The Python standard library provides three different profiling implementations:
55
55
56
56
**Profiler Comparison: **
57
57
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
+ +-------------------+-------------------------- +----------------------+----------------------+
74
74
75
75
.. note ::
76
76
77
- The statistical profiler (:mod: `profile.sample `) is recommended for most production
77
+ The statistical profiler (:mod: `!profiling.sampling `) is recommended for most production
78
78
use cases due to its extremely low overhead and ability to profile running processes
79
79
without modification. It can attach to any Python process and collect performance
80
80
data with minimal impact on execution speed, making it ideal for debugging
@@ -138,11 +138,11 @@ on an existing application.
138
138
139
139
To profile an existing running process::
140
140
141
- python -m profile.sample 1234
141
+ python -m profiling.sampling 1234
142
142
143
143
To profile with custom settings::
144
144
145
- python -m profile.sample -i 50 -d 30 1234
145
+ python -m profiling.sampling -i 50 -d 30 1234
146
146
147
147
**Deterministic Profiling (Development/Testing): **
148
148
@@ -218,34 +218,34 @@ them in various ways.
218
218
Statistical Profiler Command Line Interface
219
219
===========================================
220
220
221
- .. program :: profile.sample
221
+ .. program :: profiling.sampling
222
222
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::
224
224
225
- python -m profile.sample [options] PID
225
+ python -m profiling.sampling [options] PID
226
226
227
227
**Basic Usage Examples: **
228
228
229
229
Profile process 1234 for 10 seconds with default settings::
230
230
231
- python -m profile.sample 1234
231
+ python -m profiling.sampling 1234
232
232
233
233
Profile with custom interval and duration, save to file::
234
234
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
236
236
237
237
Generate collapsed stacks to use with tools like `flamegraph.pl
238
238
<https://github.com/brendangregg/FlameGraph> `_::
239
239
240
- python -m profile.sample --collapsed 1234
240
+ python -m profiling.sampling --collapsed 1234
241
241
242
242
Profile all threads, sort by total time::
243
243
244
- python -m profile.sample -a --sort-tottime 1234
244
+ python -m profiling.sampling -a --sort-tottime 1234
245
245
246
246
Profile with real-time sampling statistics::
247
247
248
- python -m profile.sample --realtime-stats 1234
248
+ python -m profiling.sampling --realtime-stats 1234
249
249
250
250
**Command Line Options: **
251
251
@@ -339,13 +339,13 @@ The statistical profiler produces output similar to deterministic profilers but
339
339
340
340
.. _profile-cli :
341
341
342
- :mod: `profile.sample ` Module Reference
342
+ :mod: `!profiling.sampling ` Module Reference
343
343
=======================================================
344
344
345
- .. module :: profile.sample
345
+ .. module :: profiling.sampling
346
346
:synopsis: Python statistical profiler.
347
347
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.
349
349
For command-line usage, see :ref: `sampling-profiler-cli `. For conceptual information
350
350
about statistical profiling, see :ref: `statistical-profiling `
351
351
@@ -373,14 +373,14 @@ about statistical profiling, see :ref:`statistical-profiling`
373
373
Examples::
374
374
375
375
# 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)
378
378
379
379
# 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)
381
381
382
382
# 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')
384
384
385
385
.. class :: SampleProfiler(pid, sample_interval_usec, all_threads)
386
386
@@ -856,7 +856,7 @@ What Is Deterministic Profiling?
856
856
call *, *function return *, and *exception * events are monitored, and precise
857
857
timings are made for the intervals between these events (during which time the
858
858
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
860
860
deduces where time is being spent. The latter technique traditionally involves
861
861
less overhead (as the code does not need to be instrumented), but provides only
862
862
relative indications of where time is being spent.
0 commit comments