diff options
Diffstat (limited to 'tools/perf/scripts/python/sctop.py')
-rw-r--r-- | tools/perf/scripts/python/sctop.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py new file mode 100644 index 000000000000..6cafad40c296 --- /dev/null +++ b/tools/perf/scripts/python/sctop.py | |||
@@ -0,0 +1,78 @@ | |||
1 | # system call top | ||
2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
3 | # Licensed under the terms of the GNU GPL License version 2 | ||
4 | # | ||
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 | ||
9 | # 3 seconds. | ||
10 | |||
11 | import thread | ||
12 | import time | ||
13 | import os | ||
14 | import sys | ||
15 | |||
16 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
17 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
18 | |||
19 | from perf_trace_context import * | ||
20 | from Core import * | ||
21 | from Util import * | ||
22 | |||
23 | usage = "perf trace -s syscall-counts.py [comm] [interval]\n"; | ||
24 | |||
25 | for_comm = None | ||
26 | default_interval = 3 | ||
27 | interval = default_interval | ||
28 | |||
29 | if len(sys.argv) > 3: | ||
30 | sys.exit(usage) | ||
31 | |||
32 | if len(sys.argv) > 2: | ||
33 | for_comm = sys.argv[1] | ||
34 | interval = int(sys.argv[2]) | ||
35 | elif len(sys.argv) > 1: | ||
36 | try: | ||
37 | interval = int(sys.argv[1]) | ||
38 | except ValueError: | ||
39 | for_comm = sys.argv[1] | ||
40 | interval = default_interval | ||
41 | |||
42 | syscalls = autodict() | ||
43 | |||
44 | def trace_begin(): | ||
45 | thread.start_new_thread(print_syscall_totals, (interval,)) | ||
46 | pass | ||
47 | |||
48 | def raw_syscalls__sys_enter(event_name, context, common_cpu, | ||
49 | common_secs, common_nsecs, common_pid, common_comm, | ||
50 | id, args): | ||
51 | if for_comm is not None: | ||
52 | if common_comm != for_comm: | ||
53 | return | ||
54 | try: | ||
55 | syscalls[id] += 1 | ||
56 | except TypeError: | ||
57 | syscalls[id] = 1 | ||
58 | |||
59 | def print_syscall_totals(interval): | ||
60 | while 1: | ||
61 | clear_term() | ||
62 | if for_comm is not None: | ||
63 | print "\nsyscall events for %s:\n\n" % (for_comm), | ||
64 | else: | ||
65 | print "\nsyscall events:\n\n", | ||
66 | |||
67 | print "%-40s %10s\n" % ("event", "count"), | ||
68 | print "%-40s %10s\n" % ("----------------------------------------", \ | ||
69 | "----------"), | ||
70 | |||
71 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ | ||
72 | reverse = True): | ||
73 | try: | ||
74 | print "%-40d %10d\n" % (id, val), | ||
75 | except TypeError: | ||
76 | pass | ||
77 | syscalls.clear() | ||
78 | time.sleep(interval) | ||