summaryrefslogtreecommitdiffstats
path: root/tools/kvm
diff options
context:
space:
mode:
authorStefan Raspl <raspl@linux.vnet.ibm.com>2017-03-10 13:40:02 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2017-03-29 12:01:25 +0200
commitdadf1e7839243474b691ca4258bfd2a59e628a5e (patch)
tree8908459086c1306540f7aa3147aad51ff5d4a6e3 /tools/kvm
parent9fc0adfc427a5e3f95f8db8dafabe1eaa3720f4a (diff)
downloadlinux-stable-dadf1e7839243474b691ca4258bfd2a59e628a5e.tar.gz
linux-stable-dadf1e7839243474b691ca4258bfd2a59e628a5e.tar.bz2
linux-stable-dadf1e7839243474b691ca4258bfd2a59e628a5e.zip
tools/kvm_stat: handle SIGINT in log and batch modes
SIGINT causes ugly unhandled exceptions in log and batch mode, which we prevent by catching the exceptions accordingly. Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com> Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Diffstat (limited to 'tools/kvm')
-rwxr-xr-xtools/kvm/kvm_stat/kvm_stat28
1 files changed, 17 insertions, 11 deletions
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index ef47ad749f8a..14536c059fd7 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -969,12 +969,15 @@ class Tui(object):
def batch(stats):
"""Prints statistics in a key, value format."""
- s = stats.get()
- time.sleep(1)
- s = stats.get()
- for key in sorted(s.keys()):
- values = s[key]
- print '%-42s%10d%10d' % (key, values[0], values[1])
+ try:
+ s = stats.get()
+ time.sleep(1)
+ s = stats.get()
+ for key in sorted(s.keys()):
+ values = s[key]
+ print '%-42s%10d%10d' % (key, values[0], values[1])
+ except KeyboardInterrupt:
+ pass
def log(stats):
"""Prints statistics as reiterating key block, multiple value blocks."""
@@ -991,11 +994,14 @@ def log(stats):
line = 0
banner_repeat = 20
while True:
- time.sleep(1)
- if line % banner_repeat == 0:
- banner()
- statline()
- line += 1
+ try:
+ time.sleep(1)
+ if line % banner_repeat == 0:
+ banner()
+ statline()
+ line += 1
+ except KeyboardInterrupt:
+ break
def get_options():
"""Returns processed program arguments."""