Last active
August 29, 2015 14:11
-
-
Save cpelley/fab6fa7efd99dcd68f7b to your computer and use it in GitHub Desktop.
process statistics
This file contains hidden or 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 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