Merge lp:~percona-toolkit-dev/percona-toolkit/fix-928226 into lp:percona-toolkit/2.0

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 193
Merged at revision: 208
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-928226
Merge into: lp:percona-toolkit/2.0
Diff against target: 93 lines (+47/-7)
3 files modified
bin/pt-diskstats (+11/-3)
lib/Diskstats.pm (+11/-3)
t/lib/Diskstats.t (+25/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-928226
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+96243@code.launchpad.net

This proposal supersedes a proposal from 2012-03-06.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote : Posted in a previous version of this proposal

Overall looks good; just needs one little tweak: simplify the new _d() message like:

_d('Using qtime=0 because average_ios is 0: number_of_ios', $number_of_ios, '+ delta for ios_in_progress', $delta_for->{ios_in_progress});

(Line break it at 80 cols.) The main reason for this change is that debug messages should never interpolate vars in strings because if $foo=undef then _d("foo=$foo") will crash. _d() handles undef args, so _d('foo=', $foo) will not crash.

review: Needs Fixing
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-diskstats'
2--- bin/pt-diskstats 2012-02-03 23:25:29 +0000
3+++ bin/pt-diskstats 2012-03-06 21:15:24 +0000
4@@ -2192,9 +2192,17 @@
5 + $delta_for->{ms_spent_writing};
6
7 if ( $number_of_ios ) {
8- $extra_stats{qtime} =
9- $delta_for->{ms_weighted} / ($number_of_ios + $delta_for->{ios_in_progress})
10- - $delta_for->{ms_spent_doing_io} / $number_of_ios;
11+ my $average_ios = $number_of_ios + $delta_for->{ios_in_progress};
12+ if ( $average_ios ) {
13+ $extra_stats{qtime} = $delta_for->{ms_weighted} / $average_ios
14+ - $delta_for->{ms_spent_doing_io} / $number_of_ios;
15+ }
16+ else {
17+ PTDEBUG && _d("IOS_IN_PROGRESS is [", $delta_for->{ios_in_progress},
18+ "], and the number of ios is [", $number_of_ios,
19+ "], going to use 0 as qtime.");
20+ $extra_stats{qtime} = 0;
21+ }
22 $extra_stats{stime}
23 = $delta_for->{ms_spent_doing_io} / $number_of_ios;
24 }
25
26=== modified file 'lib/Diskstats.pm'
27--- lib/Diskstats.pm 2012-02-03 17:00:40 +0000
28+++ lib/Diskstats.pm 2012-03-06 21:15:24 +0000
29@@ -818,9 +818,17 @@
30 + $delta_for->{ms_spent_writing};
31
32 if ( $number_of_ios ) {
33- $extra_stats{qtime} =
34- $delta_for->{ms_weighted} / ($number_of_ios + $delta_for->{ios_in_progress})
35- - $delta_for->{ms_spent_doing_io} / $number_of_ios;
36+ my $average_ios = $number_of_ios + $delta_for->{ios_in_progress};
37+ if ( $average_ios ) {
38+ $extra_stats{qtime} = $delta_for->{ms_weighted} / $average_ios
39+ - $delta_for->{ms_spent_doing_io} / $number_of_ios;
40+ }
41+ else {
42+ PTDEBUG && _d("IOS_IN_PROGRESS is [", $delta_for->{ios_in_progress},
43+ "], and the number of ios is [", $number_of_ios,
44+ "], going to use 0 as qtime.");
45+ $extra_stats{qtime} = 0;
46+ }
47 $extra_stats{stime}
48 = $delta_for->{ms_spent_doing_io} / $number_of_ios;
49 }
50
51=== modified file 't/lib/Diskstats.t'
52--- t/lib/Diskstats.t 2012-02-03 18:30:21 +0000
53+++ t/lib/Diskstats.t 2012-03-06 21:15:24 +0000
54@@ -9,7 +9,7 @@
55 use strict;
56 use warnings FATAL => 'all';
57 use English qw(-no_match_vars);
58-use Test::More tests => 107;
59+use Test::More tests => 108;
60
61 use PerconaTest;
62
63@@ -449,6 +449,30 @@
64 "_calc_misc_stats works"
65 );
66
67+# Bug 928226: IOS IN PROGRESS can be negative due to kernel bugs,
68+# which can eventually cause a division by zero if it happens to
69+# be the negative of the number of ios.
70+# The tool should return zero in that case, rather than dying.
71+$deltas->{ios_in_progress} = -$deltas->{ios_requested};
72+%misc_stats = $obj->_calc_misc_stats(
73+ delta_for => $deltas,
74+ elapsed => $curr->{TS} - $prev->{TS},
75+ devs_in_group => 1,
76+ stats => { %write_stats, %read_stats },
77+);
78+
79+is_deeply(
80+ \%misc_stats,
81+ {
82+ busy => '0.6',
83+ line_ts => ' 0.0',
84+ qtime => 0,
85+ s_spent_doing_io => '28.5',
86+ stime => '0.0364741641337386',
87+ },
88+ "_calc_misc_stats works around a negative the IOS IN PROGRESS"
89+);
90+
91 $obj->clear_state();
92
93 }

Subscribers

People subscribed via source and target branches