Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf/trace/scripting: rwtop script cleanup

A couple of fixes for the rwtop script:

- printing the totals and clearing the hashes in the signal handler
eventually leads to various random and serious problems when running
the rwtop script continuously. Moving the print_totals() calls to
the event handlers solves that problem, and the event handlers are
invoked frequently enough that it doesn't affect the timeliness of
the output.

- Fix nuisance 'use of uninitialized value' warnings

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Message-Id: <1273466820-9330-4-git-send-email-tzanussi@gmail.com>
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Tom Zanussi and committed by
Arnaldo Carvalho de Melo
e88a4bfb 6922c3d7

+35 -13
+35 -13
tools/perf/scripts/perl/rwtop.pl
··· 21 21 my $default_interval = 3; 22 22 my $nlines = 20; 23 23 my $print_thread; 24 + my $print_pending = 0; 24 25 25 26 my %reads; 26 27 my %writes; ··· 36 35 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, 37 36 $common_pid, $common_comm, 38 37 $nr, $ret) = @_; 38 + 39 + print_check(); 39 40 40 41 if ($ret > 0) { 41 42 $reads{$common_pid}{bytes_read} += $ret; ··· 55 52 $common_pid, $common_comm, 56 53 $nr, $fd, $buf, $count) = @_; 57 54 55 + print_check(); 56 + 58 57 $reads{$common_pid}{bytes_requested} += $count; 59 58 $reads{$common_pid}{total_reads}++; 60 59 $reads{$common_pid}{comm} = $common_comm; ··· 67 62 my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, 68 63 $common_pid, $common_comm, 69 64 $nr, $ret) = @_; 65 + 66 + print_check(); 70 67 71 68 if ($ret <= 0) { 72 69 $writes{$common_pid}{errors}{$ret}++; ··· 81 74 $common_pid, $common_comm, 82 75 $nr, $fd, $buf, $count) = @_; 83 76 77 + print_check(); 78 + 84 79 $writes{$common_pid}{bytes_written} += $count; 85 80 $writes{$common_pid}{total_writes}++; 86 81 $writes{$common_pid}{comm} = $common_comm; ··· 90 81 91 82 sub trace_begin 92 83 { 93 - $SIG{ALRM} = \&print_totals; 84 + $SIG{ALRM} = \&set_print_pending; 94 85 alarm 1; 95 86 } 96 87 ··· 98 89 { 99 90 print_unhandled(); 100 91 print_totals(); 92 + } 93 + 94 + sub print_check() 95 + { 96 + if ($print_pending == 1) { 97 + $print_pending = 0; 98 + print_totals(); 99 + } 100 + } 101 + 102 + sub set_print_pending() 103 + { 104 + $print_pending = 1; 105 + alarm $interval; 101 106 } 102 107 103 108 sub print_totals ··· 129 106 printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", 130 107 "----------", "----------", "----------"); 131 108 132 - foreach my $pid (sort {$reads{$b}{bytes_read} <=> 133 - $reads{$a}{bytes_read}} keys %reads) { 134 - my $comm = $reads{$pid}{comm}; 135 - my $total_reads = $reads{$pid}{total_reads}; 136 - my $bytes_requested = $reads{$pid}{bytes_requested}; 137 - my $bytes_read = $reads{$pid}{bytes_read}; 109 + foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=> 110 + ($reads{$a}{bytes_read} || 0) } keys %reads) { 111 + my $comm = $reads{$pid}{comm} || ""; 112 + my $total_reads = $reads{$pid}{total_reads} || 0; 113 + my $bytes_requested = $reads{$pid}{bytes_requested} || 0; 114 + my $bytes_read = $reads{$pid}{bytes_read} || 0; 138 115 139 116 printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, 140 117 $total_reads, $bytes_requested, $bytes_read); ··· 153 130 printf("%6s %-20s %10s %13s\n", "------", "--------------------", 154 131 "----------", "-------------"); 155 132 156 - foreach my $pid (sort {$writes{$b}{bytes_written} <=> 157 - $writes{$a}{bytes_written}} keys %writes) { 158 - my $comm = $writes{$pid}{comm}; 159 - my $total_writes = $writes{$pid}{total_writes}; 160 - my $bytes_written = $writes{$pid}{bytes_written}; 133 + foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=> 134 + ($writes{$a}{bytes_written} || 0)} keys %writes) { 135 + my $comm = $writes{$pid}{comm} || ""; 136 + my $total_writes = $writes{$pid}{total_writes} || 0; 137 + my $bytes_written = $writes{$pid}{bytes_written} || 0; 161 138 162 139 printf("%6s %-20s %10s %13s\n", $pid, $comm, 163 140 $total_writes, $bytes_written); ··· 169 146 170 147 %reads = (); 171 148 %writes = (); 172 - alarm $interval; 173 149 } 174 150 175 151 my %unhandled;