2 # (c) 2010, Tom Zanussi <tzanussi@gmail.com>
3 # Licensed under the terms of the GNU GPL License version 2
7 # Periodically displays system-wide r/w call activity, broken down by
8 # pid. If an [interval] arg is specified, the display will be
9 # refreshed every [interval] seconds. The default interval is 3
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
;
20 use POSIX qw
/SIGALRM SA_RESTART/;
22 my $default_interval = 3;
25 my $print_pending = 0;
32 $interval = $default_interval;
35 sub syscalls
::sys_exit_read
37 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
38 $common_pid, $common_comm,
44 $reads{$common_pid}{bytes_read
} += $ret;
46 if (!defined ($reads{$common_pid}{bytes_read
})) {
47 $reads{$common_pid}{bytes_read
} = 0;
49 $reads{$common_pid}{errors
}{$ret}++;
53 sub syscalls
::sys_enter_read
55 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
56 $common_pid, $common_comm,
57 $nr, $fd, $buf, $count) = @_;
61 $reads{$common_pid}{bytes_requested
} += $count;
62 $reads{$common_pid}{total_reads
}++;
63 $reads{$common_pid}{comm
} = $common_comm;
66 sub syscalls
::sys_exit_write
68 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
69 $common_pid, $common_comm,
75 $writes{$common_pid}{errors
}{$ret}++;
79 sub syscalls
::sys_enter_write
81 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
82 $common_pid, $common_comm,
83 $nr, $fd, $buf, $count) = @_;
87 $writes{$common_pid}{bytes_written
} += $count;
88 $writes{$common_pid}{total_writes
}++;
89 $writes{$common_pid}{comm
} = $common_comm;
94 my $sa = POSIX
::SigAction
->new(\
&set_print_pending
);
95 $sa->flags(SA_RESTART
);
97 POSIX
::sigaction
(SIGALRM
, $sa) or die "Can't set SIGALRM handler: $!\n";
109 if ($print_pending == 1) {
115 sub set_print_pending
()
129 printf("\nread counts by pid:\n\n");
131 printf("%6s %20s %10s %10s %10s\n", "pid", "comm",
132 "# reads", "bytes_req", "bytes_read");
133 printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------",
134 "----------", "----------", "----------");
136 foreach my $pid (sort { ($reads{$b}{bytes_read
} || 0) <=>
137 ($reads{$a}{bytes_read
} || 0) } keys %reads) {
138 my $comm = $reads{$pid}{comm
} || "";
139 my $total_reads = $reads{$pid}{total_reads
} || 0;
140 my $bytes_requested = $reads{$pid}{bytes_requested
} || 0;
141 my $bytes_read = $reads{$pid}{bytes_read
} || 0;
143 printf("%6s %-20s %10s %10s %10s\n", $pid, $comm,
144 $total_reads, $bytes_requested, $bytes_read);
146 if (++$count == $nlines) {
153 printf("\nwrite counts by pid:\n\n");
155 printf("%6s %20s %10s %13s\n", "pid", "comm",
156 "# writes", "bytes_written");
157 printf("%6s %-20s %10s %13s\n", "------", "--------------------",
158 "----------", "-------------");
160 foreach my $pid (sort { ($writes{$b}{bytes_written
} || 0) <=>
161 ($writes{$a}{bytes_written
} || 0)} keys %writes) {
162 my $comm = $writes{$pid}{comm
} || "";
163 my $total_writes = $writes{$pid}{total_writes
} || 0;
164 my $bytes_written = $writes{$pid}{bytes_written
} || 0;
166 printf("%6s %-20s %10s %13s\n", $pid, $comm,
167 $total_writes, $bytes_written);
169 if (++$count == $nlines) {
182 if ((scalar keys %unhandled) == 0) {
186 print "\nunhandled events:\n\n";
188 printf("%-40s %10s\n", "event", "count");
189 printf("%-40s %10s\n", "----------------------------------------",
192 foreach my $event_name (keys %unhandled) {
193 printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
199 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
200 $common_pid, $common_comm) = @_;
202 $unhandled{$event_name}++;