GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / tools / perf / scripts / perl / rw-by-pid.pl
blob9db23c9daf5552d9159a093bf14381750cb71ac7
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 all processes
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 %reads;
22 my %writes;
24 sub syscalls::sys_exit_read
26 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
27 $common_pid, $common_comm,
28 $nr, $ret) = @_;
30 if ($ret > 0) {
31 $reads{$common_pid}{bytes_read} += $ret;
32 } else {
33 if (!defined ($reads{$common_pid}{bytes_read})) {
34 $reads{$common_pid}{bytes_read} = 0;
36 $reads{$common_pid}{errors}{$ret}++;
40 sub syscalls::sys_enter_read
42 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
43 $common_pid, $common_comm,
44 $nr, $fd, $buf, $count) = @_;
46 $reads{$common_pid}{bytes_requested} += $count;
47 $reads{$common_pid}{total_reads}++;
48 $reads{$common_pid}{comm} = $common_comm;
51 sub syscalls::sys_exit_write
53 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
54 $common_pid, $common_comm,
55 $nr, $ret) = @_;
57 if ($ret <= 0) {
58 $writes{$common_pid}{errors}{$ret}++;
62 sub syscalls::sys_enter_write
64 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
65 $common_pid, $common_comm,
66 $nr, $fd, $buf, $count) = @_;
68 $writes{$common_pid}{bytes_written} += $count;
69 $writes{$common_pid}{total_writes}++;
70 $writes{$common_pid}{comm} = $common_comm;
73 sub trace_end
75 printf("read counts by pid:\n\n");
77 printf("%6s %20s %10s %10s %10s\n", "pid", "comm",
78 "# reads", "bytes_requested", "bytes_read");
79 printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------",
80 "-----------", "----------", "----------");
82 foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=>
83 ($reads{$a}{bytes_read} || 0) } keys %reads) {
84 my $comm = $reads{$pid}{comm} || "";
85 my $total_reads = $reads{$pid}{total_reads} || 0;
86 my $bytes_requested = $reads{$pid}{bytes_requested} || 0;
87 my $bytes_read = $reads{$pid}{bytes_read} || 0;
89 printf("%6s %-20s %10s %10s %10s\n", $pid, $comm,
90 $total_reads, $bytes_requested, $bytes_read);
93 printf("\nfailed reads by pid:\n\n");
95 printf("%6s %20s %6s %10s\n", "pid", "comm", "error #", "# errors");
96 printf("%6s %20s %6s %10s\n", "------", "--------------------",
97 "------", "----------");
99 my @errcounts = ();
101 foreach my $pid (keys %reads) {
102 foreach my $error (keys %{$reads{$pid}{errors}}) {
103 my $comm = $reads{$pid}{comm} || "";
104 my $errcount = $reads{$pid}{errors}{$error} || 0;
105 push @errcounts, [$pid, $comm, $error, $errcount];
109 @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts;
111 for my $i (0 .. $#errcounts) {
112 printf("%6d %-20s %6d %10s\n", $errcounts[$i][0],
113 $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]);
116 printf("\nwrite counts by pid:\n\n");
118 printf("%6s %20s %10s %10s\n", "pid", "comm",
119 "# writes", "bytes_written");
120 printf("%6s %-20s %10s %10s\n", "------", "--------------------",
121 "-----------", "----------");
123 foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=>
124 ($writes{$a}{bytes_written} || 0)} keys %writes) {
125 my $comm = $writes{$pid}{comm} || "";
126 my $total_writes = $writes{$pid}{total_writes} || 0;
127 my $bytes_written = $writes{$pid}{bytes_written} || 0;
129 printf("%6s %-20s %10s %10s\n", $pid, $comm,
130 $total_writes, $bytes_written);
133 printf("\nfailed writes by pid:\n\n");
135 printf("%6s %20s %6s %10s\n", "pid", "comm", "error #", "# errors");
136 printf("%6s %20s %6s %10s\n", "------", "--------------------",
137 "------", "----------");
139 @errcounts = ();
141 foreach my $pid (keys %writes) {
142 foreach my $error (keys %{$writes{$pid}{errors}}) {
143 my $comm = $writes{$pid}{comm} || "";
144 my $errcount = $writes{$pid}{errors}{$error} || 0;
145 push @errcounts, [$pid, $comm, $error, $errcount];
149 @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts;
151 for my $i (0 .. $#errcounts) {
152 printf("%6d %-20s %6d %10s\n", $errcounts[$i][0],
153 $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]);
156 print_unhandled();
159 my %unhandled;
161 sub print_unhandled
163 if ((scalar keys %unhandled) == 0) {
164 return;
167 print "\nunhandled events:\n\n";
169 printf("%-40s %10s\n", "event", "count");
170 printf("%-40s %10s\n", "----------------------------------------",
171 "-----------");
173 foreach my $event_name (keys %unhandled) {
174 printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
178 sub trace_unhandled
180 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
181 $common_pid, $common_comm) = @_;
183 $unhandled{$event_name}++;