failed-syscalls-by-pid.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # failed system call counts, by pid
  2. # (c) 2010, Tom Zanussi <tzanussi@gmail.com>
  3. # Licensed under the terms of the GNU GPL License version 2
  4. #
  5. # Displays system-wide failed system call totals, broken down by pid.
  6. # If a [comm] arg is specified, only syscalls called by [comm] are displayed.
  7. import os
  8. import sys
  9. sys.path.append(os.environ['PERF_EXEC_PATH'] + \
  10. '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
  11. from perf_trace_context import *
  12. from Core import *
  13. from Util import *
  14. usage = "perf script -s syscall-counts-by-pid.py [comm|pid]\n";
  15. for_comm = None
  16. for_pid = None
  17. if len(sys.argv) > 2:
  18. sys.exit(usage)
  19. if len(sys.argv) > 1:
  20. try:
  21. for_pid = int(sys.argv[1])
  22. except:
  23. for_comm = sys.argv[1]
  24. syscalls = autodict()
  25. def trace_begin():
  26. print "Press control+C to stop and show the summary"
  27. def trace_end():
  28. print_error_totals()
  29. def raw_syscalls__sys_exit(event_name, context, common_cpu,
  30. common_secs, common_nsecs, common_pid, common_comm,
  31. common_callchain, id, ret):
  32. if (for_comm and common_comm != for_comm) or \
  33. (for_pid and common_pid != for_pid ):
  34. return
  35. if ret < 0:
  36. try:
  37. syscalls[common_comm][common_pid][id][ret] += 1
  38. except TypeError:
  39. syscalls[common_comm][common_pid][id][ret] = 1
  40. def syscalls__sys_exit(event_name, context, common_cpu,
  41. common_secs, common_nsecs, common_pid, common_comm,
  42. id, ret):
  43. raw_syscalls__sys_exit(**locals())
  44. def print_error_totals():
  45. if for_comm is not None:
  46. print "\nsyscall errors for %s:\n\n" % (for_comm),
  47. else:
  48. print "\nsyscall errors:\n\n",
  49. print "%-30s %10s\n" % ("comm [pid]", "count"),
  50. print "%-30s %10s\n" % ("------------------------------", \
  51. "----------"),
  52. comm_keys = syscalls.keys()
  53. for comm in comm_keys:
  54. pid_keys = syscalls[comm].keys()
  55. for pid in pid_keys:
  56. print "\n%s [%d]\n" % (comm, pid),
  57. id_keys = syscalls[comm][pid].keys()
  58. for id in id_keys:
  59. print " syscall: %-16s\n" % syscall_name(id),
  60. ret_keys = syscalls[comm][pid][id].keys()
  61. for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True):
  62. print " err = %-20s %10d\n" % (strerror(ret), val),