Skip to content

Commit 8200ba7

Browse files
committed
Fixes
1 parent 3bfa0ec commit 8200ba7

File tree

13 files changed

+51
-19
lines changed

13 files changed

+51
-19
lines changed

Doc/library/debug.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ intrusive debugging or patching.
1717
pdb.rst
1818
profiling.rst
1919
pstats.rst
20-
profile.rst
2120
timeit.rst
2221
trace.rst
2322
tracemalloc.rst

Doc/library/profiling-sampling.rst

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ What is statistical profiling?
3333

3434
Statistical profiling builds a picture of program behavior by periodically
3535
capturing 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

3939
This approach rests on a simple principle: functions that consume significant
4040
CPU time will appear frequently in the collected samples. By gathering thousands
@@ -53,7 +53,9 @@ and inferring your path from those snapshots.
5353

5454
This external observation model is what makes sampling profiling practical for
5555
production 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,
5759
collect data, and detach without the application ever knowing it was observed.
5860
The trade-off is that very short-lived functions may be missed if they happen
5961
to complete between samples.
@@ -262,6 +264,36 @@ if the profiler cannot keep up. The statistics help verify that profiling is
262264
working 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+
265297
Profiling modes
266298
===============
267299

@@ -441,7 +473,7 @@ zooms into that portion of the call tree.
441473
The 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

Doc/library/superseded.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ currently no modules in this latter category.
2424
:maxdepth: 1
2525

2626
getopt.rst
27+
profile.rst

Doc/whatsnew/2.5.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,12 +1277,12 @@ complete list of changes, or look through the SVN logs for all the details.
12771277
with the new ':keyword:`with`' statement. See section :ref:`contextlibmod`
12781278
for more about this module.
12791279

1280-
* New module: The :mod:`cProfile` module is a C implementation of the existing
1281-
:mod:`profile` module that has much lower overhead. The module's interface is
1282-
the same as :mod:`profile`: you run ``cProfile.run('main()')`` to profile a
1280+
* New module: The :mod:`!cProfile` module is a C implementation of the existing
1281+
:mod:`!profile` module that has much lower overhead. The module's interface is
1282+
the same as :mod:`!profile`: you run ``cProfile.run('main()')`` to profile a
12831283
function, can save profile data to a file, etc. It's not yet known if the
12841284
Hotshot profiler, which is also written in C but doesn't match the
1285-
:mod:`profile` module's interface, will continue to be maintained in future
1285+
:mod:`!profile` module's interface, will continue to be maintained in future
12861286
versions of Python. (Contributed by Armin Rigo.)
12871287

12881288
Also, the :mod:`pstats` module for analyzing the data measured by the profiler

Doc/whatsnew/3.7.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ and by Alexander Mohr and Ilya Kulakov in :issue:`29302`.)
841841
cProfile
842842
--------
843843

844-
The :mod:`cProfile` command line now accepts ``-m module_name`` as an
844+
The :mod:`!cProfile` command line now accepts ``-m module_name`` as an
845845
alternative to script path. (Contributed by Sanyam Khurana in :issue:`21862`.)
846846

847847

Misc/NEWS.d/3.10.0a2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ of treating them as a match.
593593
.. nonce: ONk9Na
594594
.. section: Library
595595
596-
Fix ``--outfile`` for :mod:`cProfile` / :mod:`profile` not writing the
596+
Fix ``--outfile`` for :mod:`!cProfile` / :mod:`!profile` not writing the
597597
output file in the original directory when the program being profiled
598598
changes the working directory. PR by Anthony Sottile.
599599

Misc/NEWS.d/3.10.0a5.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ specified using a relative path and the current directory changed.
426426
.. nonce: Jq6Az-
427427
.. section: Library
428428
429-
Fix CLI of :mod:`cProfile` and :mod:`profile` to catch
429+
Fix CLI of :mod:`!cProfile` and :mod:`!profile` to catch
430430
:exc:`BrokenPipeError`.
431431

432432
..

Misc/NEWS.d/3.12.0b1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ defined by any build system or documented for manual use.
12571257
.. nonce: n_AfcS
12581258
.. section: Library
12591259
1260-
Update :mod:`cProfile` to use PEP 669 API
1260+
Update :mod:`!cProfile` to use PEP 669 API
12611261

12621262
..
12631263

Misc/NEWS.d/3.13.0a1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3476,7 +3476,7 @@ Fix rare concurrency bug in lock acquisition by the logging package.
34763476
.. nonce: ya5jBT
34773477
.. section: Library
34783478
3479-
Added PY_THROW event hook for :mod:`cProfile` for generators
3479+
Added PY_THROW event hook for :mod:`!cProfile` for generators
34803480

34813481
..
34823482

Misc/NEWS.d/3.14.0a1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,7 @@ Fix :func:`unittest.mock.patch` to not read attributes of the target when
26232623
.. nonce: s4HXR0
26242624
.. section: Library
26252625
2626-
Fixed the use-after-free issue in :mod:`cProfile` by disallowing
2626+
Fixed the use-after-free issue in :mod:`!cProfile` by disallowing
26272627
``disable()`` and ``clear()`` in external timers.
26282628

26292629
..

0 commit comments

Comments
 (0)