check-perf-trace.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # perf script event handlers, generated by perf script -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. common_callchain, 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. common_callchain, 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, event_fields_dict):
  41. try:
  42. unhandled[event_name] += 1
  43. except TypeError:
  44. unhandled[event_name] = 1
  45. def print_header(event_name, cpu, secs, nsecs, pid, comm):
  46. print "%-20s %5u %05u.%09u %8u %-20s " % \
  47. (event_name, cpu, secs, nsecs, pid, comm),
  48. # print trace fields not included in handler args
  49. def print_uncommon(context):
  50. print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \
  51. % (common_pc(context), trace_flag_str(common_flags(context)), \
  52. common_lock_depth(context))
  53. def print_unhandled():
  54. keys = unhandled.keys()
  55. if not keys:
  56. return
  57. print "\nunhandled events:\n\n",
  58. print "%-40s %10s\n" % ("event", "count"),
  59. print "%-40s %10s\n" % ("----------------------------------------", \
  60. "-----------"),
  61. for event_name in keys:
  62. print "%-40s %10d\n" % (event_name, unhandled[event_name])