diff options
Diffstat (limited to 'tools/perf/scripts/perl/rwtop.pl')
-rw-r--r-- | tools/perf/scripts/perl/rwtop.pl | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/tools/perf/scripts/perl/rwtop.pl b/tools/perf/scripts/perl/rwtop.pl new file mode 100644 index 000000000000..ec2ab49a6f25 --- /dev/null +++ b/tools/perf/scripts/perl/rwtop.pl | |||
@@ -0,0 +1,177 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
3 | # Licensed under the terms of the GNU GPL License version 2 | ||
4 | |||
5 | # read/write top | ||
6 | # | ||
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 | ||
10 | # seconds. | ||
11 | |||
12 | use 5.010000; | ||
13 | use strict; | ||
14 | use warnings; | ||
15 | |||
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 | |||
21 | my $default_interval = 3; | ||
22 | my $nlines = 20; | ||
23 | my $print_thread; | ||
24 | |||
25 | my %reads; | ||
26 | my %writes; | ||
27 | |||
28 | my $interval = shift; | ||
29 | if (!$interval) { | ||
30 | $interval = $default_interval; | ||
31 | } | ||
32 | |||
33 | sub syscalls::sys_exit_read | ||
34 | { | ||
35 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
36 | $common_pid, $common_comm, | ||
37 | $nr, $ret) = @_; | ||
38 | |||
39 | if ($ret > 0) { | ||
40 | $reads{$common_pid}{bytes_read} += $ret; | ||
41 | } else { | ||
42 | if (!defined ($reads{$common_pid}{bytes_read})) { | ||
43 | $reads{$common_pid}{bytes_read} = 0; | ||
44 | } | ||
45 | $reads{$common_pid}{errors}{$ret}++; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | sub syscalls::sys_enter_read | ||
50 | { | ||
51 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
52 | $common_pid, $common_comm, | ||
53 | $nr, $fd, $buf, $count) = @_; | ||
54 | |||
55 | $reads{$common_pid}{bytes_requested} += $count; | ||
56 | $reads{$common_pid}{total_reads}++; | ||
57 | $reads{$common_pid}{comm} = $common_comm; | ||
58 | } | ||
59 | |||
60 | sub syscalls::sys_exit_write | ||
61 | { | ||
62 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
63 | $common_pid, $common_comm, | ||
64 | $nr, $ret) = @_; | ||
65 | |||
66 | if ($ret <= 0) { | ||
67 | $writes{$common_pid}{errors}{$ret}++; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | sub syscalls::sys_enter_write | ||
72 | { | ||
73 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
74 | $common_pid, $common_comm, | ||
75 | $nr, $fd, $buf, $count) = @_; | ||
76 | |||
77 | $writes{$common_pid}{bytes_written} += $count; | ||
78 | $writes{$common_pid}{total_writes}++; | ||
79 | $writes{$common_pid}{comm} = $common_comm; | ||
80 | } | ||
81 | |||
82 | sub trace_begin | ||
83 | { | ||
84 | $SIG{ALRM} = \&print_totals; | ||
85 | alarm 1; | ||
86 | } | ||
87 | |||
88 | sub trace_end | ||
89 | { | ||
90 | print_unhandled(); | ||
91 | print_totals(); | ||
92 | } | ||
93 | |||
94 | sub print_totals | ||
95 | { | ||
96 | my $count; | ||
97 | |||
98 | $count = 0; | ||
99 | |||
100 | clear_term(); | ||
101 | |||
102 | printf("\nread counts by pid:\n\n"); | ||
103 | |||
104 | printf("%6s %20s %10s %10s %10s\n", "pid", "comm", | ||
105 | "# reads", "bytes_req", "bytes_read"); | ||
106 | printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", | ||
107 | "----------", "----------", "----------"); | ||
108 | |||
109 | foreach my $pid (sort {$reads{$b}{bytes_read} <=> | ||
110 | $reads{$a}{bytes_read}} keys %reads) { | ||
111 | my $comm = $reads{$pid}{comm}; | ||
112 | my $total_reads = $reads{$pid}{total_reads}; | ||
113 | my $bytes_requested = $reads{$pid}{bytes_requested}; | ||
114 | my $bytes_read = $reads{$pid}{bytes_read}; | ||
115 | |||
116 | printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, | ||
117 | $total_reads, $bytes_requested, $bytes_read); | ||
118 | |||
119 | if (++$count == $nlines) { | ||
120 | last; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | $count = 0; | ||
125 | |||
126 | printf("\nwrite counts by pid:\n\n"); | ||
127 | |||
128 | printf("%6s %20s %10s %13s\n", "pid", "comm", | ||
129 | "# writes", "bytes_written"); | ||
130 | printf("%6s %-20s %10s %13s\n", "------", "--------------------", | ||
131 | "----------", "-------------"); | ||
132 | |||
133 | foreach my $pid (sort {$writes{$b}{bytes_written} <=> | ||
134 | $writes{$a}{bytes_written}} keys %writes) { | ||
135 | my $comm = $writes{$pid}{comm}; | ||
136 | my $total_writes = $writes{$pid}{total_writes}; | ||
137 | my $bytes_written = $writes{$pid}{bytes_written}; | ||
138 | |||
139 | printf("%6s %-20s %10s %13s\n", $pid, $comm, | ||
140 | $total_writes, $bytes_written); | ||
141 | |||
142 | if (++$count == $nlines) { | ||
143 | last; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | %reads = (); | ||
148 | %writes = (); | ||
149 | alarm $interval; | ||
150 | } | ||
151 | |||
152 | my %unhandled; | ||
153 | |||
154 | sub print_unhandled | ||
155 | { | ||
156 | if ((scalar keys %unhandled) == 0) { | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | print "\nunhandled events:\n\n"; | ||
161 | |||
162 | printf("%-40s %10s\n", "event", "count"); | ||
163 | printf("%-40s %10s\n", "----------------------------------------", | ||
164 | "-----------"); | ||
165 | |||
166 | foreach my $event_name (keys %unhandled) { | ||
167 | printf("%-40s %10d\n", $event_name, $unhandled{$event_name}); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | sub trace_unhandled | ||
172 | { | ||
173 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
174 | $common_pid, $common_comm) = @_; | ||
175 | |||
176 | $unhandled{$event_name}++; | ||
177 | } | ||