History

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

Tony Jones committed 7 years ago

Commit ee75a891 parent 118af5b1 file · +16 −8Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/sctop.py+16−8
@@ -8,7 +8,14 @@ · 7 unmodified lines
88 # will be refreshed every [interval] seconds. The default interval is
99 # 3 seconds.
1010
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
1219
1320 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
1421 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -62,18 +69,19 @@ def print_syscall_totals(interval): · 47 unmodified lines
6269 while 1:
6370 clear_term()
6471 if for_comm is not None:
65− print "\nsyscall events for %s:\n\n" % (for_comm),
72+ print("\nsyscall events for %s:\n" % (for_comm))
6673 else:
67− print "\nsyscall events:\n\n",
74+ print("\nsyscall events:\n")
6875
69− print "%-40s %10s\n" % ("event", "count"),
70− print "%-40s %10s\n" % ("----------------------------------------", \
71− "----------"),
76+ print("%-40s %10s" % ("event", "count"))
77+ print("%-40s %10s" %
78+ ("----------------------------------------",
79+ "----------"))
7280
73− for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
81+ for id, val in sorted(syscalls.items(), key = lambda kv: (kv[1], kv[0]), \
7482 reverse = True):
7583 try:
76− print "%-40s %10d\n" % (syscall_name(id), val),
84+ print("%-40s %10d" % (syscall_name(id), val))
7785 except TypeError:
7886 pass
7987 syscalls.clear()