I use tracemalloc in the main function to measure a Python3 program that is heavily using threading. I periodically get two stats from the main function
- Take a
tracemalloc.take_snapshot()and then add allsizeof the files fromSnapshot.statistics('filename') - Also call the
tracemalloc.get_traced_memory()to get the current size and peak size of memory blocks.
The result at the first step roughly matches the current size of memory consumption at the second step. However, both of these numbers are only about 1/10 of the memory consumption if I do top and check the same running instance.
I fail to find any document that could explain this discrepancy, nor to clarify whether or not tracemalloc could use to measure the memory of a thread-based multithreading program.