Use PREFIX in install rule.
[SysBars.git] / procstat.py
bloba7c847dafea319a961f517fb88f63e2a788fcbb7
1 #!/usr/bin/env/python
3 import time
5 old_idle = [0, 0, 0]
6 old_busy = [0, 0, 0]
8 fp = open('/proc/stat', 'r')
9 while True:
10 while True:
11 idle = [0, 0, 0]
12 busy = [0, 0, 0]
13 line = fp.readline()
14 if not line:
15 break
16 if line.startswith('cpu'):
17 figures = line.split()
18 cpu = figures[0]
19 figures = map((lambda x: long(x)), figures[1:])
20 busy = figures[0] + figures[1] + figures[2]
21 idle = figures[3]
22 if len(figures) >= 7:
23 idle += figures[4]
24 busy += figures[5] + figures[6]
25 if len(figures) >= 8:
26 busy += figures[7]
27 if cpu == 'cpu':
28 cpu = 0
29 else:
30 cpu = int(cpu[3:]) + 1
31 idle[cpu] = idle
32 busy[cpu] = busy
33 for n in range(3):
34 if n == 0:
35 print "CPU A",
36 else:
37 print "CPU", n - 1,
38 print busy[cpu], ':', idle[cpu] + busy[cpu], ' = ', \
39 100 * busy[cpu] / (busy[cpu] + idle[cpu]), '%'
40 old_idle = idle
41 old_busy = busy
42 time.sleep(1)
43 fp.rewind()