Back to home page

OSCL-LXR

 
 

    


0001 # system call counts
0002 # (c) 2010, Tom Zanussi <tzanussi@gmail.com>
0003 # Licensed under the terms of the GNU GPL License version 2
0004 #
0005 # Displays system-wide system call totals, broken down by syscall.
0006 # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
0007 
0008 from __future__ import print_function
0009 
0010 import os
0011 import sys
0012 
0013 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
0014     '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
0015 
0016 from perf_trace_context import *
0017 from Core import *
0018 from Util import syscall_name
0019 
0020 usage = "perf script -s syscall-counts.py [comm]\n";
0021 
0022 for_comm = None
0023 
0024 if len(sys.argv) > 2:
0025     sys.exit(usage)
0026 
0027 if len(sys.argv) > 1:
0028     for_comm = sys.argv[1]
0029 
0030 syscalls = autodict()
0031 
0032 def trace_begin():
0033     print("Press control+C to stop and show the summary")
0034 
0035 def trace_end():
0036     print_syscall_totals()
0037 
0038 def raw_syscalls__sys_enter(event_name, context, common_cpu,
0039         common_secs, common_nsecs, common_pid, common_comm,
0040         common_callchain, id, args):
0041     if for_comm is not None:
0042         if common_comm != for_comm:
0043             return
0044     try:
0045         syscalls[id] += 1
0046     except TypeError:
0047         syscalls[id] = 1
0048 
0049 def syscalls__sys_enter(event_name, context, common_cpu,
0050         common_secs, common_nsecs, common_pid, common_comm, id, args):
0051     raw_syscalls__sys_enter(**locals())
0052 
0053 def print_syscall_totals():
0054     if for_comm is not None:
0055         print("\nsyscall events for %s:\n" % (for_comm))
0056     else:
0057         print("\nsyscall events:\n")
0058 
0059     print("%-40s  %10s" % ("event", "count"))
0060     print("%-40s  %10s" % ("----------------------------------------",
0061                 "-----------"))
0062 
0063     for id, val in sorted(syscalls.items(),
0064             key = lambda kv: (kv[1], kv[0]), reverse = True):
0065         print("%-40s  %10d" % (syscall_name(id), val))