mirror of
https://github.com/python/cpython.git
synced 2025-09-12 11:46:52 +00:00
[3.11] GH-96612: Skip incomplete frames in tracemalloc traces. (GH-96613) (#96617)
(cherry picked from commit 95e271b226
)
Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
parent
a0848d169b
commit
26dc4dfac3
3 changed files with 23 additions and 3 deletions
|
@ -360,6 +360,20 @@ class TestTracemallocEnabled(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
support.wait_process(pid, exitcode=0)
|
support.wait_process(pid, exitcode=0)
|
||||||
|
|
||||||
|
def test_no_incomplete_frames(self):
|
||||||
|
tracemalloc.stop()
|
||||||
|
tracemalloc.start(8)
|
||||||
|
|
||||||
|
def f(x):
|
||||||
|
def g():
|
||||||
|
return x
|
||||||
|
return g
|
||||||
|
|
||||||
|
obj = f(0).__closure__[0]
|
||||||
|
traceback = tracemalloc.get_object_traceback(obj)
|
||||||
|
self.assertIn("test_tracemalloc", traceback[-1].filename)
|
||||||
|
self.assertNotIn("test_tracemalloc", traceback[-2].filename)
|
||||||
|
|
||||||
|
|
||||||
class TestSnapshot(unittest.TestCase):
|
class TestSnapshot(unittest.TestCase):
|
||||||
maxDiff = 4000
|
maxDiff = 4000
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make sure that incomplete frames do not show up in tracemalloc traces.
|
|
@ -400,7 +400,13 @@ traceback_get_frames(traceback_t *traceback)
|
||||||
}
|
}
|
||||||
|
|
||||||
_PyInterpreterFrame *pyframe = tstate->cframe->current_frame;
|
_PyInterpreterFrame *pyframe = tstate->cframe->current_frame;
|
||||||
for (; pyframe != NULL;) {
|
for (;;) {
|
||||||
|
while (pyframe && _PyFrame_IsIncomplete(pyframe)) {
|
||||||
|
pyframe = pyframe->previous;
|
||||||
|
}
|
||||||
|
if (pyframe == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) {
|
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) {
|
||||||
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
|
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
|
||||||
assert(traceback->frames[traceback->nframe].filename != NULL);
|
assert(traceback->frames[traceback->nframe].filename != NULL);
|
||||||
|
@ -410,8 +416,7 @@ traceback_get_frames(traceback_t *traceback)
|
||||||
traceback->total_nframe++;
|
traceback->total_nframe++;
|
||||||
}
|
}
|
||||||
|
|
||||||
_PyInterpreterFrame *back = pyframe->previous;
|
pyframe = pyframe->previous;
|
||||||
pyframe = back;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue