Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf script python: Add Python3 support to sctop.py

Support both Python2 and Python3 in the sctop.py script

There may be differences in the ordering of output lines due to
differences in dictionary ordering etc. However the format within lines
should be unchanged.

The use of 'from __future__' implies the minimum supported Python2 version
is now v2.6

Signed-off-by: Tony Jones <tonyj@suse.de>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-11-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Tony Jones and committed by
Arnaldo Carvalho de Melo
ee75a896 118af5bf

+16 -8
+16 -8
tools/perf/scripts/python/sctop.py
··· 8 8 # will be refreshed every [interval] seconds. The default interval is 9 9 # 3 seconds. 10 10 11 - import os, sys, thread, time 11 + from __future__ import print_function 12 + 13 + import os, sys, time 14 + 15 + try: 16 + import thread 17 + except ImportError: 18 + import _thread as thread 12 19 13 20 sys.path.append(os.environ['PERF_EXEC_PATH'] + \ 14 21 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') ··· 69 62 while 1: 70 63 clear_term() 71 64 if for_comm is not None: 72 - print "\nsyscall events for %s:\n\n" % (for_comm), 65 + print("\nsyscall events for %s:\n" % (for_comm)) 73 66 else: 74 - print "\nsyscall events:\n\n", 67 + print("\nsyscall events:\n") 75 68 76 - print "%-40s %10s\n" % ("event", "count"), 77 - print "%-40s %10s\n" % ("----------------------------------------", \ 78 - "----------"), 69 + print("%-40s %10s" % ("event", "count")) 70 + print("%-40s %10s" % 71 + ("----------------------------------------", 72 + "----------")) 79 73 80 - for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ 74 + for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \ 81 75 reverse = True): 82 76 try: 83 - print "%-40s %10d\n" % (syscall_name(id), val), 77 + print("%-40s %10d" % (syscall_name(id), val)) 84 78 except TypeError: 85 79 pass 86 80 syscalls.clear()