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