Hi,
I like to compute differences between two snapshots (diff), rather
than looking at a single snapshot:
https://docs.python.org/dev/library/tracemalloc.html#compute-differences
You can modify your signal handler to write the snapshot into a file
using pickle.dump():
https://github.com/vstinner/tracemallocqt#usage
Then use pickle.load() to reload snapshots from files. You can take
multiple snapshots and compare snapshot 1 with snapshot 2, compare 1
with 3, etc. If there is a major memory increase between two
snapshots, I expect a significant difference between these two
snapshots.
You can configure tracemalloc to decide how many frames per traceback
are stored. See -X tracemalloc=NFRAME, PYTHONTRACEMALLOC=NFRAME and
start() argument:
https://docs.python.org/dev/library/tracemalloc.html#tracemalloc.start
tracemalloc only "sees" memory allocations made by Python. You can get
the "current size size of memory blocks traced by the tracemalloc
module" with:
https://docs.python.org/dev/library/tracemalloc.html#tracemalloc.get_trac...
Note: tracemalloc itself consumes a lot of memory, which can explain
why your application uses more RSS memory when tracemalloc is used.
If there is a huge difference between the RSS memory increase the what
tracemalloc see (ex: RSS: +100 MB, tracemalloc: +1 MB), maybe you
should use another tool working at the malloc/free level, like
Valgrind.
Victor