diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-10-25 16:44:09 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-10-25 16:48:15 -0400 |
| commit | a64fa198ba1cd232871710c37476e006ed5516ed (patch) | |
| tree | bb0116b48545b5e1a63560219306299b6d0c6cb0 | |
| parent | 2e7d1e3fb8043380a2fc5d759eb357bf05acf935 (diff) | |
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>
| -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 @@ | |||
| 5 | # Displays system-wide system call totals, broken down by syscall. | 5 | # Displays system-wide system call totals, broken down by syscall. |
| 6 | # If a [comm] arg is specified, only syscalls called by [comm] are displayed. | 6 | # If a [comm] arg is specified, only syscalls called by [comm] are displayed. |
| 7 | 7 | ||
| 8 | import os | 8 | import os, sys |
| 9 | import sys | ||
| 10 | 9 | ||
| 11 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | 10 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ |
| 12 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | 11 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') |
| 13 | 12 | ||
| 14 | from perf_trace_context import * | 13 | from perf_trace_context import * |
| 15 | from Core import * | 14 | from Core import * |
| 15 | from Util import syscall_name | ||
| 16 | 16 | ||
| 17 | usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; | 17 | usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; |
| 18 | 18 | ||
| 19 | for_comm = None | 19 | for_comm = None |
| 20 | for_pid = None | ||
| 20 | 21 | ||
| 21 | if len(sys.argv) > 2: | 22 | if len(sys.argv) > 2: |
| 22 | sys.exit(usage) | 23 | sys.exit(usage) |
| 23 | 24 | ||
| 24 | if len(sys.argv) > 1: | 25 | if len(sys.argv) > 1: |
| 25 | for_comm = sys.argv[1] | 26 | try: |
| 27 | for_pid = int(sys.argv[1]) | ||
| 28 | except: | ||
| 29 | for_comm = sys.argv[1] | ||
| 26 | 30 | ||
| 27 | syscalls = autodict() | 31 | syscalls = autodict() |
| 28 | 32 | ||
| 29 | def trace_begin(): | 33 | def trace_begin(): |
| 30 | pass | 34 | print "Press control+C to stop and show the summary" |
| 31 | 35 | ||
| 32 | def trace_end(): | 36 | def trace_end(): |
| 33 | print_syscall_totals() | 37 | print_syscall_totals() |
| @@ -35,9 +39,10 @@ def trace_end(): | |||
| 35 | def raw_syscalls__sys_enter(event_name, context, common_cpu, | 39 | def raw_syscalls__sys_enter(event_name, context, common_cpu, |
| 36 | common_secs, common_nsecs, common_pid, common_comm, | 40 | common_secs, common_nsecs, common_pid, common_comm, |
| 37 | id, args): | 41 | id, args): |
| 38 | if for_comm is not None: | 42 | |
| 39 | if common_comm != for_comm: | 43 | if (for_comm and common_comm != for_comm) or \ |
| 40 | return | 44 | (for_pid and common_pid != for_pid ): |
| 45 | return | ||
| 41 | try: | 46 | try: |
| 42 | syscalls[common_comm][common_pid][id] += 1 | 47 | syscalls[common_comm][common_pid][id] += 1 |
| 43 | except TypeError: | 48 | except TypeError: |
| @@ -61,4 +66,4 @@ def print_syscall_totals(): | |||
| 61 | id_keys = syscalls[comm][pid].keys() | 66 | id_keys = syscalls[comm][pid].keys() |
| 62 | for id, val in sorted(syscalls[comm][pid].iteritems(), \ | 67 | for id, val in sorted(syscalls[comm][pid].iteritems(), \ |
| 63 | key = lambda(k, v): (v, k), reverse = True): | 68 | key = lambda(k, v): (v, k), reverse = True): |
| 64 | print " %-38d %10d\n" % (id, val), | 69 | print " %-38s %10d\n" % (syscall_name(id), val), |
