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
8# will be refreshed every [interval] seconds. The default interval is8# will be refreshed every [interval] seconds. The default interval is
9# 3 seconds.9# 3 seconds.
10 10
11import os, sys, thread, time11from __future__ import print_function
12
13import os, sys, time
14
15try:
16 import thread
17except ImportError:
18 import _thread as thread
12 19
13sys.path.append(os.environ['PERF_EXEC_PATH'] + \20sys.path.append(os.environ['PERF_EXEC_PATH'] + \
14 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')21 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -62,18 +69,19 @@ def print_syscall_totals(interval): · 47 unmodified lines
62 while 1:69 while 1:
63 clear_term()70 clear_term()
64 if for_comm is not None:71 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))
66 else:73 else:
67 print "\nsyscall events:\n\n",74 print("\nsyscall events:\n")
68 75
69 print "%-40s %10s\n" % ("event", "count"),76 print("%-40s %10s" % ("event", "count"))
70 print "%-40s %10s\n" % ("----------------------------------------", \77 print("%-40s %10s" %
71 "----------"),78 ("----------------------------------------",
79 "----------"))
72 80
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]), \
74 reverse = True):82 reverse = True):
75 try:83 try:
76 print "%-40s %10d\n" % (syscall_name(id), val),84 print("%-40s %10d" % (syscall_name(id), val))
77 except TypeError:85 except TypeError:
78 pass86 pass
79 syscalls.clear()87 syscalls.clear()