1e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# perf script event handlers, generated by perf script -g perl
2e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# (c) 2009, Tom Zanussi <tzanussi@gmail.com>
3e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# Licensed under the terms of the GNU GPL License version 2
4e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
5e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# This script tests basic functionality such as flag and symbol
6e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# strings, common_xxx() calls back into perf, begin, end, unhandled
7e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# events, etc.  Basically, if this script runs successfully and
8e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# displays expected results, perl scripting support should be ok.
9e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
10e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chenguse lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
11e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chenguse lib "./Perf-Trace-Util/lib";
12e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chenguse Perf::Trace::Core;
13e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chenguse Perf::Trace::Context;
14e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chenguse Perf::Trace::Util;
15e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
16e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub trace_begin
17e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
18e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    print "trace_begin\n";
19e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
20e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
21e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub trace_end
22e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
23e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    print "trace_end\n";
24e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
25e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    print_unhandled();
26e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
27e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
28e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub irq::softirq_entry
29e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
30e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
31e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	    $common_pid, $common_comm,
32e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	    $vec) = @_;
33e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
34e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	print_header($event_name, $common_cpu, $common_secs, $common_nsecs,
35e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng		     $common_pid, $common_comm);
36e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
37e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	print_uncommon($context);
38e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
39e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	printf("vec=%s\n",
40e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	       symbol_str("irq::softirq_entry", "vec", $vec));
41e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
42e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
43e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub kmem::kmalloc
44e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
45e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
46e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	    $common_pid, $common_comm,
47e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	    $call_site, $ptr, $bytes_req, $bytes_alloc,
48e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	    $gfp_flags) = @_;
49e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
50e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	print_header($event_name, $common_cpu, $common_secs, $common_nsecs,
51e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng		     $common_pid, $common_comm);
52e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
53e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	print_uncommon($context);
54e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
55e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	printf("call_site=%p, ptr=%p, bytes_req=%u, bytes_alloc=%u, ".
56e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	       "gfp_flags=%s\n",
57e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	       $call_site, $ptr, $bytes_req, $bytes_alloc,
58e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
59e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	       flag_str("kmem::kmalloc", "gfp_flags", $gfp_flags));
60e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
61e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
62e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng# print trace fields not included in handler args
63e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub print_uncommon
64e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
65e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    my ($context) = @_;
66e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
67e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    printf("common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, ",
68e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	   common_pc($context), trace_flag_str(common_flags($context)),
69e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	   common_lock_depth($context));
70e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
71e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
72e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
73e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengmy %unhandled;
74e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
75e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub print_unhandled
76e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
77e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    if ((scalar keys %unhandled) == 0) {
78e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	return;
79e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    }
80e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
81e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    print "\nunhandled events:\n\n";
82e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
83e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    printf("%-40s  %10s\n", "event", "count");
84e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    printf("%-40s  %10s\n", "----------------------------------------",
85e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	   "-----------");
86e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
87e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    foreach my $event_name (keys %unhandled) {
88e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	printf("%-40s  %10d\n", $event_name, $unhandled{$event_name});
89e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    }
90e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
91e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
92e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub trace_unhandled
93e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
94e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
95e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	$common_pid, $common_comm) = @_;
96e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
97e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng    $unhandled{$event_name}++;
98e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
99e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
100e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengsub print_header
101e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{
102e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	my ($event_name, $cpu, $secs, $nsecs, $pid, $comm) = @_;
103e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng
104e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	printf("%-20s %5u %05u.%09u %8u %-20s ",
105e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng	       $event_name, $cpu, $secs, $nsecs, $pid, $comm);
106e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng}
107