syscall-counts.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. from Util import syscall_name
  14. usage = "perf trace -s syscall-counts.py [comm]\n";
  15. for_comm = None
  16. if len(sys.argv) > 2:
  17. sys.exit(usage)
  18. if len(sys.argv) > 1:
  19. for_comm = sys.argv[1]
  20. syscalls = autodict()
  21. def trace_begin():
  22. print "Press control+C to stop and show the summary"
  23. def trace_end():
  24. print_syscall_totals()
  25. def raw_syscalls__sys_enter(event_name, context, common_cpu,
  26. common_secs, common_nsecs, common_pid, common_comm,
  27. id, args):
  28. if for_comm is not None:
  29. if common_comm != for_comm:
  30. return
  31. try:
  32. syscalls[id] += 1
  33. except TypeError:
  34. syscalls[id] = 1
  35. def print_syscall_totals():
  36. if for_comm is not None:
  37. print "\nsyscall events for %s:\n\n" % (for_comm),
  38. else:
  39. print "\nsyscall events:\n\n",
  40. print "%-40s %10s\n" % ("event", "count"),
  41. print "%-40s %10s\n" % ("----------------------------------------", \
  42. "-----------"),
  43. for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
  44. reverse = True):
  45. print "%-40s %10d\n" % (syscall_name(id), val),