kvm: libkvm: track more memory slot fields
[qemu-kvm/fedora.git] / kvm / kvm_stat
blob77e25641ba309210ad0cabdb19b1a08bd2999500
1 #!/usr/bin/python
3 import curses
4 import sys, os, time
6 class Stats:
7 def __init__(self):
8 self.base = '/sys/kernel/debug/kvm'
9 self.values = {}
10 for key in os.listdir(self.base):
11 self.values[key] = None
12 def get(self):
13 for key, oldval in self.values.iteritems():
14 newval = int(file(self.base + '/' + key).read())
15 newdelta = None
16 if oldval is not None:
17 newdelta = newval - oldval[0]
18 self.values[key] = (newval, newdelta)
19 return self.values
21 if not os.access('/sys/kernel/debug', os.F_OK):
22 print 'Please enable CONFIG_DEBUG_FS in your kernel'
23 sys.exit(1)
24 if not os.access('/sys/kernel/debug/kvm', os.F_OK):
25 print "Please mount debugfs ('mount -t debugfs debugfs /sys/kernel/debug')"
26 print "and ensure the kvm modules are loaded"
27 sys.exit(1)
29 stats = Stats()
31 def main(screen, stats):
32 curses.use_default_colors()
33 curses.noecho()
34 def refresh():
35 screen.erase()
36 screen.addstr(0, 0, 'kvm statistics')
37 row = 2
38 s = stats.get()
39 for key in sorted(s.keys()):
40 values = s[key]
41 screen.addstr(row, 1, key)
42 screen.addstr(row, 12, '%10d' % (values[0],))
43 if values[1] is not None:
44 screen.addstr(row, 22, '%8d' % (values[1],))
45 row += 1
46 screen.refresh()
48 while True:
49 refresh()
50 curses.halfdelay(10)
51 try:
52 c = screen.getkey()
53 if c == 'q':
54 break
55 except KeyboardInterrupt:
56 break
57 except curses.error:
58 continue
61 import curses.wrapper
62 curses.wrapper(main, stats)