1# perf script event handlers, generated by perf script -g python
2# (c) 2010, Tom Zanussi <[email protected]>
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
10import os
11import sys
12
13sys.path.append(os.environ['PERF_EXEC_PATH'] + \
14	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
15
16from Core import *
17from perf_trace_context import *
18
19unhandled = autodict()
20
21def trace_begin():
22	print "trace_begin"
23	pass
24
25def trace_end():
26	print_unhandled()
27
28def irq__softirq_entry(event_name, context, common_cpu,
29		       common_secs, common_nsecs, common_pid, common_comm,
30		       common_callchain, vec):
31	print_header(event_name, common_cpu, common_secs, common_nsecs,
32		common_pid, common_comm)
33
34	print_uncommon(context)
35
36	print "vec=%s\n" % (symbol_str("irq__softirq_entry", "vec", vec)),
37
38def kmem__kmalloc(event_name, context, common_cpu,
39		  common_secs, common_nsecs, common_pid, common_comm,
40		  common_callchain, call_site, ptr, bytes_req, bytes_alloc,
41		  gfp_flags):
42	print_header(event_name, common_cpu, common_secs, common_nsecs,
43		common_pid, common_comm)
44
45	print_uncommon(context)
46
47	print "call_site=%u, ptr=%u, bytes_req=%u, " \
48		"bytes_alloc=%u, gfp_flags=%s\n" % \
49		(call_site, ptr, bytes_req, bytes_alloc,
50		flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)),
51
52def trace_unhandled(event_name, context, event_fields_dict):
53	try:
54		unhandled[event_name] += 1
55	except TypeError:
56		unhandled[event_name] = 1
57
58def print_header(event_name, cpu, secs, nsecs, pid, comm):
59	print "%-20s %5u %05u.%09u %8u %-20s " % \
60		(event_name, cpu, secs, nsecs, pid, comm),
61
62# print trace fields not included in handler args
63def print_uncommon(context):
64	print "common_preempt_count=%d, common_flags=%s, " \
65		"common_lock_depth=%d, " % \
66		(common_pc(context), trace_flag_str(common_flags(context)),
67		common_lock_depth(context))
68
69def print_unhandled():
70	keys = unhandled.keys()
71	if not keys:
72		return
73
74	print "\nunhandled events:\n\n",
75
76	print "%-40s  %10s\n" % ("event", "count"),
77	print "%-40s  %10s\n" % ("----------------------------------------", \
78				"-----------"),
79
80	for event_name in keys:
81		print "%-40s  %10d\n" % (event_name, unhandled[event_name])
82