check-perf-trace.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # perf trace event handlers, generated by perf trace -g python
  2. # (c) 2010, Tom Zanussi <tzanussi@gmail.com>
  3. # Licensed under the terms of the GNU GPL License version 2
  4. #
  5. # This script tests basic functionality such as flag and symbol
  6. # strings, common_xxx() calls back into perf, begin, end, unhandled
  7. # events, etc. Basically, if this script runs successfully and
  8. # displays expected results, Python scripting support should be ok.
  9. import os
  10. import sys
  11. sys.path.append(os.environ['PERF_EXEC_PATH'] + \
  12. '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
  13. from Core import *
  14. from perf_trace_context import *
  15. unhandled = autodict()
  16. def trace_begin():
  17. print "trace_begin"
  18. pass
  19. def trace_end():
  20. print_unhandled()
  21. def irq__softirq_entry(event_name, context, common_cpu,
  22. common_secs, common_nsecs, common_pid, common_comm,
  23. vec):
  24. print_header(event_name, common_cpu, common_secs, common_nsecs,
  25. common_pid, common_comm)
  26. print_uncommon(context)
  27. print "vec=%s\n" % \
  28. (symbol_str("irq__softirq_entry", "vec", vec)),
  29. def kmem__kmalloc(event_name, context, common_cpu,
  30. common_secs, common_nsecs, common_pid, common_comm,
  31. call_site, ptr, bytes_req, bytes_alloc,
  32. gfp_flags):
  33. print_header(event_name, common_cpu, common_secs, common_nsecs,
  34. common_pid, common_comm)
  35. print_uncommon(context)
  36. print "call_site=%u, ptr=%u, bytes_req=%u, " \
  37. "bytes_alloc=%u, gfp_flags=%s\n" % \
  38. (call_site, ptr, bytes_req, bytes_alloc,
  39. flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)),
  40. def trace_unhandled(event_name, context, common_cpu, common_secs, common_nsecs,
  41. common_pid, common_comm):
  42. try:
  43. unhandled[event_name] += 1
  44. except TypeError:
  45. unhandled[event_name] = 1
  46. def print_header(event_name, cpu, secs, nsecs, pid, comm):
  47. print "%-20s %5u %05u.%09u %8u %-20s " % \
  48. (event_name, cpu, secs, nsecs, pid, comm),
  49. # print trace fields not included in handler args
  50. def print_uncommon(context):
  51. print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \
  52. % (common_pc(context), trace_flag_str(common_flags(context)), \
  53. common_lock_depth(context))
  54. def print_unhandled():
  55. keys = unhandled.keys()
  56. if not keys:
  57. return
  58. print "\nunhandled events:\n\n",
  59. print "%-40s %10s\n" % ("event", "count"),
  60. print "%-40s %10s\n" % ("----------------------------------------", \
  61. "-----------"),
  62. for event_name in keys:
  63. print "%-40s %10d\n" % (event_name, unhandled[event_name])