diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-10-25 18:44:09 -0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-10-25 18:48:15 -0200 |
commit | a64fa198ba1cd232871710c37476e006ed5516ed (patch) | |
tree | bb0116b48545b5e1a63560219306299b6d0c6cb0 /tools/perf/scripts | |
parent | 2e7d1e3fb8043380a2fc5d759eb357bf05acf935 (diff) | |
download | lwn-a64fa198ba1cd232871710c37476e006ed5516ed.tar.gz lwn-a64fa198ba1cd232871710c37476e006ed5516ed.zip |
perf python scripting: Improve the syscalls-by-pid script
. Print message at script start telling how to get te summary
. Print the syscall names
. Accept both pid (if numeric) or COMM name
Now it looks like this:
[root@emilia tmp]# perf trace syscall-counts-by-pid
Press control+C to stop and show the summary
^C
syscall events by comm/pid:
comm [pid]/syscalls count
---------------------------------------- ----------
automount [1670]
futex 2
sshd [2322]
rt_sigprocmask 4
select 2
write 1
read 1
perf [15178]
read 2506
open 794
close 769
write 240
getdents 112
lseek 16
stat 9
perf_counter_open 5
fcntl 5
mmap 5
statfs 2
perf [15179]
read 56701
open 499
stat 176
fstat 149
close 109
mmap 98
brk 75
rt_sigaction 66
munmap 42
mprotect 24
lstat 7
lseek 5
getdents 4
ioctl 3
readlink 2
futex 1
statfs 1
getegid 1
geteuid 1
getgid 1
getuid 1
getrlimit 1
fcntl 1
uname 1
write 1
[root@emilia tmp]# fg
-bash: fg: current: no such job
[root@emilia tmp]# perf trace syscall-counts-by-pid 2322
Press control+C to stop and show the summary
^C
syscall events by comm/pid:
comm [pid]/syscalls count
---------------------------------------- ----------
sshd [2322]
rt_sigprocmask 4
select 2
write 1
read 1
[root@emilia tmp]# perf trace syscall-counts-by-pid sshd
Press control+C to stop and show the summary
^C
syscall events for sshd:
comm [pid]/syscalls count
---------------------------------------- ----------
sshd [2322]
rt_sigprocmask 4
select 2
write 1
read 1
[root@emilia tmp]#
Cc: David S. Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/scripts')
-rw-r--r-- | tools/perf/scripts/python/syscall-counts-by-pid.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py index af722d6a4b3f..d1ee3ec10cf2 100644 --- a/tools/perf/scripts/python/syscall-counts-by-pid.py +++ b/tools/perf/scripts/python/syscall-counts-by-pid.py @@ -5,29 +5,33 @@ # Displays system-wide system call totals, broken down by syscall. # If a [comm] arg is specified, only syscalls called by [comm] are displayed. -import os -import sys +import os, sys sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from perf_trace_context import * from Core import * +from Util import syscall_name usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; for_comm = None +for_pid = None if len(sys.argv) > 2: sys.exit(usage) if len(sys.argv) > 1: - for_comm = sys.argv[1] + try: + for_pid = int(sys.argv[1]) + except: + for_comm = sys.argv[1] syscalls = autodict() def trace_begin(): - pass + print "Press control+C to stop and show the summary" def trace_end(): print_syscall_totals() @@ -35,9 +39,10 @@ def trace_end(): def raw_syscalls__sys_enter(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, id, args): - if for_comm is not None: - if common_comm != for_comm: - return + + if (for_comm and common_comm != for_comm) or \ + (for_pid and common_pid != for_pid ): + return try: syscalls[common_comm][common_pid][id] += 1 except TypeError: @@ -61,4 +66,4 @@ def print_syscall_totals(): id_keys = syscalls[comm][pid].keys() for id, val in sorted(syscalls[comm][pid].iteritems(), \ key = lambda(k, v): (v, k), reverse = True): - print " %-38d %10d\n" % (id, val), + print " %-38s %10d\n" % (syscall_name(id), val), |