^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/usr/bin/perl -w
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) # (c) 2009, Tom Zanussi <tzanussi@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # Display r/w activity for all processes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # The common_* event handler fields are the most useful fields common to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # all events. They don't necessarily correspond to the 'common_*' fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # in the status files. Those fields not available as handler params can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # be retrieved via script functions of the form get_common_*().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) use 5.010000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) use strict;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) use warnings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) use lib "./Perf-Trace-Util/lib";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) use Perf::Trace::Core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) use Perf::Trace::Util;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) my %reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) my %writes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) sub syscalls::sys_exit_read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) $common_pid, $common_comm, $common_callchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) $nr, $ret) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if ($ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) $reads{$common_pid}{bytes_read} += $ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (!defined ($reads{$common_pid}{bytes_read})) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) $reads{$common_pid}{bytes_read} = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) $reads{$common_pid}{errors}{$ret}++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) sub syscalls::sys_enter_read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) $common_pid, $common_comm, $common_callchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) $nr, $fd, $buf, $count) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) $reads{$common_pid}{bytes_requested} += $count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) $reads{$common_pid}{total_reads}++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) $reads{$common_pid}{comm} = $common_comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) sub syscalls::sys_exit_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) $common_pid, $common_comm, $common_callchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) $nr, $ret) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if ($ret <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) $writes{$common_pid}{errors}{$ret}++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^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) sub syscalls::sys_enter_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) $common_pid, $common_comm, $common_callchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) $nr, $fd, $buf, $count) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) $writes{$common_pid}{bytes_written} += $count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) $writes{$common_pid}{total_writes}++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) $writes{$common_pid}{comm} = $common_comm;
^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) sub trace_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) printf("read counts by pid:\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) printf("%6s %20s %10s %10s %10s\n", "pid", "comm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) "# reads", "bytes_requested", "bytes_read");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) "-----------", "----------", "----------");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ($reads{$a}{bytes_read} || 0) } keys %reads) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) my $comm = $reads{$pid}{comm} || "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) my $total_reads = $reads{$pid}{total_reads} || 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) my $bytes_requested = $reads{$pid}{bytes_requested} || 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) my $bytes_read = $reads{$pid}{bytes_read} || 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) printf("%6s %-20s %10s %10s %10s\n", $pid, $comm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) $total_reads, $bytes_requested, $bytes_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) printf("\nfailed reads by pid:\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) printf("%6s %20s %6s %10s\n", "pid", "comm", "error #", "# errors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) printf("%6s %20s %6s %10s\n", "------", "--------------------",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) "------", "----------");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) my @errcounts = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) foreach my $pid (keys %reads) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) foreach my $error (keys %{$reads{$pid}{errors}}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) my $comm = $reads{$pid}{comm} || "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) my $errcount = $reads{$pid}{errors}{$error} || 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) push @errcounts, [$pid, $comm, $error, $errcount];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for my $i (0 .. $#errcounts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) printf("%6d %-20s %6d %10s\n", $errcounts[$i][0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) printf("\nwrite counts by pid:\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) printf("%6s %20s %10s %10s\n", "pid", "comm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) "# writes", "bytes_written");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) printf("%6s %-20s %10s %10s\n", "------", "--------------------",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) "-----------", "----------");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ($writes{$a}{bytes_written} || 0)} keys %writes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) my $comm = $writes{$pid}{comm} || "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) my $total_writes = $writes{$pid}{total_writes} || 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) my $bytes_written = $writes{$pid}{bytes_written} || 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) printf("%6s %-20s %10s %10s\n", $pid, $comm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) $total_writes, $bytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) printf("\nfailed writes by pid:\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) printf("%6s %20s %6s %10s\n", "pid", "comm", "error #", "# errors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) printf("%6s %20s %6s %10s\n", "------", "--------------------",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) "------", "----------");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) @errcounts = ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) foreach my $pid (keys %writes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) foreach my $error (keys %{$writes{$pid}{errors}}) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) my $comm = $writes{$pid}{comm} || "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) my $errcount = $writes{$pid}{errors}{$error} || 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) push @errcounts, [$pid, $comm, $error, $errcount];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) for my $i (0 .. $#errcounts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) printf("%6d %-20s %6d %10s\n", $errcounts[$i][0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) print_unhandled();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) my %unhandled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) sub print_unhandled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if ((scalar keys %unhandled) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) print "\nunhandled events:\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) printf("%-40s %10s\n", "event", "count");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) printf("%-40s %10s\n", "----------------------------------------",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) "-----------");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) foreach my $event_name (keys %unhandled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) sub trace_unhandled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) $common_pid, $common_comm, $common_callchain) = @_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) $unhandled{$event_name}++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }