Is there a way to profile memory of a multithread program in Python?
For CPU profiling, I am using the cProfile to create seperate profiler stats for each thread and later combine them. However, I couldn't find a way to do this with memory profilers. I am using heapy.
Is there a way to combine stats in heapy like the cProfile? Or what other memory profilers would you suggest that is more suitable for this task.
A related question was asked for profiling CPU usage over multi-thread program: How can I profile a multithread program in Python?
Also another question regarding the memory profiler: Python memory profiler
If you are happy to profile objects rather than raw memory, you can use the
gc.get_objects()
function so you don't need a custom metaclass. In more recent Python versions,sys.getsizeof()
will also let you take a shot at figuring out how much underlying memory is in use by those objects.