failed-syscalls-by-pid.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. usage = "perf trace -s syscall-counts-by-pid.py [comm]\n";
  14. for_comm = None
  15. if len(sys.argv) > 2:
  16. sys.exit(usage)
  17. if len(sys.argv) > 1:
  18. for_comm = sys.argv[1]
  19. syscalls = autodict()
  20. def trace_begin():
  21. pass
  22. def trace_end():
  23. print_error_totals()
  24. def raw_syscalls__sys_exit(event_name, context, common_cpu,
  25. common_secs, common_nsecs, common_pid, common_comm,
  26. id, ret):
  27. if for_comm is not None:
  28. if common_comm != for_comm:
  29. return
  30. if ret < 0:
  31. try:
  32. syscalls[common_comm][common_pid][id][ret] += 1
  33. except TypeError:
  34. syscalls[common_comm][common_pid][id][ret] = 1
  35. def print_error_totals():
  36. if for_comm is not None:
  37. print "\nsyscall errors for %s:\n\n" % (for_comm),
  38. else:
  39. print "\nsyscall errors:\n\n",
  40. print "%-30s %10s\n" % ("comm [pid]", "count"),
  41. print "%-30s %10s\n" % ("------------------------------", \
  42. "----------"),
  43. comm_keys = syscalls.keys()
  44. for comm in comm_keys:
  45. pid_keys = syscalls[comm].keys()
  46. for pid in pid_keys:
  47. print "\n%s [%d]\n" % (comm, pid),
  48. id_keys = syscalls[comm][pid].keys()
  49. for id in id_keys:
  50. print " syscall: %-16d\n" % (id),
  51. ret_keys = syscalls[comm][pid][id].keys()
  52. for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True):
  53. print " err = %-20d %10d\n" % (ret, val),