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
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -8,7 +8,14 @@ · 7 unmodified lines | |||
| 8 | # will be refreshed every [interval] seconds. The default interval is | 8 | # will be refreshed every [interval] seconds. The default interval is |
| 9 | # 3 seconds. | 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 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | 20 | sys.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 | pass | 86 | pass |
| 79 | syscalls.clear() | 87 | syscalls.clear() |