2 # (c) 2010, Tom Zanussi <tzanussi@gmail.com>
3 # Licensed under the terms of the GNU GPL License version 2
5 # Periodically displays system-wide system call totals, broken down by
6 # syscall. If a [comm] arg is specified, only syscalls called by
7 # [comm] are displayed. If an [interval] arg is specified, the display
8 # will be refreshed every [interval] seconds. The default interval is
11 from __future__
import print_function
18 import _thread
as thread
20 sys
.path
.append(os
.environ
['PERF_EXEC_PATH'] + \
21 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
23 from perf_trace_context
import *
27 usage
= "perf script -s sctop.py [comm] [interval]\n";
31 interval
= default_interval
37 for_comm
= sys
.argv
[1]
38 interval
= int(sys
.argv
[2])
39 elif len(sys
.argv
) > 1:
41 interval
= int(sys
.argv
[1])
43 for_comm
= sys
.argv
[1]
44 interval
= default_interval
49 thread
.start_new_thread(print_syscall_totals
, (interval
,))
52 def raw_syscalls__sys_enter(event_name
, context
, common_cpu
,
53 common_secs
, common_nsecs
, common_pid
, common_comm
,
54 common_callchain
, id, args
):
55 if for_comm
is not None:
56 if common_comm
!= for_comm
:
63 def syscalls__sys_enter(event_name
, context
, common_cpu
,
64 common_secs
, common_nsecs
, common_pid
, common_comm
,
66 raw_syscalls__sys_enter(**locals())
68 def print_syscall_totals(interval
):
71 if for_comm
is not None:
72 print("\nsyscall events for %s:\n" % (for_comm
))
74 print("\nsyscall events:\n")
76 print("%-40s %10s" % ("event", "count"))
78 ("----------------------------------------",
81 for id, val
in sorted(syscalls
.items(),
82 key
= lambda kv
: (kv
[1], kv
[0]),
85 print("%-40s %10d" % (syscall_name(id), val
))