Skip to content

Commit de667cc

Browse files
tonyj-suseacmel
authored andcommitted
perf script python: Add Python3 support to syscall-counts-by-pid.py
Support both Python2 and Python3 in the syscall-counts-by-pid.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> Link: http://lkml.kernel.org/r/20190222230619.17887-15-tonyj@suse.de Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 1d1b0db commit de667cc

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tools/perf/scripts/python/syscall-counts-by-pid.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# Displays system-wide system call totals, broken down by syscall.
66
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
77

8+
from __future__ import print_function
9+
810
import os, sys
911

1012
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
@@ -31,7 +33,7 @@
3133
syscalls = autodict()
3234

3335
def trace_begin():
34-
print "Press control+C to stop and show the summary"
36+
print("Press control+C to stop and show the summary")
3537

3638
def trace_end():
3739
print_syscall_totals()
@@ -55,20 +57,20 @@ def syscalls__sys_enter(event_name, context, common_cpu,
5557

5658
def print_syscall_totals():
5759
if for_comm is not None:
58-
print "\nsyscall events for %s:\n\n" % (for_comm),
60+
print("\nsyscall events for %s:\n" % (for_comm))
5961
else:
60-
print "\nsyscall events by comm/pid:\n\n",
62+
print("\nsyscall events by comm/pid:\n")
6163

62-
print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"),
63-
print "%-40s %10s\n" % ("----------------------------------------", \
64-
"----------"),
64+
print("%-40s %10s" % ("comm [pid]/syscalls", "count"))
65+
print("%-40s %10s" % ("----------------------------------------",
66+
"----------"))
6567

6668
comm_keys = syscalls.keys()
6769
for comm in comm_keys:
6870
pid_keys = syscalls[comm].keys()
6971
for pid in pid_keys:
70-
print "\n%s [%d]\n" % (comm, pid),
72+
print("\n%s [%d]" % (comm, pid))
7173
id_keys = syscalls[comm][pid].keys()
72-
for id, val in sorted(syscalls[comm][pid].iteritems(), \
73-
key = lambda(k, v): (v, k), reverse = True):
74-
print " %-38s %10d\n" % (syscall_name(id), val),
74+
for id, val in sorted(syscalls[comm][pid].items(), \
75+
key = lambda kv: (kv[1], kv[0]), reverse = True):
76+
print(" %-38s %10d" % (syscall_name(id), val))

0 commit comments

Comments
 (0)