Skip to content
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

fnmatch.py can appear in tracemalloc diffs #66151

Closed
pitrou opened this issue Jul 10, 2014 · 4 comments
Closed

fnmatch.py can appear in tracemalloc diffs #66151

pitrou opened this issue Jul 10, 2014 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Jul 10, 2014

BPO 21952
Nosy @pitrou, @vstinner, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-12-06.16:21:43.530>
created_at = <Date 2014-07-10.19:36:07.100>
labels = ['type-bug', 'library']
title = 'fnmatch.py can appear in tracemalloc diffs'
updated_at = <Date 2021-12-06.16:21:43.529>
user = 'https://github.com/pitrou'

bugs.python.org fields:

activity = <Date 2021-12-06.16:21:43.529>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2021-12-06.16:21:43.530>
closer = 'vstinner'
components = ['Library (Lib)']
creation = <Date 2014-07-10.19:36:07.100>
creator = 'pitrou'
dependencies = []
files = []
hgrepos = []
issue_num = 21952
keywords = []
message_count = 4.0
messages = ['222692', '222696', '246722', '407829']
nosy_count = 3.0
nosy_names = ['pitrou', 'vstinner', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue21952'
versions = ['Python 3.4', 'Python 3.5']

@pitrou
Copy link
Member Author

pitrou commented Jul 10, 2014

When using some filters and comparing snapshots, fnmatch will appear in the statistic diffs, e.g.:

/home/antoine/34/lib/python3.4/fnmatch.py:70: size=824 B (+64 B), count=2 (+1), average=412 B
eeleak.py:37: size=2512 B (+0 B), count=3 (+0), average=837 B
/home/antoine/llvmpy/llvm/ee.py:109: size=976 B (+0 B), count=2 (+0), average=488 B
/home/antoine/llvmpy/llvm/core.py:401: size=904 B (+0 B), count=2 (+0), average=452 B
/home/antoine/34/lib/python3.4/sre_compile.py:488: size=856 B (+0 B), count=1 (+0), average=856 B

Perhaps it would be nice to manually cache the compiled re pattern, instead of going through fnmatch's lru_cache thing which seems to make reports less robust.

@pitrou pitrou added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 10, 2014
@vstinner
Copy link
Member

When using some filters and comparing snapshots, fnmatch will appear in the statistic diffs, e.g.:

During the design of the tracemalloc module (PEP-454), it was decided to not filter traces in the C module, but filter traces on a snapshot object. The reason is to keep the C module simple. To debug, you can analyze snapshots on a fast machine.

Can you try to filter traces?

snapshot = snapshot.filter_traces(Filter(False, tracemalloc.__file__))

In you case, the top frame is in the fnmatch module, so you probably need to trace more than one thread (ex: tracemalloc.start(10)) and apply the filter on all frames, not only on the top frame:

snapshot = snapshot.filter_traces(Filter(False, tracemalloc.__file__, all_frames=True))

You can also ignore fnmatch & sre_compile modules (blacklist, exclusive filters), or only keep traces of the directory /home/antoine/llvmpy/llvm/ (whitelist, an inclusive filter).

Perhaps it would be nice to manually cache the compiled re pattern, instead of going through fnmatch's lru_cache thing which seems to make reports less robust.

Ah, interesting point. Would you be interested to work on that?

I tried to use tracemalloc to detect memory leaks in test.regrtest, but it's very difficult to get a reliable output. See the issue bpo-19816.

@serhiy-storchaka
Copy link
Member

In 3.5+ lru_cache() is implemented in C. Is this issue still actual?

@vstinner
Copy link
Member

vstinner commented Dec 6, 2021

Exposing internal caches in tracemalloc is not a bug but a deliberate choice. It's easy to write your own filters to ignore selected files (or even specific functions if you can locate them by line nubmers).

@vstinner vstinner closed this as completed Dec 6, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants