-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-130695: add count create/destroy refs to tracemalloc #130696
New issue
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
Conversation
Oh, I just realized we already have a test in cpython/Modules/_testcapimodule.c Lines 2320 to 2396 in b545450
Given that we already have a test, it might make sense to improve it instead of adding additional functionality to |
I saw that but thought its too simple for general testing. Your call... (I mean its just testing the C API like the box says)... |
@@ -94,6 +94,12 @@ struct _tracemalloc_runtime_state { | |||
/* domain (unsigned int) => traces (_Py_hashtable_t). | |||
Protected by TABLES_LOCK(). */ | |||
_Py_hashtable_t *domains; | |||
/* Number of allocations. | |||
Protected by TABLES_LOCK(). */ | |||
Py_ssize_t allocations; |
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.
I suggest to rename it to "ref_created" and "ref_destroyed".
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.
I started with that but as per colesbury above: """The terminology here is a bit confusing, but I don't think we should be calling these "references" or "refs". It's tracking object allocation and deallocation, not references or reference counts.""". Technically its tracking the first reference on an object (not all references), so excluding some unallocated "static" objects, its essentially allocations, but its called RefTracer
, so that's unfortunate. But maybe following the established naming convention, although imperfect, is better? Anyways, putting it back to refs_created/_destroyed
, but of course you have the final say so let me know which you prefer.
.. function:: get_traced_refs() | ||
|
||
Get the current count of created and destroyed traced references. | ||
:mod:`tracemalloc` module as a tuple: ``(created: int, destroyed: int)``. |
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.
I don't understand this sentence: "tracemalloc module as a tuple"?
f() | ||
refs = tracemalloc.get_traced_refs() | ||
if refs == (1, 0): | ||
warnings.warn("ceval Py_DECREF doesn't emit PyRefTracer_DESTROY in this build") |
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.
I expect a test failure, not a warning. In which case we would fall into this case? And why ignoring this failure?
|
||
Get the current count of created and destroyed traced references. | ||
:mod:`tracemalloc` module as a tuple: ``(created: int, destroyed: int)``. | ||
|
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.
You should explain what are "references" here. They are not the classical reference count. Maybe explain the difference with the reference count?
Clear traces of memory blocks allocated and counts of created and destroyed | ||
memory blocks by Python. |
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.
Clear traces of memory blocks allocated and counts of created and destroyed | |
memory blocks by Python. | |
Clear traces of memory blocks allocated by Python, and reset counts | |
of created and destroyed references. |
So far, I'm not convinced that this feature really makes sense to end users to help them tracking memory leaks. Examples given seem to be more about checking if the Python implementation is correct. |
Yeah, I actually agree, and especially adding another lock on memfree wrt perfomance is probably not worth it. Will see about suggestion above to reuse |
Add a way to track the number of allocations and specifically DEALLOCATIONS in
tracemalloc
. For a concrete example of why this is needed see:#130382
and
#130689
for the rationale for this PR.
PyRefTracer_DESTROY
events intracemalloc
#130695📚 Documentation preview 📚: https://cpython-previews--130696.org.readthedocs.build/