4 import sys
, os
, time
, optparse
8 self
.base
= '/sys/kernel/debug/kvm'
10 for key
in os
.listdir(self
.base
):
11 self
.values
[key
] = None
13 for key
, oldval
in self
.values
.iteritems():
14 newval
= int(file(self
.base
+ '/' + key
).read())
16 if oldval
is not None:
17 newdelta
= newval
- oldval
[0]
18 self
.values
[key
] = (newval
, newdelta
)
21 if not os
.access('/sys/kernel/debug', os
.F_OK
):
22 print 'Please enable CONFIG_DEBUG_FS in your kernel'
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"
34 def tui(screen
, stats
):
35 curses
.use_default_colors()
39 screen
.addstr(0, 0, 'kvm statistics')
42 for key
in sorted(s
.keys()):
43 if row
>= screen
.getmaxyx()[0]:
47 screen
.addstr(row
, col
, key
)
49 screen
.addstr(row
, col
, '%10d' % (values
[0],))
51 if values
[1] is not None:
52 screen
.addstr(row
, col
, '%8d' % (values
[1],))
63 except KeyboardInterrupt:
72 for key
in sorted(s
.keys()):
74 print '%-22s%10d%10d' % (key
, values
[0], values
[1])
76 options
= optparse
.OptionParser()
77 options
.add_option('-1', '--once', '--batch',
78 action
= 'store_true',
81 help = 'run in batch mode for one second',
83 (options
, args
) = options
.parse_args(sys
.argv
)
87 curses
.wrapper(tui
, stats
)