diff mbox

tools/kvm_stat: Add Python 3 support to kvm_stat

Message ID 0100015e90f5f216-374488c9-c5cb-43e9-825e-15f006b79825-000000@email.amazonses.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jeremy Cline Sept. 17, 2017, 5:49 p.m. UTC
Make kvm_stat support Python 3 by changing the use of "print" to a
function rather than a statement and switching from "iteritems" (removed
in Python 3) to "items".

With this change, kvm_stat is usable with Python 2.6 and greater.

Signed-off-by: Jeremy Cline <jeremy@jcline.org>
---
 tools/kvm/kvm_stat/kvm_stat | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Stefan Hajnoczi Sept. 18, 2017, 9:32 a.m. UTC | #1
On Sun, Sep 17, 2017 at 05:49:51PM +0000, Jeremy Cline wrote:
> Make kvm_stat support Python 3 by changing the use of "print" to a
> function rather than a statement and switching from "iteritems" (removed
> in Python 3) to "items".
> 
> With this change, kvm_stat is usable with Python 2.6 and greater.
> 
> Signed-off-by: Jeremy Cline <jeremy@jcline.org>
> ---
>  tools/kvm/kvm_stat/kvm_stat | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox

Patch

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 32283d88701a..1ed18b3e619c 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -19,6 +19,7 @@  Three different ways of output formatting are available:
 
 The data is sampled from the KVM's debugfs entries and its perf events.
 """
+from __future__ import print_function
 
 import curses
 import sys
@@ -666,7 +667,7 @@  class TracepointProvider(Provider):
         """Returns 'event name: current value' for all enabled events."""
         ret = defaultdict(int)
         for group in self.group_leaders:
-            for name, val in group.read().iteritems():
+            for name, val in group.read().items():
                 if name in self._fields:
                     ret[name] += val
         return ret
@@ -1369,7 +1370,7 @@  def batch(stats):
         s = stats.get()
         for key in sorted(s.keys()):
             values = s[key]
-            print '%-42s%10d%10d' % (key, values[0], values[1])
+            print('%-42s%10d%10d' % (key, values[0], values[1]))
     except KeyboardInterrupt:
         pass
 
@@ -1380,14 +1381,14 @@  def log(stats):
 
     def banner():
         for k in keys:
-            print '%s' % k,
-        print
+            print(k)
+        print()
 
     def statline():
         s = stats.get()
         for k in keys:
-            print ' %9d' % s[k][1],
-        print
+            print(' %9d' % s[k][1])
+        print()
     line = 0
     banner_repeat = 20
     while True: