0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 use 5.010000;
0013 use strict;
0014 use warnings;
0015
0016 use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
0017 use lib "./Perf-Trace-Util/lib";
0018 use Perf::Trace::Core;
0019 use Perf::Trace::Util;
0020
0021 my $usage = "perf script -s rw-by-file.pl <comm>\n";
0022
0023 my $for_comm = shift or die $usage;
0024
0025 my %reads;
0026 my %writes;
0027
0028 sub syscalls::sys_enter_read
0029 {
0030 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
0031 $common_pid, $common_comm, $common_callchain, $nr, $fd, $buf, $count) = @_;
0032
0033 if ($common_comm eq $for_comm) {
0034 $reads{$fd}{bytes_requested} += $count;
0035 $reads{$fd}{total_reads}++;
0036 }
0037 }
0038
0039 sub syscalls::sys_enter_write
0040 {
0041 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
0042 $common_pid, $common_comm, $common_callchain, $nr, $fd, $buf, $count) = @_;
0043
0044 if ($common_comm eq $for_comm) {
0045 $writes{$fd}{bytes_written} += $count;
0046 $writes{$fd}{total_writes}++;
0047 }
0048 }
0049
0050 sub trace_end
0051 {
0052 printf("file read counts for $for_comm:\n\n");
0053
0054 printf("%6s %10s %10s\n", "fd", "# reads", "bytes_requested");
0055 printf("%6s %10s %10s\n", "------", "----------", "-----------");
0056
0057 foreach my $fd (sort {$reads{$b}{bytes_requested} <=>
0058 $reads{$a}{bytes_requested}} keys %reads) {
0059 my $total_reads = $reads{$fd}{total_reads};
0060 my $bytes_requested = $reads{$fd}{bytes_requested};
0061 printf("%6u %10u %10u\n", $fd, $total_reads, $bytes_requested);
0062 }
0063
0064 printf("\nfile write counts for $for_comm:\n\n");
0065
0066 printf("%6s %10s %10s\n", "fd", "# writes", "bytes_written");
0067 printf("%6s %10s %10s\n", "------", "----------", "-----------");
0068
0069 foreach my $fd (sort {$writes{$b}{bytes_written} <=>
0070 $writes{$a}{bytes_written}} keys %writes) {
0071 my $total_writes = $writes{$fd}{total_writes};
0072 my $bytes_written = $writes{$fd}{bytes_written};
0073 printf("%6u %10u %10u\n", $fd, $total_writes, $bytes_written);
0074 }
0075
0076 print_unhandled();
0077 }
0078
0079 my %unhandled;
0080
0081 sub print_unhandled
0082 {
0083 if ((scalar keys %unhandled) == 0) {
0084 return;
0085 }
0086
0087 print "\nunhandled events:\n\n";
0088
0089 printf("%-40s %10s\n", "event", "count");
0090 printf("%-40s %10s\n", "----------------------------------------",
0091 "-----------");
0092
0093 foreach my $event_name (keys %unhandled) {
0094 printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
0095 }
0096 }
0097
0098 sub trace_unhandled
0099 {
0100 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
0101 $common_pid, $common_comm, $common_callchain) = @_;
0102
0103 $unhandled{$event_name}++;
0104 }
0105
0106