syscall-counts.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # system call counts
  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 system call totals, broken down by syscall.
  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.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_syscall_totals()
  24. def raw_syscalls__sys_enter(event_name, context, common_cpu,
  25. common_secs, common_nsecs, common_pid, common_comm,
  26. id, args):
  27. if for_comm is not None:
  28. if common_comm != for_comm:
  29. return
  30. try:
  31. syscalls[id] += 1
  32. except TypeError:
  33. syscalls[id] = 1
  34. def print_syscall_totals():
  35. if for_comm is not None:
  36. print "\nsyscall events for %s:\n\n" % (for_comm),
  37. else:
  38. print "\nsyscall events:\n\n",
  39. print "%-40s %10s\n" % ("event", "count"),
  40. print "%-40s %10s\n" % ("----------------------------------------", \
  41. "-----------"),
  42. for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
  43. reverse = True):
  44. print "%-40d %10d\n" % (id, val),