diff options
author | Tom Zanussi <tzanussi@gmail.com> | 2010-05-10 00:46:54 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-05-10 18:50:56 -0400 |
commit | e88a4bfbcda440b1c6b9d5a31a554a6ad9686182 (patch) | |
tree | ba73fe7a89847aadf2584e1a537ee257a56ac564 /tools/perf | |
parent | 6922c3d772711239e75ddaea760e6b0535e7e7a6 (diff) |
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>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/scripts/perl/rwtop.pl | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/tools/perf/scripts/perl/rwtop.pl b/tools/perf/scripts/perl/rwtop.pl index ec2ab49a6f25..4bb3ecd33472 100644 --- a/tools/perf/scripts/perl/rwtop.pl +++ b/tools/perf/scripts/perl/rwtop.pl | |||
@@ -21,6 +21,7 @@ use Perf::Trace::Util; | |||
21 | my $default_interval = 3; | 21 | my $default_interval = 3; |
22 | my $nlines = 20; | 22 | my $nlines = 20; |
23 | my $print_thread; | 23 | my $print_thread; |
24 | my $print_pending = 0; | ||
24 | 25 | ||
25 | my %reads; | 26 | my %reads; |
26 | my %writes; | 27 | my %writes; |
@@ -36,6 +37,8 @@ sub syscalls::sys_exit_read | |||
36 | $common_pid, $common_comm, | 37 | $common_pid, $common_comm, |
37 | $nr, $ret) = @_; | 38 | $nr, $ret) = @_; |
38 | 39 | ||
40 | print_check(); | ||
41 | |||
39 | if ($ret > 0) { | 42 | if ($ret > 0) { |
40 | $reads{$common_pid}{bytes_read} += $ret; | 43 | $reads{$common_pid}{bytes_read} += $ret; |
41 | } else { | 44 | } else { |
@@ -52,6 +55,8 @@ sub syscalls::sys_enter_read | |||
52 | $common_pid, $common_comm, | 55 | $common_pid, $common_comm, |
53 | $nr, $fd, $buf, $count) = @_; | 56 | $nr, $fd, $buf, $count) = @_; |
54 | 57 | ||
58 | print_check(); | ||
59 | |||
55 | $reads{$common_pid}{bytes_requested} += $count; | 60 | $reads{$common_pid}{bytes_requested} += $count; |
56 | $reads{$common_pid}{total_reads}++; | 61 | $reads{$common_pid}{total_reads}++; |
57 | $reads{$common_pid}{comm} = $common_comm; | 62 | $reads{$common_pid}{comm} = $common_comm; |
@@ -63,6 +68,8 @@ sub syscalls::sys_exit_write | |||
63 | $common_pid, $common_comm, | 68 | $common_pid, $common_comm, |
64 | $nr, $ret) = @_; | 69 | $nr, $ret) = @_; |
65 | 70 | ||
71 | print_check(); | ||
72 | |||
66 | if ($ret <= 0) { | 73 | if ($ret <= 0) { |
67 | $writes{$common_pid}{errors}{$ret}++; | 74 | $writes{$common_pid}{errors}{$ret}++; |
68 | } | 75 | } |
@@ -74,6 +81,8 @@ sub syscalls::sys_enter_write | |||
74 | $common_pid, $common_comm, | 81 | $common_pid, $common_comm, |
75 | $nr, $fd, $buf, $count) = @_; | 82 | $nr, $fd, $buf, $count) = @_; |
76 | 83 | ||
84 | print_check(); | ||
85 | |||
77 | $writes{$common_pid}{bytes_written} += $count; | 86 | $writes{$common_pid}{bytes_written} += $count; |
78 | $writes{$common_pid}{total_writes}++; | 87 | $writes{$common_pid}{total_writes}++; |
79 | $writes{$common_pid}{comm} = $common_comm; | 88 | $writes{$common_pid}{comm} = $common_comm; |
@@ -81,7 +90,7 @@ sub syscalls::sys_enter_write | |||
81 | 90 | ||
82 | sub trace_begin | 91 | sub trace_begin |
83 | { | 92 | { |
84 | $SIG{ALRM} = \&print_totals; | 93 | $SIG{ALRM} = \&set_print_pending; |
85 | alarm 1; | 94 | alarm 1; |
86 | } | 95 | } |
87 | 96 | ||
@@ -91,6 +100,20 @@ sub trace_end | |||
91 | print_totals(); | 100 | print_totals(); |
92 | } | 101 | } |
93 | 102 | ||
103 | sub print_check() | ||
104 | { | ||
105 | if ($print_pending == 1) { | ||
106 | $print_pending = 0; | ||
107 | print_totals(); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | sub set_print_pending() | ||
112 | { | ||
113 | $print_pending = 1; | ||
114 | alarm $interval; | ||
115 | } | ||
116 | |||
94 | sub print_totals | 117 | sub print_totals |
95 | { | 118 | { |
96 | my $count; | 119 | my $count; |
@@ -106,12 +129,12 @@ sub print_totals | |||
106 | printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", | 129 | printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", |
107 | "----------", "----------", "----------"); | 130 | "----------", "----------", "----------"); |
108 | 131 | ||
109 | foreach my $pid (sort {$reads{$b}{bytes_read} <=> | 132 | foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=> |
110 | $reads{$a}{bytes_read}} keys %reads) { | 133 | ($reads{$a}{bytes_read} || 0) } keys %reads) { |
111 | my $comm = $reads{$pid}{comm}; | 134 | my $comm = $reads{$pid}{comm} || ""; |
112 | my $total_reads = $reads{$pid}{total_reads}; | 135 | my $total_reads = $reads{$pid}{total_reads} || 0; |
113 | my $bytes_requested = $reads{$pid}{bytes_requested}; | 136 | my $bytes_requested = $reads{$pid}{bytes_requested} || 0; |
114 | my $bytes_read = $reads{$pid}{bytes_read}; | 137 | my $bytes_read = $reads{$pid}{bytes_read} || 0; |
115 | 138 | ||
116 | printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, | 139 | printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, |
117 | $total_reads, $bytes_requested, $bytes_read); | 140 | $total_reads, $bytes_requested, $bytes_read); |
@@ -130,11 +153,11 @@ sub print_totals | |||
130 | printf("%6s %-20s %10s %13s\n", "------", "--------------------", | 153 | printf("%6s %-20s %10s %13s\n", "------", "--------------------", |
131 | "----------", "-------------"); | 154 | "----------", "-------------"); |
132 | 155 | ||
133 | foreach my $pid (sort {$writes{$b}{bytes_written} <=> | 156 | foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=> |
134 | $writes{$a}{bytes_written}} keys %writes) { | 157 | ($writes{$a}{bytes_written} || 0)} keys %writes) { |
135 | my $comm = $writes{$pid}{comm}; | 158 | my $comm = $writes{$pid}{comm} || ""; |
136 | my $total_writes = $writes{$pid}{total_writes}; | 159 | my $total_writes = $writes{$pid}{total_writes} || 0; |
137 | my $bytes_written = $writes{$pid}{bytes_written}; | 160 | my $bytes_written = $writes{$pid}{bytes_written} || 0; |
138 | 161 | ||
139 | printf("%6s %-20s %10s %13s\n", $pid, $comm, | 162 | printf("%6s %-20s %10s %13s\n", $pid, $comm, |
140 | $total_writes, $bytes_written); | 163 | $total_writes, $bytes_written); |
@@ -146,7 +169,6 @@ sub print_totals | |||
146 | 169 | ||
147 | %reads = (); | 170 | %reads = (); |
148 | %writes = (); | 171 | %writes = (); |
149 | alarm $interval; | ||
150 | } | 172 | } |
151 | 173 | ||
152 | my %unhandled; | 174 | my %unhandled; |