1765532c8SArnaldo Carvalho de Melo# perf script event handlers, generated by perf script -g python
24d161f03STom Zanussi# (c) 2010, Tom Zanussi <[email protected]>
34d161f03STom Zanussi# Licensed under the terms of the GNU GPL License version 2
44d161f03STom Zanussi#
54d161f03STom Zanussi# This script tests basic functionality such as flag and symbol
64d161f03STom Zanussi# strings, common_xxx() calls back into perf, begin, end, unhandled
74d161f03STom Zanussi# events, etc.  Basically, if this script runs successfully and
84d161f03STom Zanussi# displays expected results, Python scripting support should be ok.
94d161f03STom Zanussi
104d161f03STom Zanussiimport os
114d161f03STom Zanussiimport sys
124d161f03STom Zanussi
134d161f03STom Zanussisys.path.append(os.environ['PERF_EXEC_PATH'] + \
144d161f03STom Zanussi	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
154d161f03STom Zanussi
164d161f03STom Zanussifrom Core import *
174d161f03STom Zanussifrom perf_trace_context import *
184d161f03STom Zanussi
194d161f03STom Zanussiunhandled = autodict()
204d161f03STom Zanussi
214d161f03STom Zanussidef trace_begin():
224d161f03STom Zanussi	print "trace_begin"
234d161f03STom Zanussi	pass
244d161f03STom Zanussi
254d161f03STom Zanussidef trace_end():
264d161f03STom Zanussi        print_unhandled()
274d161f03STom Zanussi
284d161f03STom Zanussidef irq__softirq_entry(event_name, context, common_cpu,
294d161f03STom Zanussi	common_secs, common_nsecs, common_pid, common_comm,
30*0f5f5bcdSJoseph Schuchart	common_callchain, vec):
314d161f03STom Zanussi		print_header(event_name, common_cpu, common_secs, common_nsecs,
324d161f03STom Zanussi			common_pid, common_comm)
334d161f03STom Zanussi
344d161f03STom Zanussi                print_uncommon(context)
354d161f03STom Zanussi
364d161f03STom Zanussi		print "vec=%s\n" % \
374d161f03STom Zanussi		(symbol_str("irq__softirq_entry", "vec", vec)),
384d161f03STom Zanussi
394d161f03STom Zanussidef kmem__kmalloc(event_name, context, common_cpu,
404d161f03STom Zanussi	common_secs, common_nsecs, common_pid, common_comm,
41*0f5f5bcdSJoseph Schuchart	common_callchain, call_site, ptr, bytes_req, bytes_alloc,
424d161f03STom Zanussi	gfp_flags):
434d161f03STom Zanussi		print_header(event_name, common_cpu, common_secs, common_nsecs,
444d161f03STom Zanussi			common_pid, common_comm)
454d161f03STom Zanussi
464d161f03STom Zanussi                print_uncommon(context)
474d161f03STom Zanussi
484d161f03STom Zanussi		print "call_site=%u, ptr=%u, bytes_req=%u, " \
494d161f03STom Zanussi		"bytes_alloc=%u, gfp_flags=%s\n" % \
504d161f03STom Zanussi		(call_site, ptr, bytes_req, bytes_alloc,
514d161f03STom Zanussi
524d161f03STom Zanussi		flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)),
534d161f03STom Zanussi
54c0251485SPierre Tardydef trace_unhandled(event_name, context, event_fields_dict):
554d161f03STom Zanussi    try:
564d161f03STom Zanussi        unhandled[event_name] += 1
574d161f03STom Zanussi    except TypeError:
584d161f03STom Zanussi        unhandled[event_name] = 1
594d161f03STom Zanussi
604d161f03STom Zanussidef print_header(event_name, cpu, secs, nsecs, pid, comm):
614d161f03STom Zanussi	print "%-20s %5u %05u.%09u %8u %-20s " % \
624d161f03STom Zanussi	(event_name, cpu, secs, nsecs, pid, comm),
634d161f03STom Zanussi
644d161f03STom Zanussi# print trace fields not included in handler args
654d161f03STom Zanussidef print_uncommon(context):
664d161f03STom Zanussi    print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \
674d161f03STom Zanussi        % (common_pc(context), trace_flag_str(common_flags(context)), \
684d161f03STom Zanussi               common_lock_depth(context))
694d161f03STom Zanussi
704d161f03STom Zanussidef print_unhandled():
714d161f03STom Zanussi    keys = unhandled.keys()
724d161f03STom Zanussi    if not keys:
734d161f03STom Zanussi        return
744d161f03STom Zanussi
754d161f03STom Zanussi    print "\nunhandled events:\n\n",
764d161f03STom Zanussi
774d161f03STom Zanussi    print "%-40s  %10s\n" % ("event", "count"),
784d161f03STom Zanussi    print "%-40s  %10s\n" % ("----------------------------------------", \
794d161f03STom Zanussi                                 "-----------"),
804d161f03STom Zanussi
814d161f03STom Zanussi    for event_name in keys:
824d161f03STom Zanussi	print "%-40s  %10d\n" % (event_name, unhandled[event_name])
83