Reputation: 11
I have a code where I need to save RAM usage so I've been tracing RAM usage through tracemalloc.get_traced_memory
. However, I have found that what tracemalloc.get_traced_memory
gives is very different from the RAM usage I see through htop
. In particular, the usage appearing in htop
is more than twice than the usage returned by tracemalloc.get_traced_memory[1]
(which is supposed to return the peak
value). I wonder why this is happening, and what would be a more accurate way to trace RAM usage other than tracemalloc.get_traced_memory
?
Ubuntu 20.04.4 LTS python version: 3.7.15
Upvotes: 1
Views: 589
Reputation: 9
It is important to note that tracemalloc only traces memory usage of Python objects that have been allocated through Python's memory manager, so it may not accurately reflect memory usage of other resources like file handles or sockets. Additionally, tracemalloc only tracks memory usage of the current process, so it does not account for memory used by child processes or other system resources.
Upvotes: 0