Back to home page

OSCL-LXR

 
 

    


0001 # failed system call counts, by pid
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 failed system call totals, broken down by pid.
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 *
0019 
0020 usage = "perf script -s syscall-counts-by-pid.py [comm|pid]\n";
0021 
0022 for_comm = None
0023 for_pid = None
0024 
0025 if len(sys.argv) > 2:
0026     sys.exit(usage)
0027 
0028 if len(sys.argv) > 1:
0029     try:
0030         for_pid = int(sys.argv[1])
0031     except:
0032         for_comm = sys.argv[1]
0033 
0034 syscalls = autodict()
0035 
0036 def trace_begin():
0037     print("Press control+C to stop and show the summary")
0038 
0039 def trace_end():
0040     print_error_totals()
0041 
0042 def raw_syscalls__sys_exit(event_name, context, common_cpu,
0043     common_secs, common_nsecs, common_pid, common_comm,
0044     common_callchain, id, ret):
0045     if (for_comm and common_comm != for_comm) or \
0046        (for_pid  and common_pid  != for_pid ):
0047         return
0048 
0049     if ret < 0:
0050         try:
0051             syscalls[common_comm][common_pid][id][ret] += 1
0052         except TypeError:
0053             syscalls[common_comm][common_pid][id][ret] = 1
0054 
0055 def syscalls__sys_exit(event_name, context, common_cpu,
0056     common_secs, common_nsecs, common_pid, common_comm,
0057     id, ret):
0058     raw_syscalls__sys_exit(**locals())
0059 
0060 def print_error_totals():
0061     if for_comm is not None:
0062         print("\nsyscall errors for %s:\n" % (for_comm))
0063     else:
0064         print("\nsyscall errors:\n")
0065 
0066     print("%-30s  %10s" % ("comm [pid]", "count"))
0067     print("%-30s  %10s" % ("------------------------------", "----------"))
0068 
0069     comm_keys = syscalls.keys()
0070     for comm in comm_keys:
0071         pid_keys = syscalls[comm].keys()
0072         for pid in pid_keys:
0073             print("\n%s [%d]" % (comm, pid))
0074             id_keys = syscalls[comm][pid].keys()
0075             for id in id_keys:
0076                 print("  syscall: %-16s" % syscall_name(id))
0077                 ret_keys = syscalls[comm][pid][id].keys()
0078                 for ret, val in sorted(syscalls[comm][pid][id].items(), key = lambda kv: (kv[1], kv[0]), reverse = True):
0079                     print("    err = %-20s  %10d" % (strerror(ret), val))