diff --git a/lib/Diskstats.pm b/lib/Diskstats.pm index c51e0b26..421753ab 100644 --- a/lib/Diskstats.pm +++ b/lib/Diskstats.pm @@ -48,7 +48,7 @@ sub new { device_regex => qr/.+/, block_size => 512, out_fh => \*STDOUT, - filter_zeroed_rows => $o->get('zero-rows') ? undef : 1, + zero_rows => $o->get('zero-rows') ? 1 : undef, sample_time => $o->get('sample-time') || 0, interactive => 0, @@ -122,14 +122,14 @@ sub set_first_ts { $self->{_ts}->{first} = $val || 0; } -sub filter_zeroed_rows { +sub zero_rows { my ($self) = @_; - return $self->{filter_zeroed_rows}; + return $self->{zero_rows}; } -sub set_filter_zeroed_rows { +sub set_zero_rows { my ($self, $new_val) = @_; - $self->{filter_zeroed_rows} = $new_val; + $self->{zero_rows} = $new_val; } sub sample_time { @@ -861,7 +861,7 @@ sub print_header { sub print_rows { my ($self, $format, $cols, $stat) = @_; - if ( $self->filter_zeroed_rows() ) { + if ( ! $self->zero_rows() ) { # Conundrum: What is "zero"? # Is 0.000001 zero? How about 0.1? # Here the answer is "it looks like zero after formatting"; diff --git a/lib/DiskstatsMenu.pm b/lib/DiskstatsMenu.pm index d58e7941..e22e89f4 100644 --- a/lib/DiskstatsMenu.pm +++ b/lib/DiskstatsMenu.pm @@ -296,7 +296,7 @@ sub help { my $device_re = $args{options}->{OptionParser}->get('devices'); my $interval = $obj->sample_time() || '(none)'; my $disp_int = $args{options}->{OptionParser}->get('redisplay-interval'); - my $inact_disk = $obj->filter_zeroed_rows() ? 'yes' : 'no'; + my $inact_disk = $obj->zero_rows() ? 'no' : 'yes'; for my $re ( $column_re, $device_re ) { $re ||= '(none)'; @@ -368,10 +368,8 @@ sub hide_inactive_disks { my (%args) = @_; my $new_val = get_blocking_input("Filter inactive rows? (Leave blank for 'No') "); - # Eeep. In OptionParser, "true" means show; in Diskstats, "true" means hide. - # Thus !$new_val for OptionParser $args{options}->{OptionParser}->set('zero-rows', !$new_val); - $args{options}->{current_group_by_obj}->set_filter_zeroed_rows($new_val); + $args{options}->{current_group_by_obj}->set_zero_rows(!$new_val); return; } diff --git a/t/lib/Diskstats.t b/t/lib/Diskstats.t index 93d1e31c..3b960f41 100644 --- a/t/lib/Diskstats.t +++ b/t/lib/Diskstats.t @@ -41,14 +41,14 @@ can_ok( $obj, qw( # Test the constructor use File::Temp (); for my $attr ( - [ filename => (File::Temp::tempfile($0.'diskstats.XXXXXX', OPEN=>0, UNLINK=>1))[1]], - [ column_regex => qr/!!!/ ], - [ device_regex => qr/!!!/ ], - [ block_size => 215 ], - [ out_fh => \*STDERR ], - [ filter_zeroed_rows => 1 ], - [ sample_time => 1 ], - [ interactive => 1 ], + [ filename => (File::Temp::tempfile($0.'diskstats.XXXXXX', OPEN=>0, UNLINK=>1))[1]], + [ column_regex => qr/!!!/ ], + [ device_regex => qr/!!!/ ], + [ block_size => 215 ], + [ out_fh => \*STDERR ], + [ zero_rows => 1 ], + [ sample_time => 1 ], + [ interactive => 1 ], ) { my $attribute = $attr->[0]; my $value = $attr->[1]; @@ -221,7 +221,7 @@ is_deeply( "...And clears the internal duplicate-checking list" ); -$obj->set_filter_zeroed_rows(1); +$obj->set_zero_rows(0); my $print_output = output( sub { $obj->print_rows( @@ -231,12 +231,12 @@ my $print_output = output( ); } ); -$obj->set_filter_zeroed_rows(0); +$obj->set_zero_rows(1); is( $print_output, "", - "->filter_zeroed_rows works" + "->zero_rows works" ); for my $method ( qw( delta_against delta_against_ts group_by ) ) { @@ -291,7 +291,7 @@ for my $test ( method => "group_by_sample", results_file_prefix => "sample", }) { - my $obj = $test->{class}->new(OptionParser => $o, filter_zeroed_rows => 0); + my $obj = $test->{class}->new(OptionParser => $o, zero_rows => 1); my $method = $test->{method}; my $prefix = $test->{results_file_prefix};