diff --git a/bin/pt-diskstats b/bin/pt-diskstats index 70837d06..1db7ae75 100755 --- a/bin/pt-diskstats +++ b/bin/pt-diskstats @@ -1306,8 +1306,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-fk-error-logger b/bin/pt-fk-error-logger index 17ac9b46..fc61ecbe 100755 --- a/bin/pt-fk-error-logger +++ b/bin/pt-fk-error-logger @@ -2328,8 +2328,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index 25c10591..743967a7 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -3967,8 +3967,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-index-usage b/bin/pt-index-usage index 35393b3c..1c10fc35 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -3530,8 +3530,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } @@ -4918,11 +4918,10 @@ sub new { last_reported => $args{start}, fraction => 0, # How complete the job is callback => sub { - my ($fraction, $elapsed, $remaining, $eta) = @_; + my ($fraction, $elapsed, $remaining) = @_; printf STDERR "$name: %3d%% %s remain\n", $fraction * 100, - Transformers::secs_to_time($remaining), - Transformers::ts($eta); + Transformers::secs_to_time($remaining); }, %args, }; diff --git a/bin/pt-kill b/bin/pt-kill index 7cdee6e8..87fd59c7 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -2589,8 +2589,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index f2c2308a..38f78c29 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -3591,11 +3591,10 @@ sub new { last_reported => $args{start}, fraction => 0, # How complete the job is callback => sub { - my ($fraction, $elapsed, $remaining, $eta) = @_; + my ($fraction, $elapsed, $remaining) = @_; printf STDERR "$name: %3d%% %s remain\n", $fraction * 100, - Transformers::secs_to_time($remaining), - Transformers::ts($eta); + Transformers::secs_to_time($remaining); }, %args, }; @@ -6124,8 +6123,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-query-digest b/bin/pt-query-digest index bef1a88b..c8fb121a 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -2555,8 +2555,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } @@ -6674,9 +6674,9 @@ sub BUILDARGS { report_all => $o->get('report-all'), report_histogram => $o->get('report-histogram'), }, - num_format => "# %-${label_width}s %3s %7s %7s %7s %7s %7s %7s %7s", - bool_format => "# %-${label_width}s %3d%% yes, %3d%% no", - string_format => "# %-${label_width}s %s", + num_format => '# %1$-'.$label_width.'s %2$3s %3$7s %4$7s %5$7s %6$7s %7$7s %8$7s %9$7s', + bool_format => '# %1$-'.$label_width.'s %2$3d%% yes, %3$3d%% no', + string_format => '# %1$-'.$label_width.'s %2$s', hidden_attrib => { # Don't sort/print these attribs in the reports. arg => 1, # They're usually handled specially, or not fingerprint => 1, # printed at all. @@ -7139,7 +7139,11 @@ sub event_report { $val->{checksum}, $val->{pos_in_log}, ); - $line .= ('_' x (LINE_LENGTH - length($line) + $self->label_width() - 12)); + my $underscores = LINE_LENGTH - length($line) + $self->label_width() - 12; + if ( $underscores < 0 ) { + $underscores = 0; + } + $line .= ('_' x $underscores); push @result, $line; if ( $val->{reason} ) { @@ -11112,11 +11116,10 @@ sub new { last_reported => $args{start}, fraction => 0, # How complete the job is callback => sub { - my ($fraction, $elapsed, $remaining, $eta) = @_; + my ($fraction, $elapsed, $remaining) = @_; printf STDERR "$name: %3d%% %s remain\n", $fraction * 100, - Transformers::secs_to_time($remaining), - Transformers::ts($eta); + Transformers::secs_to_time($remaining); }, %args, }; diff --git a/bin/pt-slave-delay b/bin/pt-slave-delay index 2373c196..d2185f44 100755 --- a/bin/pt-slave-delay +++ b/bin/pt-slave-delay @@ -2582,8 +2582,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-slave-find b/bin/pt-slave-find index c2b09f46..777afa71 100755 --- a/bin/pt-slave-find +++ b/bin/pt-slave-find @@ -3455,8 +3455,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 770b2033..8623f9e5 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -7930,8 +7930,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } @@ -8179,11 +8179,10 @@ sub new { last_reported => $args{start}, fraction => 0, # How complete the job is callback => sub { - my ($fraction, $elapsed, $remaining, $eta) = @_; + my ($fraction, $elapsed, $remaining) = @_; printf STDERR "$name: %3d%% %s remain\n", $fraction * 100, - Transformers::secs_to_time($remaining), - Transformers::ts($eta); + Transformers::secs_to_time($remaining); }, %args, }; diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 0c663241..58075412 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -8093,8 +8093,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } diff --git a/bin/pt-table-usage b/bin/pt-table-usage index ea492642..826afdae 100755 --- a/bin/pt-table-usage +++ b/bin/pt-table-usage @@ -2443,24 +2443,26 @@ use Time::Local qw(timegm timelocal); use Digest::MD5 qw(md5_hex); use B qw(); -require Exporter; -our @ISA = qw(Exporter); -our %EXPORT_TAGS = (); -our @EXPORT = (); -our @EXPORT_OK = qw( - micro_t - percentage_of - secs_to_time - time_to_secs - shorten - ts - parse_timestamp - unix_timestamp - any_unix_timestamp - make_checksum - crc32 - encode_json -); +BEGIN { + require Exporter; + our @ISA = qw(Exporter); + our %EXPORT_TAGS = (); + our @EXPORT = (); + our @EXPORT_OK = qw( + micro_t + percentage_of + secs_to_time + time_to_secs + shorten + ts + parse_timestamp + unix_timestamp + any_unix_timestamp + make_checksum + crc32 + encode_json + ); +} our $mysql_ts = qr/(\d\d)(\d\d)(\d\d) +(\d+):(\d+):(\d+)(\.\d+)?/; our $proper_ts = qr/(\d\d\d\d)-(\d\d)-(\d\d)[T ](\d\d):(\d\d):(\d\d)(\.\d+)?/; @@ -2562,8 +2564,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } @@ -2592,6 +2594,9 @@ sub parse_timestamp { . (defined $f ? '%09.6f' : '%02d'), $y + 2000, $m, $d, $h, $i, (defined $f ? $s + $f : $s); } + elsif ( $val =~ m/^$proper_ts$/ ) { + return $val; + } return $val; } @@ -6209,11 +6214,10 @@ sub new { last_reported => $args{start}, fraction => 0, # How complete the job is callback => sub { - my ($fraction, $elapsed, $remaining, $eta) = @_; + my ($fraction, $elapsed, $remaining) = @_; printf STDERR "$name: %3d%% %s remain\n", $fraction * 100, - Transformers::secs_to_time($remaining), - Transformers::ts($eta); + Transformers::secs_to_time($remaining); }, %args, }; diff --git a/bin/pt-upgrade b/bin/pt-upgrade index a75ef503..376cfcae 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -2799,8 +2799,8 @@ sub shorten { } return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); } @@ -9123,11 +9123,10 @@ sub new { last_reported => $args{start}, fraction => 0, # How complete the job is callback => sub { - my ($fraction, $elapsed, $remaining, $eta) = @_; + my ($fraction, $elapsed, $remaining) = @_; printf STDERR "$name: %3d%% %s remain\n", $fraction * 100, - Transformers::secs_to_time($remaining), - Transformers::ts($eta); + Transformers::secs_to_time($remaining); }, %args, }; diff --git a/lib/Progress.pm b/lib/Progress.pm index 07ad4f4c..5657e873 100644 --- a/lib/Progress.pm +++ b/lib/Progress.pm @@ -71,11 +71,10 @@ sub new { last_reported => $args{start}, fraction => 0, # How complete the job is callback => sub { - my ($fraction, $elapsed, $remaining, $eta) = @_; + my ($fraction, $elapsed, $remaining) = @_; printf STDERR "$name: %3d%% %s remain\n", $fraction * 100, - Transformers::secs_to_time($remaining), - Transformers::ts($eta); + Transformers::secs_to_time($remaining); }, %args, }; diff --git a/lib/QueryReportFormatter.pm b/lib/QueryReportFormatter.pm index 7ec51d06..e5d2570a 100644 --- a/lib/QueryReportFormatter.pm +++ b/lib/QueryReportFormatter.pm @@ -123,9 +123,9 @@ sub BUILDARGS { report_all => $o->get('report-all'), report_histogram => $o->get('report-histogram'), }, - num_format => "# %-${label_width}s %3s %7s %7s %7s %7s %7s %7s %7s", - bool_format => "# %-${label_width}s %3d%% yes, %3d%% no", - string_format => "# %-${label_width}s %s", + num_format => '# %1$-'.$label_width.'s %2$3s %3$7s %4$7s %5$7s %6$7s %7$7s %8$7s %9$7s', + bool_format => '# %1$-'.$label_width.'s %2$3d%% yes, %3$3d%% no', + string_format => '# %1$-'.$label_width.'s %2$s', hidden_attrib => { # Don't sort/print these attribs in the reports. arg => 1, # They're usually handled specially, or not fingerprint => 1, # printed at all. @@ -673,7 +673,11 @@ sub event_report { $val->{checksum}, $val->{pos_in_log}, ); - $line .= ('_' x (LINE_LENGTH - length($line) + $self->label_width() - 12)); + my $underscores = LINE_LENGTH - length($line) + $self->label_width() - 12; + if ( $underscores < 0 ) { + $underscores = 0; + } + $line .= ('_' x $underscores); push @result, $line; # Second line: reason why this class is being reported. diff --git a/lib/Transformers.pm b/lib/Transformers.pm index f378c474..1a98d515 100644 --- a/lib/Transformers.pm +++ b/lib/Transformers.pm @@ -159,10 +159,12 @@ sub shorten { $num /= $d; ++$n; } + # Added indexes 1$, 2$ to sprintf format to avoid 'redundant' warning + # https://bugs.launchpad.net/percona-toolkit/+bug/1480719 return sprintf( $num =~ m/\./ || $n - ? "%.${p}f%s" - : '%d', + ? '%1$.'.$p.'f%2$s' + : '%1$d', $num, $units[$n]); }