check-perf-trace.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. from __future__ import print_function
  10. import os
  11. import sys
  12. sys.path.append(os.environ['PERF_EXEC_PATH'] + \
  13. '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
  14. from Core import *
  15. from perf_trace_context import *
  16. unhandled = autodict()
  17. def trace_begin():
  18. print("trace_begin")
  19. pass
  20. def trace_end():
  21. print_unhandled()
  22. def irq__softirq_entry(event_name, context, common_cpu,
  23. common_secs, common_nsecs, common_pid, common_comm,
  24. common_callchain, vec):
  25. print_header(event_name, common_cpu, common_secs, common_nsecs,
  26. common_pid, common_comm)
  27. print_uncommon(context)
  28. print("vec=%s" % (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" %
  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. end=' ')
  49. # print trace fields not included in handler args
  50. def print_uncommon(context):
  51. print("common_preempt_count=%d, common_flags=%s, "
  52. "common_lock_depth=%d, " %
  53. (common_pc(context), trace_flag_str(common_flags(context)),
  54. common_lock_depth(context)))
  55. def print_unhandled():
  56. keys = unhandled.keys()
  57. if not keys:
  58. return
  59. print("\nunhandled events:\n")
  60. print("%-40s %10s" % ("event", "count"))
  61. print("%-40s %10s" % ("----------------------------------------",
  62. "-----------"))
  63. for event_name in keys:
  64. print("%-40s %10d\n" % (event_name, unhandled[event_name]))