Created
August 17, 2015 10:20
-
-
Save martinth/1042c452046600529e52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pympler import summary, muppy | |
import psutil | |
# source: http://www.mobify.com/blog/sqlalchemy-memory-magic/ | |
def get_virtual_memory_usage_kb(): # pragma: no cover | |
""" | |
The process's current virtual memory size in Kb, as a float. | |
""" | |
return float(psutil.Process().memory_info_ex().vms) / 1024.0 | |
def memory_usage(where, object_limit=2): # pragma: no cover | |
""" | |
Print out a basic summary of memory usage. | |
""" | |
mem_summary = summary.summarize(muppy.get_objects()) | |
print("Memory summary:", where) | |
summary.print_(mem_summary, limit=object_limit) | |
print("VM: %.2fMb" % (get_virtual_memory_usage_kb() / 1024.0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment