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