[PATCH] tools/kvm_stat: Add Python 3 support to kvm_stat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tools/kvm/kvm_stat/kvm_stat | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

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:
-- 
2.13.5




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux