Input: rotary-encoder - set gpio direction for each requested gpio
[linux/fpc-iii.git] / tools / perf / scripts / perl / rw-by-file.pl
blob2a39097687b9f70dffb2fe83f4477539ff8e98b4
1 #!/usr/bin/perl -w
2 # (c) 2009, Tom Zanussi <tzanussi@gmail.com>
3 # Licensed under the terms of the GNU GPL License version 2
5 # Display r/w activity for files read/written to for a given program
7 # The common_* event handler fields are the most useful fields common to
8 # all events. They don't necessarily correspond to the 'common_*' fields
9 # in the status files. Those fields not available as handler params can
10 # be retrieved via script functions of the form get_common_*().
12 use 5.010000;
13 use strict;
14 use warnings;
16 use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
17 use lib "./Perf-Trace-Util/lib";
18 use Perf::Trace::Core;
19 use Perf::Trace::Util;
21 my $usage = "perf trace -s rw-by-file.pl <comm>\n";
23 my $for_comm = shift or die $usage;
25 my %reads;
26 my %writes;
28 sub syscalls::sys_enter_read
30 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
31 $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_;
33 if ($common_comm eq $for_comm) {
34 $reads{$fd}{bytes_requested} += $count;
35 $reads{$fd}{total_reads}++;
39 sub syscalls::sys_enter_write
41 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
42 $common_pid, $common_comm, $nr, $fd, $buf, $count) = @_;
44 if ($common_comm eq $for_comm) {
45 $writes{$fd}{bytes_written} += $count;
46 $writes{$fd}{total_writes}++;
50 sub trace_end
52 printf("file read counts for $for_comm:\n\n");
54 printf("%6s %10s %10s\n", "fd", "# reads", "bytes_requested");
55 printf("%6s %10s %10s\n", "------", "----------", "-----------");
57 foreach my $fd (sort {$reads{$b}{bytes_requested} <=>
58 $reads{$a}{bytes_requested}} keys %reads) {
59 my $total_reads = $reads{$fd}{total_reads};
60 my $bytes_requested = $reads{$fd}{bytes_requested};
61 printf("%6u %10u %10u\n", $fd, $total_reads, $bytes_requested);
64 printf("\nfile write counts for $for_comm:\n\n");
66 printf("%6s %10s %10s\n", "fd", "# writes", "bytes_written");
67 printf("%6s %10s %10s\n", "------", "----------", "-----------");
69 foreach my $fd (sort {$writes{$b}{bytes_written} <=>
70 $writes{$a}{bytes_written}} keys %writes) {
71 my $total_writes = $writes{$fd}{total_writes};
72 my $bytes_written = $writes{$fd}{bytes_written};
73 printf("%6u %10u %10u\n", $fd, $total_writes, $bytes_written);
76 print_unhandled();
79 my %unhandled;
81 sub print_unhandled
83 if ((scalar keys %unhandled) == 0) {
84 return;
87 print "\nunhandled events:\n\n";
89 printf("%-40s %10s\n", "event", "count");
90 printf("%-40s %10s\n", "----------------------------------------",
91 "-----------");
93 foreach my $event_name (keys %unhandled) {
94 printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
98 sub trace_unhandled
100 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
101 $common_pid, $common_comm) = @_;
103 $unhandled{$event_name}++;