diff options
author | Kenneth Heafield <github@kheafield.com> | 2012-08-03 07:46:54 -0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2012-08-03 07:46:54 -0400 |
commit | be1ab0a8937f9c5668ea5e6c31b798e87672e55e (patch) | |
tree | a13aad60ab6cced213401bce6a38ac885ba171ba /sa-extract/monitor.py | |
parent | e5d6f4ae41009c26978ecd62668501af9762b0bc (diff) | |
parent | 9fe0219562e5db25171cce8776381600ff9a5649 (diff) |
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'sa-extract/monitor.py')
-rw-r--r-- | sa-extract/monitor.py | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/sa-extract/monitor.py b/sa-extract/monitor.py deleted file mode 100644 index eb0bed57..00000000 --- a/sa-extract/monitor.py +++ /dev/null @@ -1,48 +0,0 @@ -import os, resource - -def cpu(): - return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ - resource.getrusage(resource.RUSAGE_SELF).ru_stime) - -# from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222 - - -_proc_status = '/proc/%d/status' % os.getpid() - -_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0, - 'KB': 1024.0, 'MB': 1024.0*1024.0} - -def _VmB(VmKey): - '''Private. - ''' - global _proc_status, _scale - # get pseudo file /proc/<pid>/status - try: - t = open(_proc_status) - v = t.read() - t.close() - except: - return 0.0 # non-Linux? - # get VmKey line e.g. 'VmRSS: 9999 kB\n ...' - i = v.index(VmKey) - v = v[i:].split(None, 3) # whitespace - if len(v) < 3: - return 0.0 # invalid format? - # convert Vm value to bytes - return float(v[1]) * _scale[v[2]] - -def memory(since=0.0): - '''Return memory usage in bytes. - ''' - return _VmB('VmSize:') - since - -def resident(since=0.0): - '''Return resident memory usage in bytes. - ''' - return _VmB('VmRSS:') - since - - -def stacksize(since=0.0): - '''Return stack size in bytes. - ''' - return _VmB('VmStk:') - since |