| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Expand Up | @@ -27,6 +27,10 @@ def __init__( | |||||||||
| # ─── indexing helpers ─────────────────────────────────────────── | ||||||||||
| def _format_stack_entry(elem: str|FrameInfo) -> str: | ||||||||||
| if not isinstance(elem, str): | ||||||||||
| if elem.location is None: | ||||||||||
|
Comment thread
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityRegular collectors rely on these helpers: cpython/Lib/profiling/sampling/collector.py Lines 46 to 47 in 40f7fbf
cpython/Lib/profiling/sampling/collector.py Lines 29 to 30 in 40f7fbf
Sorry, something went wrong.
All reactions
|
||||||||||
| if elem.filename in ("", "~"): | ||||||||||
| return f"{elem.funcname}" | ||||||||||
| return f"{elem.funcname} {elem.filename}" | ||||||||||
| if elem.location.lineno == 0 and elem.filename == "": | ||||||||||
| return f"{elem.funcname}" | ||||||||||
| else: | ||||||||||
| Expand Down Expand Up | @@ -190,8 +194,7 @@ def build_task_table(result): | |||||||||
| # Build coroutine stack string | ||||||||||
| frames = [frame for coro in task_info.coroutine_stack | ||||||||||
| for frame in coro.call_stack] | ||||||||||
| coro_stack = " -> ".join(_format_stack_entry(x).split(" ")[0] | ||||||||||
|
Comment thread
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis does not work for the <unknown function> sentinel.
Sorry, something went wrong.
All reactions
|
||||||||||
| for x in frames) | ||||||||||
| coro_stack = " -> ".join(x.funcname for x in frames) | ||||||||||
|
|
||||||||||
| # Handle tasks with no awaiters | ||||||||||
| if not task_info.awaited_by: | ||||||||||
| Expand All | @@ -202,8 +205,7 @@ def build_task_table(result): | |||||||||
| # Handle tasks with awaiters | ||||||||||
| for coro_info in task_info.awaited_by: | ||||||||||
| parent_id = coro_info.task_name | ||||||||||
| awaiter_frames = [_format_stack_entry(x).split(" ")[0] | ||||||||||
| for x in coro_info.call_stack] | ||||||||||
| awaiter_frames = [x.funcname for x in coro_info.call_stack] | ||||||||||
| awaiter_chain = " -> ".join(awaiter_frames) | ||||||||||
| awaiter_name = id2name.get(parent_id, "Unknown") | ||||||||||
| parent_id_str = (hex(parent_id) if isinstance(parent_id, int) | ||||||||||
| Expand Down | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -665,6 +665,26 @@ def test_same_line_different_columns(self): | |
| collector, count = self.roundtrip(samples) | ||
| self.assertEqual(count, 3) | ||
|
|
||
| def test_synthetic_frames_roundtrip(self): | ||
| """Degraded/sentinel frames (location=None) survive the binary format.""" | ||
| frames = [ | ||
| FrameInfo(("~", None, name, None)) | ||
| for name in ( | ||
| "<GC>", | ||
| "<native>", | ||
| "<unknown function>", | ||
| "<unknown file>", | ||
| "<unreadable frame>", | ||
|
Comment thread
Comment on lines
+673
to
+677
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityPerhaps we could add something like is_synthetic to FrameInfo?
Sorry, something went wrong.
All reactions
|
||
| ) | ||
| ] | ||
| frames.append(FrameInfo(("app.py", None, "<unknown function>", None))) | ||
| frames.append(FrameInfo(("<unknown file>", None, "real_func", None))) | ||
| samples = [[make_interpreter(0, [make_thread(1, frames)])]] | ||
|
|
||
| collector, count = self.roundtrip(samples) | ||
| self.assertEqual(count, 1) | ||
| self.assert_samples_equal(samples, collector) | ||
|
|
||
|
|
||
| class TestBinaryEdgeCases(BinaryFormatTestBase): | ||
| """Tests for edge cases in binary format.""" | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix the sampling profiler dropping entire samples when a non-fatal read fails; | ||
| frames now keep any readable metadata, and long funcnames and filenames are | ||
| truncated instead. Patch by Maurycy Pawłowski-Wieroński. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -341,11 +341,16 @@ parse_code_object(RemoteUnwinderObject *unwinder, | |
| PyObject **result, | ||
| const CodeObjectContext *ctx) | ||
| { | ||
| _Py_DECLARE_STR(unknown_function, "<unknown function>"); | ||
| _Py_DECLARE_STR(unknown_file, "<unknown file>"); | ||
| _Py_DECLARE_STR(unreadable_frame, "<unreadable frame>"); | ||
|
|
||
| void *key = (void *)ctx->code_addr; | ||
| CachedCodeMetadata *meta = NULL; | ||
| PyObject *func = NULL; | ||
| PyObject *file = NULL; | ||
| PyObject *linetable = NULL; | ||
| int code_metadata_incomplete = 0; | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityPerhaps parse_code_object() should return this information, and we should not store incomplete objects in the frame_cache? Perhaps we should collect degradation stats? Important caveat is that we will likely have more types of degradation.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| #ifdef Py_GIL_DISABLED | ||
| // In free threading builds, code object addresses might have the low bit set | ||
| Expand All | @@ -369,30 +374,50 @@ parse_code_object(RemoteUnwinderObject *unwinder, | |
| if (_Py_RemoteDebug_PagedReadRemoteMemory( | ||
| &unwinder->handle, real_address, SIZEOF_CODE_OBJ, code_object) < 0) | ||
| { | ||
| set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read code object"); | ||
| goto error; | ||
| if (_Py_RemoteDebug_IsFatalReadError()) { | ||
| goto error; | ||
| } | ||
| PyErr_Clear(); | ||
| func = Py_NewRef(&_Py_STR(unreadable_frame)); | ||
| file = Py_NewRef(_Py_LATIN1_CHR('~')); | ||
| goto degraded; | ||
| } | ||
|
|
||
| func = read_py_str(unwinder, | ||
| GET_MEMBER(uintptr_t, code_object, unwinder->debug_offsets.code_object.qualname), 1024); | ||
| if (!func) { | ||
| set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read function name from code object"); | ||
| goto error; | ||
| if (_Py_RemoteDebug_IsFatalReadError()) { | ||
| goto error; | ||
| } | ||
| PyErr_Clear(); | ||
| func = Py_NewRef(&_Py_STR(unknown_function)); | ||
| code_metadata_incomplete = 1; | ||
| } | ||
|
|
||
| file = read_py_str(unwinder, | ||
| GET_MEMBER(uintptr_t, code_object, unwinder->debug_offsets.code_object.filename), 1024); | ||
| if (!file) { | ||
| set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read filename from code object"); | ||
| goto error; | ||
| if (_Py_RemoteDebug_IsFatalReadError()) { | ||
| goto error; | ||
| } | ||
| PyErr_Clear(); | ||
| file = Py_NewRef(&_Py_STR(unknown_file)); | ||
| code_metadata_incomplete = 1; | ||
| } | ||
|
|
||
| if (code_metadata_incomplete) { | ||
| goto degraded; | ||
| } | ||
|
|
||
| linetable = read_py_bytes(unwinder, | ||
| GET_MEMBER(uintptr_t, code_object, unwinder->debug_offsets.code_object.linetable), | ||
| MAX_LINETABLE_SIZE); | ||
| if (!linetable) { | ||
| set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read linetable from code object"); | ||
| goto error; | ||
| if (_Py_RemoteDebug_IsFatalReadError()) { | ||
| goto error; | ||
| } | ||
| PyErr_Clear(); | ||
| goto degraded; | ||
| } | ||
|
|
||
| meta = PyMem_RawMalloc(sizeof(CachedCodeMetadata)); | ||
| Expand Down Expand Up | @@ -561,6 +586,18 @@ parse_code_object(RemoteUnwinderObject *unwinder, | |
| *result = tuple; | ||
| return 0; | ||
|
|
||
| degraded: { | ||
| PyObject *degraded_tuple = make_frame_info(unwinder, file, Py_None, | ||
| func, Py_None); | ||
| Py_CLEAR(func); | ||
| Py_CLEAR(file); | ||
| if (!degraded_tuple) { | ||
| return -1; | ||
| } | ||
| *result = degraded_tuple; | ||
| return 0; | ||
| } | ||
|
|
||
| error: | ||
| Py_XDECREF(func); | ||
| Py_XDECREF(file); | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI believe that isinstance(elem, str) is dead since #135436. Perhaps we should clean this defensive code everywhere.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.