iris
iris copied to clipboard
Trial different memory profiler in benchmarks
From work elsewhere, we find that it might be better to track Python heap usage, instead of Linux RSS space
At least the observation here ("When initially run, this claimed that no memory at all was used ") is relevant : It show that "RSS" is not working for a simple tests where a setup may allocate space that is then re-used within the tested operation -- but "tracemalloc" does seem to do that right.
A really simple tracemalloc solution may look like this (thanks to @jamesp )
class MemoryMonitor:
def __init__(self):
self.memory_mb = None
@contextmanager
def context(self):
"""Measure the time+memory used by a codeblock."""
tracemalloc.start()
yield
_, peak_mem = tracemalloc.get_traced_memory()
tracemalloc.stop()
self.memory_mb = peak_mem * 1.0 / 1024 ** 2
memmon = MemoryMonitor()
with memmon.context():
op()
print(memmon.memory_mb)
(though syntax usage might be improved?)
TODO : need to compare results with/without offline to assess. As @trexfeathers points out, you can't use ASV for this !
In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity.
If this issue is still important to you, then please comment on this issue and the stale label will be removed.
Otherwise this issue will be automatically closed in 28 days time.
This stale issue has been automatically closed due to a lack of community activity.
If you still care about this issue, then please either:
- Re-open this issue, if you have sufficient permissions, or
- Add a comment stating that this is still relevant and someone will re-open it on your behalf.
Having used tracemalloc elsewhere, I'm increasingly convinced that it does offer a better solution. E.G. See #5753
Having used tracemalloc elsewhere, I'm increasingly convinced that it does offer a better solution. E.G. See #5753
See now also : #5796