6 examples of 'python print memory usage' in Python

Every line of 'python print memory usage' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
65def print_memory_usage(old=None):
66 info = get_mem_usage()
67 M = 1024*1024.0
68
69 if old:
70 print("RSS: %0.1fM (+%0.1fM), VMS: %0.1fM (+%0.1fM)" % (
71 info.rss/M, (info.rss-old.rss)/M, info.vms/M, (info.vms-old.vms)/M),
72 )
73 else:
74 print("RSS: %0.1fM, VMS: %0.1fM" % (info.rss/M, info.vms/M))
979def printMemUsage(self):
980 import humanize
981 total = 0
982 print("Memory usage:")
983 for v in self.__dict__:
984 if type(self.__dict__[v]).__module__ == np.__name__:
985 size = self.__dict__[v].nbytes
986 total += size
987 print("{}: {} ".format(v, (humanize.naturalsize(size, binary=True))), end=' ')
988 #TODO: extend for builtins
989 print("- total: {}".format(humanize.naturalsize(total, binary=True)))
154def memory_usage(where):
155 """Print out a basic summary of memory usage."""
156 mem_summary = summary.summarize(muppy.get_objects())
157 log.debug("Memory summary: {}".format(where))
158 summary.print_(mem_summary, limit=2)
159 log.debug("VM: {:2f}Mb".format(get_virtual_memory_usage_kb() / 1024.0))
191def show_memory():
192
193 M = MemoryCheck()
194 return M.value
7def memory_usage_psutil():
8 # return the memory usage in MB
9 process = psutil.Process(os.getpid())
10 #mem = process.get_memory_info()[0] / float(2 ** 20)
11 mem = process.memory_info()[0] / float(2 ** 20)
12
13
14 return mem
52def get_available_memory():
53 try:
54 import psutil # preferred way
55 res = psutil.virtual_memory().available
56 except ImportError:
57 res = platform_free_memory()
58 return res

Related snippets