Coverage for src/pymor/tools/memory : 68%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
## {{{ http://code.activestate.com/recipes/577504/ (r3) MIT licensed
'''Returns the memory usage of the current process in bytes
Returns ------- usage Current memory usage. change Change of memory usage since last call. ''' unit = unit.lower() assert unit in ('b', 'kb', 'mb', 'gb') factors = {'b': 1, 'kb': 1024, 'mb': 1024**2, 'gb': 1024**3} global last_memory_usage x = last_memory_usage last_memory_usage = resource.getrusage(resource.RUSAGE_SELF)[2] * 1024 return (last_memory_usage / factors[unit], (last_memory_usage - x) / factors[unit])
u = memory_usage(unit) if msg is None: print('Memory usage {0:5.1f} {1} - delta: {2:5.1f} {1}'.format(u[0], unit.upper(), u[1])) else: print('Memory usage {0:5.1f} {1} - delta: {2:5.1f} {1} - {3}'.format(u[0], unit.upper(), u[1], msg))
""" Returns the approximate memory footprint of an object and all of its contents.
Automatically finds the contents of the following builtin containers and their subclasses: tuple, list, deque, dict, set and frozenset. To search other containers, add handlers to iterate over their contents:
handlers = {SomeContainerClass: iter, OtherContainerClass: OtherContainerClass.get_elements}
""" list: iter, deque: iter, dict: dict_handler, set: iter, frozenset: iter, }
return 0
print(s, type(o), repr(o), file=stderr)
##### Example call #####
d = dict(a=1, b=2, c=3, d=[4, 5, 6, 7], e='a string of chars') print(total_size(d, verbose=True)) ## end of http://code.activestate.com/recipes/577504/ }}} |