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