Skip to content

Commit dfc0d31

Browse files
committed
More fixes from review
1 parent 0ccea49 commit dfc0d31

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

Doc/library/profiling.sampling.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,13 +1103,15 @@ workflow that separates data capture from analysis. Rather than generating
11031103
visualizations during profiling, you capture raw data to a compact binary file
11041104
and convert it to different formats later.
11051105

1106-
This approach has three main benefits. First, sampling runs faster because the
1107-
work of building data structures for visualization is deferred until replay.
1108-
Second, a single binary capture can be converted to multiple output formats
1109-
without re-profiling---pstats for a quick overview, flame graph for visual
1110-
exploration, heatmap for line-level detail. Third, binary files are compact
1111-
and easy to share with colleagues who can convert them to their preferred
1112-
format.
1106+
This approach has three main benefits:
1107+
1108+
- Sampling runs faster because the work of building data structures for
1109+
visualization is deferred until replay.
1110+
- A single binary capture can be converted to multiple output formats
1111+
without re-profiling: pstats for a quick overview, flame graph for visual
1112+
exploration, heatmap for line-level detail.
1113+
- Binary files are compact and easy to share with colleagues who can convert
1114+
them to their preferred format.
11131115

11141116
A typical workflow::
11151117

@@ -1433,9 +1435,9 @@ Output options
14331435
.. option:: -o <path>, --output <path>
14341436

14351437
Output file or directory path. Default behavior varies by format:
1436-
``--pstats`` writes to stdout, ``--flamegraph``, ``--gecko``, and
1437-
``--binary`` generate files like ``flamegraph.PID.html``, and ``--heatmap``
1438-
creates a directory named ``heatmap_PID``.
1438+
:option:`--pstats` writes to stdout, while other formats generate a file
1439+
named ``<format>_<PID>.<ext>`` (for example, ``flamegraph_12345.html``).
1440+
:option:`--heatmap` creates a directory named ``heatmap_<PID>``.
14391441

14401442

14411443
pstats display options

Modules/_remote_debugging/binary_io_reader.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,18 +799,19 @@ emit_batch(RemoteDebuggingState *state, PyObject *collector,
799799
frame_indices, stack_depth, reader, timestamps_list);
800800
}
801801

802-
/* Helper to invoke progress callback, clearing any errors */
803-
static inline void
802+
/* Helper to invoke progress callback, returns -1 on error */
803+
static inline int
804804
invoke_progress_callback(PyObject *callback, Py_ssize_t current, uint32_t total)
805805
{
806806
if (callback && callback != Py_None) {
807807
PyObject *result = PyObject_CallFunction(callback, "nI", current, total);
808808
if (result) {
809809
Py_DECREF(result);
810810
} else {
811-
PyErr_Clear();
811+
return -1;
812812
}
813813
}
814+
return 0;
814815
}
815816

816817
Py_ssize_t
@@ -838,7 +839,9 @@ binary_reader_replay(BinaryReader *reader, PyObject *collector, PyObject *progre
838839
Py_ssize_t replayed = 0;
839840

840841
/* Initial progress callback at 0% */
841-
invoke_progress_callback(progress_callback, 0, reader->sample_count);
842+
if (invoke_progress_callback(progress_callback, 0, reader->sample_count) < 0) {
843+
return -1;
844+
}
842845

843846
while (offset < reader->sample_data_size) {
844847
/* Read thread_id (8 bytes) + interpreter_id (4 bytes) */
@@ -954,7 +957,9 @@ binary_reader_replay(BinaryReader *reader, PyObject *collector, PyObject *progre
954957

955958
/* Progress callback after batch */
956959
if (replayed % PROGRESS_CALLBACK_INTERVAL < count) {
957-
invoke_progress_callback(progress_callback, replayed, reader->sample_count);
960+
if (invoke_progress_callback(progress_callback, replayed, reader->sample_count) < 0) {
961+
return -1;
962+
}
958963
}
959964
break;
960965
}
@@ -1026,12 +1031,16 @@ binary_reader_replay(BinaryReader *reader, PyObject *collector, PyObject *progre
10261031

10271032
/* Progress callback */
10281033
if (replayed % PROGRESS_CALLBACK_INTERVAL == 0) {
1029-
invoke_progress_callback(progress_callback, replayed, reader->sample_count);
1034+
if (invoke_progress_callback(progress_callback, replayed, reader->sample_count) < 0) {
1035+
return -1;
1036+
}
10301037
}
10311038
}
10321039

10331040
/* Final progress callback at 100% */
1034-
invoke_progress_callback(progress_callback, replayed, reader->sample_count);
1041+
if (invoke_progress_callback(progress_callback, replayed, reader->sample_count) < 0) {
1042+
return -1;
1043+
}
10351044

10361045
return replayed;
10371046
}

0 commit comments

Comments
 (0)