blob: d2c22954800d56698312a4beececb5c001ea6232 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001# 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
David Brazdil0f672f62019-12-10 10:32:29 +000010from __future__ import print_function
11
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000012import os
13import sys
14
15sys.path.append(os.environ['PERF_EXEC_PATH'] + \
16 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
17
18from Core import *
19from perf_trace_context import *
20
21unhandled = autodict()
22
23def trace_begin():
David Brazdil0f672f62019-12-10 10:32:29 +000024 print("trace_begin")
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025 pass
26
27def trace_end():
David Brazdil0f672f62019-12-10 10:32:29 +000028 print_unhandled()
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000029
30def irq__softirq_entry(event_name, context, common_cpu,
David Brazdil0f672f62019-12-10 10:32:29 +000031 common_secs, common_nsecs, common_pid, common_comm,
32 common_callchain, vec):
33 print_header(event_name, common_cpu, common_secs, common_nsecs,
34 common_pid, common_comm)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000035
David Brazdil0f672f62019-12-10 10:32:29 +000036 print_uncommon(context)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000037
David Brazdil0f672f62019-12-10 10:32:29 +000038 print("vec=%s" % (symbol_str("irq__softirq_entry", "vec", vec)))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039
40def kmem__kmalloc(event_name, context, common_cpu,
David Brazdil0f672f62019-12-10 10:32:29 +000041 common_secs, common_nsecs, common_pid, common_comm,
42 common_callchain, call_site, ptr, bytes_req, bytes_alloc,
43 gfp_flags):
44 print_header(event_name, common_cpu, common_secs, common_nsecs,
45 common_pid, common_comm)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000046
David Brazdil0f672f62019-12-10 10:32:29 +000047 print_uncommon(context)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000048
David Brazdil0f672f62019-12-10 10:32:29 +000049 print("call_site=%u, ptr=%u, bytes_req=%u, "
50 "bytes_alloc=%u, gfp_flags=%s" %
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000051 (call_site, ptr, bytes_req, bytes_alloc,
David Brazdil0f672f62019-12-10 10:32:29 +000052 flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000053
54def trace_unhandled(event_name, context, event_fields_dict):
David Brazdil0f672f62019-12-10 10:32:29 +000055 try:
56 unhandled[event_name] += 1
57 except TypeError:
58 unhandled[event_name] = 1
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000059
60def print_header(event_name, cpu, secs, nsecs, pid, comm):
David Brazdil0f672f62019-12-10 10:32:29 +000061 print("%-20s %5u %05u.%09u %8u %-20s " %
62 (event_name, cpu, secs, nsecs, pid, comm),
63 end=' ')
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000064
65# print trace fields not included in handler args
66def print_uncommon(context):
David Brazdil0f672f62019-12-10 10:32:29 +000067 print("common_preempt_count=%d, common_flags=%s, "
68 "common_lock_depth=%d, " %
69 (common_pc(context), trace_flag_str(common_flags(context)),
70 common_lock_depth(context)))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000071
72def print_unhandled():
David Brazdil0f672f62019-12-10 10:32:29 +000073 keys = unhandled.keys()
74 if not keys:
75 return
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000076
David Brazdil0f672f62019-12-10 10:32:29 +000077 print("\nunhandled events:\n")
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000078
David Brazdil0f672f62019-12-10 10:32:29 +000079 print("%-40s %10s" % ("event", "count"))
80 print("%-40s %10s" % ("----------------------------------------",
81 "-----------"))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000082
David Brazdil0f672f62019-12-10 10:32:29 +000083 for event_name in keys:
84 print("%-40s %10d\n" % (event_name, unhandled[event_name]))