Re: [Python-Dev] [Python-checkins] cpython: Close #19762: Fix name of _get_traces() and _get_object_traceback() function
Why are these functions (get_traces and get_object_traceback) private? (1) Is the whole module provisional? At one point, I had thought so, but I don't see that in the PEP or implementation. (I'm not sure that it should be provisional, but I want to be sure that the decision is intentional.) (2) This implementation does lock in certain choices about the nature of traces. (What data to include for analysis vs excluding to save memory; which events are tracked separately and which combined into a single total; organizing the data that is saved in a hash by certain keys; etc) While I would prefer more flexibility, the existing code provides a reasonable default, and I can't forsee changing traces so much that these functions *can't* be reasonably supported unless the rest of the module API changes too. (3) get_object_traceback is the killer app that justifies the specific data-collection choices Victor made; if it isn't public, the implementation starts to look overbuilt. (4) get_traces is about the only way to get at even the all the data that *is* stored, prior to additional summarization. If it isn't public, those default summarization options become even more locked in.. -jJ On Mon, Nov 25, 2013 at 3:34 AM, victor.stinner <python-checkins@python.org>wrote:
http://hg.python.org/cpython/rev/2e2ec595dc58 changeset: 87551:2e2ec595dc58 user: Victor Stinner <victor.stinner@gmail.com> date: Mon Nov 25 09:33:18 2013 +0100 summary: Close #19762: Fix name of _get_traces() and _get_object_traceback() function name in their docstring. Patch written by Vajrasky Kok.
files: Modules/_tracemalloc.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -1018,7 +1018,7 @@ }
PyDoc_STRVAR(tracemalloc_get_traces_doc, - "get_traces() -> list\n" + "_get_traces() -> list\n" "\n" "Get traces of all memory blocks allocated by Python.\n" "Return a list of (size: int, traceback: tuple) tuples.\n" @@ -1083,7 +1083,7 @@ }
PyDoc_STRVAR(tracemalloc_get_object_traceback_doc, - "get_object_traceback(obj)\n" + "_get_object_traceback(obj)\n" "\n" "Get the traceback where the Python object obj was allocated.\n" "Return a tuple of (filename: str, lineno: int) tuples.\n"
-- Repository URL: http://hg.python.org/cpython
_______________________________________________ Python-checkins mailing list Python-checkins@python.org https://mail.python.org/mailman/listinfo/python-checkins
2013/11/25 Jim Jewett <jimjjewett@gmail.com>:
Why are these functions (get_traces and get_object_traceback) private?
_get_object_traceback() is wrapped to get a nice Python object: http://hg.python.org/cpython/file/6ec6facb69ca/Lib/tracemalloc.py#l208 _get_traces() is private, it is used internally by take_snapshot(): http://hg.python.org/cpython/file/6ec6facb69ca/Lib/tracemalloc.py#l455 So it's possible to modify the low-level (private) structure used in the C module without touching the high-level (public) Python API.
(1) Is the whole module provisional? At one point, I had thought so, but I don't see that in the PEP or implementation. (I'm not sure that it should be provisional, but I want to be sure that the decision is intentional.)
I don't know.
(2) This implementation does lock in certain choices about the nature of traces. (What data to include for analysis vs excluding to save memory; which events are tracked separately and which combined into a single total; organizing the data that is saved in a hash by certain keys; etc)
While I would prefer more flexibility, the existing code provides a reasonable default, and I can't forsee changing traces so much that these functions *can't* be reasonably supported unless the rest of the module API changes too.
Sorry, I don't see which kind of information is "excluded" to save memory. Maybe you read an old version of the PEP? About "events": tracemalloc doesn't store functions calls as event, there is no timestamp. I didn't try to implement that, and I doesn't want to. If you develop it (maybe on top of tracemalloc, I mean by modify _tracemalloc.c), I would be interested to see your code and test it :-)
(3) get_object_traceback is the killer app that justifies the specific data-collection choices Victor made; if it isn't public, the implementation starts to look overbuilt.
It is public, see the doc and the doc: http://docs.python.org/dev/library/tracemalloc.html#tracemalloc.get_object_t... http://www.python.org/dev/peps/pep-0454/
(4) get_traces is about the only way to get at even the all the data that *is* stored, prior to additional summarization. If it isn't public, those default summarization options become even more locked in..
Snapshot.traces contains exactly the same data than _get_traces(). In a previous version of the PEP/code, statistics were computed while traces were collected. It's not more the case. Now the API only collect raw data, and then you have call to Snapshot.statistics() or Snapshot.compare_to(). Victor
participants (2)
-
Jim Jewett
-
Victor Stinner