Skip to content

Instantly share code, notes, and snippets.

@cpelley
Last active August 29, 2015 14:11
Show Gist options
  • Save cpelley/fab6fa7efd99dcd68f7b to your computer and use it in GitHub Desktop.
Save cpelley/fab6fa7efd99dcd68f7b to your computer and use it in GitHub Desktop.
process statistics
from functools import wraps
import os
def proc_stat():
pid = os.getpid()
fnme = os.path.join('/', 'proc', str(pid), 'status')
fields = ['VmSize', 'VmRSS', 'VmPeak', 'VmHWM']
with open(fnme, 'r') as fh:
for line in fh:
for field in fields:
if field in line:
print line.strip()
def timer(func):
@wraps(func)
def time_measure(*args, **kwargs):
tt = time.time()
result = func(*args, **kwargs)
time_taken = time.time() - tt
unit = 's'
if time_taken > (60*60):
time_taken /= (60*60)
unit = 'hr'
elif time_taken > 60:
time_taken /= 60
unit = 'm'
print "'{}' took {} {}".format(func.func_name, time_taken, unit)
return result
return time_measure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment