# -*- coding: utf-8 -*-
from __future__ import division
+import subprocess
__proc_keys__ = (
# see man 5 proc
__states__ = {
'R': 'running',
'S': 'sleeping',
- 'D': 'disk sleep',
+ 'D': 'waiting disk',
'Z': 'zombie',
- 'T': 'stoped',
- 'W': 'paging',
+ 'T': 'stopped',
+ 'W': 'swapping',
}
+def get_clk_tck():
+ process = subprocess.Popen(['getconf', 'CLK_TCK'], shell=True, stdout=subprocess.PIPE)
+ if process.wait() != 0:
+ raise "getconf CLK_TCK failed"
+ return process[0]
+
+ #= 100 -> 1 tick = 1/100 seconds
+ # require libc-bin to be installed
+
class Stat(dict):
def __init__(self, processid):
dict.__init__(self)
- strstats = file('/proc/%s/stat' % processid).read()
- # TODO:
- # "getconf CLK_TCK" = 100 -> 1 tick = 1/100 seconds
+ strstats = open('/proc/%s/stat' % processid).read()
strstats = strstats.rstrip('\n').split(' ')
for i, keycls in enumerate(__proc_keys__):
key, cls = keycls
return "%s (%s)" % (state, nice_state)
# TODO:
- # "getconf CLK_TCK" = 100 -> 1 tick = 1/100 seconds
+ # subprocess.call(['getconf', 'CLK_TCK']) = 100 -> 1 tick = 1/100 seconds
def nice_utime(self):
return self['utime'] / 100
def nice_stime(self):
return self['stime'] / 100
+
+if __name__ == '__main__':
+ print get_clk_tck()