This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: tracemalloc: add a get_line() method to Trace and Frame classes
Type: Stage:
Components: Versions: Python 3.5
Status: closed Resolution: postponed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, larry, python-dev, r.david.murray, vstinner
Priority: normal Keywords: patch

Created on 2014-03-11 02:33 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
tracemalloc_getline.patch vstinner, 2014-03-11 02:33 review
tracemalloc_get_line-2.patch vstinner, 2014-03-11 07:26 review
Messages (6)
msg213113 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-11 02:33
Is it too late in Python 3.4 release process to add a new method to classes of the tracemalloc module?

Here is a patch which adds unit tests and uses the new method in the documentation.

Example before:

    Top 10 lines
    #1: collections/ 291.9 KiB
    #2: Lib/ 200.2 KiB
    #3: unittest/ 160.3 KiB
    #4: Lib/ 99.8 KiB
    #5: urllib/ 71.8 KiB
    #6: <string>:5: 62.7 KiB
    #7: Lib/ 59.8 KiB
    #8: Lib/ 51.8 KiB
    #9: collections/ 50.6 KiB
    #10: test/ 48.0 KiB
    7496 other: 4161.9 KiB
    Total allocated size: 5258.8 KiB

Example after:

    Top 10 lines
    #1: Lib/ 419.8 KiB
        _b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
    #2: Lib/ 419.8 KiB
        _a85chars2 = [(a + b) for a in _a85chars for b in _a85chars]
    #3: collections/ 293.6 KiB
        exec(class_definition, namespace)
    #4: Lib/ 115.2 KiB
        cls = super().__new__(mcls, name, bases, namespace)
    #5: unittest/ 103.1 KiB
    #6: Lib/ 95.4 KiB
        lines = fp.readlines()
    #7: urllib/ 71.8 KiB
        for a in _hexdig for b in _hexdig}
    #8: <string>:5: 62.0 KiB
    #9: Lib/ 60.0 KiB = set()
    #10: Lib/ 59.8 KiB
        _b32tab2 = [a + b for a in _b32tab for b in _b32tab]
    6220 other: 3602.8 KiB
    Total allocated size: 5303.1 KiB

The getline() is convinient.

Sorry for being late, but the need of the new method came when I started to work again on tracemalloc to prepare my conference for Pycon US.
msg213115 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-11 02:51
Yes it is too late.  The only reason any code changes should be made to the final RC is if we would otherwise have a brown bag release.
msg213121 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-11 07:13
New changeset 14c1ff6a8086 by Victor Stinner in branch 'default':
Issue #20888: improve "Pretty Top" example of tracemalloc, use linecache
msg213124 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-11 07:26
The method name should be "get_line", not "getline", to conform to the PEP 8.

It's not very useful to add an helper to the Traceback, it's more interesting to add it to the Trace class. So linecache.getline(trace.traceback[0].filename, trace.traceback[0].lineno) just becomes trace.get_line().

I updated the patch: tracemalloc_get_line-2.patch.

> Yes it is too late.

Ok. I applied to most interesting change (on the documentation) for Python 3.4.1.

About the patch, is it a bad thing to add new methods (get_line) to such debug module in a minor version (3.4.1)? It can be surprising if sometimes try the same code on Python 3.4.1 and 3.4.0.

Well, the proposed addition is just an helper, linecache can still used ;-) It's just convinient to write "one-shot" script (use and delete) using tracemalloc.
msg213131 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2014-03-11 09:25
The policy is clear, no API additions in micro releases (the only exceptions should be made for security issues).
msg213472 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-13 21:19
Ok, I prefer to develop this feature is tools based on tracemalloc and wait later to add this feature if it is still needed.
Date User Action Args
2022-04-11 14:57:59adminsetgithub: 65087
2014-03-13 21:19:43vstinnersetstatus: open -> closed
resolution: postponed
messages: + msg213472
2014-03-11 09:25:15georg.brandlsetnosy: + georg.brandl

messages: + msg213131
versions: + Python 3.5, - Python 3.4
2014-03-11 07:26:10vstinnersetfiles: + tracemalloc_get_line-2.patch

messages: + msg213124
title: tracemalloc: add getline() method to Traceback and Frame -> tracemalloc: add a get_line() method to Trace and Frame classes
2014-03-11 07:13:44python-devsetnosy: + python-dev
messages: + msg213121
2014-03-11 02:51:27r.david.murraysetnosy: + r.david.murray
messages: + msg213115
2014-03-11 02:33:56vstinnercreate