Fixes as per Baron's review.

This commit is contained in:
Brian Fraser
2012-01-17 11:40:01 -03:00
parent 076c0d70b1
commit 05fec15473
6 changed files with 113 additions and 132 deletions

View File

@@ -1576,8 +1576,8 @@ sub new {
block_size => 512, block_size => 512,
show_inactive => $o->get('show-inactive'), show_inactive => $o->get('show-inactive'),
sample_time => $o->get('sample-time') || 0, sample_time => $o->get('sample-time') || 0,
column_regex => qr/$columns/, columns_regex => qr/$columns/,
device_regex => $devices ? qr/$devices/ : undef, devices_regex => $devices ? qr/$devices/ : undef,
interactive => 0, interactive => 0,
%args, %args,
@@ -1602,8 +1602,7 @@ sub new {
_ordered_devs => [], _ordered_devs => [],
_active_devices => {}, _active_devices => {},
_ts => {}, _ts => {},
_first => 1, _first_stats_for => {},
_first_time_magic => 1,
_nochange_skips => [], _nochange_skips => [],
_save_curr_as_prev => 1, _save_curr_as_prev => 1,
@@ -1678,24 +1677,24 @@ sub set_interactive {
} }
} }
sub column_regex { sub columns_regex {
my ( $self ) = @_; my ( $self ) = @_;
return $self->{column_regex}; return $self->{columns_regex};
} }
sub set_column_regex { sub set_columns_regex {
my ( $self, $new_re ) = @_; my ( $self, $new_re ) = @_;
return $self->{column_regex} = $new_re; return $self->{columns_regex} = $new_re;
} }
sub device_regex { sub devices_regex {
my ( $self ) = @_; my ( $self ) = @_;
return $self->{device_regex}; return $self->{devices_regex};
} }
sub set_device_regex { sub set_devices_regex {
my ( $self, $new_re ) = @_; my ( $self, $new_re ) = @_;
return $self->{device_regex} = $new_re; return $self->{devices_regex} = $new_re;
} }
sub filename { sub filename {
@@ -1735,7 +1734,6 @@ sub add_ordered_dev {
sub clear_state { sub clear_state {
my ($self) = @_; my ($self) = @_;
$self->{_first} = 1;
$self->{_print_header} = 1; $self->{_print_header} = 1;
$self->clear_curr_stats(); $self->clear_curr_stats();
$self->clear_prev_stats(); $self->clear_prev_stats();
@@ -1838,7 +1836,7 @@ sub _save_curr_as_prev {
sub _save_curr_as_first { sub _save_curr_as_first {
my ($self, $curr) = @_; my ($self, $curr) = @_;
if ( $self->{_first} ) { if ( !%{$self->{_first_stats_for}} ) {
$self->{_first_stats_for} = { $self->{_first_stats_for} = {
map { $_ => [@{$curr->{$_}}] } keys %$curr map { $_ => [@{$curr->{$_}}] } keys %$curr
}; };
@@ -1856,7 +1854,7 @@ sub trim {
sub col_ok { sub col_ok {
my ( $self, $column ) = @_; my ( $self, $column ) = @_;
my $regex = $self->column_regex(); my $regex = $self->columns_regex();
return ($column =~ $regex) || (trim($column) =~ $regex); return ($column =~ $regex) || (trim($column) =~ $regex);
} }
@@ -1879,7 +1877,7 @@ our @columns_in_order = (
[ "in_prg" => "%6d", "in_progress", ], [ "in_prg" => "%6d", "in_progress", ],
[ " io_s" => "%7.1f", "s_spent_doing_io", ], [ " io_s" => "%7.1f", "s_spent_doing_io", ],
[ " qtime" => "%6.1f", "qtime", ], [ " qtime" => "%6.1f", "qtime", ],
[ " stime" => "%5.1f", "stime", ], [ "stime" => "%5.1f", "stime", ],
); );
{ {
@@ -2158,14 +2156,12 @@ sub _calc_delta_for {
sub _print_device_if { sub _print_device_if {
my ($self, $dev ) = @_; my ($self, $dev ) = @_;
my $dev_re = $self->device_regex(); my $dev_re = $self->devices_regex();
if ( $dev_re ) { if ( $dev_re ) {
return $dev if $dev =~ $dev_re; return $dev if $dev =~ $dev_re;
} }
else { else {
return $dev if $self->{_first_time_magic}; # First time around
if ( $self->show_inactive() || $self->active_device($dev) ) { if ( $self->show_inactive() || $self->active_device($dev) ) {
return $dev; return $dev;
} }
@@ -2227,7 +2223,6 @@ sub _calc_stats_for_deltas {
push @end_stats, \%stats; push @end_stats, \%stats;
} }
$self->{_first_time_magic} = undef;
if ( @{$self->{_nochange_skips}} ) { if ( @{$self->{_nochange_skips}} ) {
my $devs = join ", ", @{$self->{_nochange_skips}}; my $devs = join ", ", @{$self->{_nochange_skips}};
PTDEBUG && _d("Skipping [$devs], haven't changed from the first sample"); PTDEBUG && _d("Skipping [$devs], haven't changed from the first sample");
@@ -2706,7 +2701,6 @@ sub clear_state {
sub compute_devs_in_group { sub compute_devs_in_group {
my ($self) = @_; my ($self) = @_;
my $stats = $self->stats_for(); my $stats = $self->stats_for();
my $re = $self->device_regex();
return scalar grep { return scalar grep {
$stats->{$_} && $self->_print_device_if($_) $stats->{$_} && $self->_print_device_if($_)
} $self->ordered_devs; } $self->ordered_devs;
@@ -2738,6 +2732,8 @@ sub _calc_stats_for_deltas {
} }
} }
return unless $delta_for && %{$delta_for};
my $in_progress = $delta_for->{ios_in_progress}; my $in_progress = $delta_for->{ios_in_progress};
my $tot_in_progress = 0; my $tot_in_progress = 0;
my $devs_in_group = $self->compute_devs_in_group() || 1; my $devs_in_group = $self->compute_devs_in_group() || 1;
@@ -2831,26 +2827,27 @@ require DiskstatsGroupByDisk;
require DiskstatsGroupBySample; require DiskstatsGroupBySample;
my %actions = ( my %actions = (
'A' => \&group_by, 'A' => \&group_by,
'D' => \&group_by, 'D' => \&group_by,
'S' => \&group_by, 'S' => \&group_by,
'i' => \&hide_inactive_disks, 'i' => \&hide_inactive_disks,
'd' => get_new_value_for( "redisplay_interval", 'd' => get_new_value_for( "redisplay_interval",
"Enter a new redisplay interval in seconds: " ), "Enter a new redisplay interval in seconds: " ),
'z' => get_new_value_for( "sample_time", 'z' => get_new_value_for( "sample_time",
"Enter a new interval between samples in seconds: " ), "Enter a new interval between samples in seconds: " ),
'c' => get_new_regex_for( "column_regex", 'c' => get_new_regex_for( "columns_regex",
"Enter a column pattern: " ), "Enter a column pattern: " ),
'/' => get_new_regex_for( "device_regex", '/' => get_new_regex_for( "devices_regex",
"Enter a disk/device pattern: " ), "Enter a disk/device pattern: " ),
'q' => sub { return 'last' }, 'q' => sub { return 'last' },
'p' => sub { 'p' => sub {
print "Paused - press any key to continue\n"; print "Paused - press any key to continue\n";
pause(@_); pause(@_);
return; return;
}, },
' ' => \&print_header, ' ' => \&print_header,
'?' => \&help, "\n" => \&print_header,
'?' => \&help,
); );
my %input_to_object = ( my %input_to_object = (
@@ -2933,6 +2930,9 @@ sub run_interactive {
filehandle => $tmp_fh, filehandle => $tmp_fh,
input => substr(ucfirst($group_by), 0, 1), input => substr(ucfirst($group_by), 0, 1),
); );
if ( !-t STDOUT && !tied *STDIN ) {
return 0
}
} }
ReadKeyMini::cbreak(); ReadKeyMini::cbreak();
@@ -3154,14 +3154,11 @@ sub get_blocking_input {
sub hide_inactive_disks { sub hide_inactive_disks {
my (%args) = @_; my (%args) = @_;
my $new_val = get_blocking_input( my $obj = $args{OptionParser}->get("current_group_by_obj");
"Filter inactive rows? (Leave blank for 'No') " my $new_val = !$obj->show_inactive();
);
$args{OptionParser}->set('show-inactive', !$new_val); $args{OptionParser}->set('show-inactive', !$new_val);
$obj->set_show_inactive(!$new_val);
$args{OptionParser}->get("current_group_by_obj")
->set_show_inactive(!$new_val);
return; return;
} }
@@ -3275,12 +3272,6 @@ use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0; use constant PTDEBUG => $ENV{PTDEBUG} || 0;
# Dump backtrace on exception if debugging is enabled.
local $SIG{__DIE__} = sub {
require Carp;
Carp::confess(@_) unless $EXCEPTIONS_BEING_CAUGHT;
} if PTDEBUG;
sub main { sub main {
@ARGV = @_; # set global ARGV for this package @ARGV = @_; # set global ARGV for this package
@@ -3637,23 +3628,4 @@ This program is copyright 2010-2011 Baron Schwartz, 2011 Percona Inc.
Feedback and improvements are welcome. Feedback and improvements are welcome.
THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF WARRANTIES, INCLUDING, WITHOUT LIMITATION, TH
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
systems, you can issue `man perlgpl' or `man perlartistic' to read these
licenses.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA.
=head1 VERSION
pt-diskstats 2.0.0_WIP
=cut
__END__

View File

@@ -79,8 +79,8 @@ sub new {
block_size => 512, block_size => 512,
show_inactive => $o->get('show-inactive'), show_inactive => $o->get('show-inactive'),
sample_time => $o->get('sample-time') || 0, sample_time => $o->get('sample-time') || 0,
column_regex => qr/$columns/, columns_regex => qr/$columns/,
device_regex => $devices ? qr/$devices/ : undef, devices_regex => $devices ? qr/$devices/ : undef,
interactive => 0, interactive => 0,
%args, %args,
@@ -105,8 +105,7 @@ sub new {
_ordered_devs => [], _ordered_devs => [],
_active_devices => {}, _active_devices => {},
_ts => {}, _ts => {},
_first => 1, _first_stats_for => {},
_first_time_magic => 1,
_nochange_skips => [], _nochange_skips => [],
# Internal for now, but might need APIfying. # Internal for now, but might need APIfying.
@@ -183,24 +182,24 @@ sub set_interactive {
} }
} }
sub column_regex { sub columns_regex {
my ( $self ) = @_; my ( $self ) = @_;
return $self->{column_regex}; return $self->{columns_regex};
} }
sub set_column_regex { sub set_columns_regex {
my ( $self, $new_re ) = @_; my ( $self, $new_re ) = @_;
return $self->{column_regex} = $new_re; return $self->{columns_regex} = $new_re;
} }
sub device_regex { sub devices_regex {
my ( $self ) = @_; my ( $self ) = @_;
return $self->{device_regex}; return $self->{devices_regex};
} }
sub set_device_regex { sub set_devices_regex {
my ( $self, $new_re ) = @_; my ( $self, $new_re ) = @_;
return $self->{device_regex} = $new_re; return $self->{devices_regex} = $new_re;
} }
sub filename { sub filename {
@@ -245,7 +244,6 @@ sub add_ordered_dev {
sub clear_state { sub clear_state {
my ($self) = @_; my ($self) = @_;
$self->{_first} = 1;
$self->{_print_header} = 1; $self->{_print_header} = 1;
$self->clear_curr_stats(); $self->clear_curr_stats();
$self->clear_prev_stats(); $self->clear_prev_stats();
@@ -348,7 +346,7 @@ sub _save_curr_as_prev {
sub _save_curr_as_first { sub _save_curr_as_first {
my ($self, $curr) = @_; my ($self, $curr) = @_;
if ( $self->{_first} ) { if ( !%{$self->{_first_stats_for}} ) {
$self->{_first_stats_for} = { $self->{_first_stats_for} = {
map { $_ => [@{$curr->{$_}}] } keys %$curr map { $_ => [@{$curr->{$_}}] } keys %$curr
}; };
@@ -366,7 +364,7 @@ sub trim {
sub col_ok { sub col_ok {
my ( $self, $column ) = @_; my ( $self, $column ) = @_;
my $regex = $self->column_regex(); my $regex = $self->columns_regex();
return ($column =~ $regex) || (trim($column) =~ $regex); return ($column =~ $regex) || (trim($column) =~ $regex);
} }
@@ -390,7 +388,7 @@ our @columns_in_order = (
[ "in_prg" => "%6d", "in_progress", ], [ "in_prg" => "%6d", "in_progress", ],
[ " io_s" => "%7.1f", "s_spent_doing_io", ], [ " io_s" => "%7.1f", "s_spent_doing_io", ],
[ " qtime" => "%6.1f", "qtime", ], [ " qtime" => "%6.1f", "qtime", ],
[ " stime" => "%5.1f", "stime", ], [ "stime" => "%5.1f", "stime", ],
); );
{ {
@@ -736,7 +734,7 @@ sub _print_device_if {
# from the first-ever observed sample # from the first-ever observed sample
my ($self, $dev ) = @_; my ($self, $dev ) = @_;
my $dev_re = $self->device_regex(); my $dev_re = $self->devices_regex();
if ( $dev_re ) { if ( $dev_re ) {
# device_regex was set explicitly, either through --devices-regex, # device_regex was set explicitly, either through --devices-regex,
@@ -744,9 +742,7 @@ sub _print_device_if {
# it blank # it blank
return $dev if $dev =~ $dev_re; return $dev if $dev =~ $dev_re;
} }
else { else {
return $dev if $self->{_first_time_magic}; # First time around
if ( $self->show_inactive() || $self->active_device($dev) ) { if ( $self->show_inactive() || $self->active_device($dev) ) {
# If --show-interactive is enabled, or we've seen # If --show-interactive is enabled, or we've seen
# the device be active at least once. # the device be active at least once.
@@ -814,7 +810,6 @@ sub _calc_stats_for_deltas {
push @end_stats, \%stats; push @end_stats, \%stats;
} }
$self->{_first_time_magic} = undef;
if ( @{$self->{_nochange_skips}} ) { if ( @{$self->{_nochange_skips}} ) {
my $devs = join ", ", @{$self->{_nochange_skips}}; my $devs = join ", ", @{$self->{_nochange_skips}};
PTDEBUG && _d("Skipping [$devs], haven't changed from the first sample"); PTDEBUG && _d("Skipping [$devs], haven't changed from the first sample");

View File

@@ -129,7 +129,6 @@ sub clear_state {
sub compute_devs_in_group { sub compute_devs_in_group {
my ($self) = @_; my ($self) = @_;
my $stats = $self->stats_for(); my $stats = $self->stats_for();
my $re = $self->device_regex();
return scalar grep { return scalar grep {
# Got stats for that device, and it matches the devices re # Got stats for that device, and it matches the devices re
$stats->{$_} && $self->_print_device_if($_) $stats->{$_} && $self->_print_device_if($_)
@@ -163,6 +162,8 @@ sub _calc_stats_for_deltas {
} }
} }
return unless $delta_for && %{$delta_for};
my $in_progress = $delta_for->{ios_in_progress}; my $in_progress = $delta_for->{ios_in_progress};
my $tot_in_progress = 0; my $tot_in_progress = 0;
my $devs_in_group = $self->compute_devs_in_group() || 1; my $devs_in_group = $self->compute_devs_in_group() || 1;

View File

@@ -41,27 +41,28 @@ require DiskstatsGroupByDisk;
require DiskstatsGroupBySample; require DiskstatsGroupBySample;
my %actions = ( my %actions = (
'A' => \&group_by, 'A' => \&group_by,
'D' => \&group_by, 'D' => \&group_by,
'S' => \&group_by, 'S' => \&group_by,
'i' => \&hide_inactive_disks, 'i' => \&hide_inactive_disks,
'd' => get_new_value_for( "redisplay_interval", 'd' => get_new_value_for( "redisplay_interval",
"Enter a new redisplay interval in seconds: " ), "Enter a new redisplay interval in seconds: " ),
'z' => get_new_value_for( "sample_time", 'z' => get_new_value_for( "sample_time",
"Enter a new interval between samples in seconds: " ), "Enter a new interval between samples in seconds: " ),
'c' => get_new_regex_for( "column_regex", 'c' => get_new_regex_for( "columns_regex",
"Enter a column pattern: " ), "Enter a column pattern: " ),
'/' => get_new_regex_for( "device_regex", '/' => get_new_regex_for( "devices_regex",
"Enter a disk/device pattern: " ), "Enter a disk/device pattern: " ),
# Magical return value. # Magical return value.
'q' => sub { return 'last' }, 'q' => sub { return 'last' },
'p' => sub { 'p' => sub {
print "Paused - press any key to continue\n"; print "Paused - press any key to continue\n";
pause(@_); pause(@_);
return; return;
}, },
' ' => \&print_header, ' ' => \&print_header,
'?' => \&help, "\n" => \&print_header,
'?' => \&help,
); );
my %input_to_object = ( my %input_to_object = (
@@ -154,6 +155,12 @@ sub run_interactive {
filehandle => $tmp_fh, filehandle => $tmp_fh,
input => substr(ucfirst($group_by), 0, 1), input => substr(ucfirst($group_by), 0, 1),
); );
if ( !-t STDOUT && !tied *STDIN ) {
# If we were passed down a file but aren't tied to a tty,
# -and- STDIN isn't tied (so we aren't in testing mode),
# then this is the end of the program.
return 0
}
} }
ReadKeyMini::cbreak(); ReadKeyMini::cbreak();
@@ -395,14 +402,11 @@ sub get_blocking_input {
sub hide_inactive_disks { sub hide_inactive_disks {
my (%args) = @_; my (%args) = @_;
my $new_val = get_blocking_input( my $obj = $args{OptionParser}->get("current_group_by_obj");
"Filter inactive rows? (Leave blank for 'No') " my $new_val = !$obj->show_inactive();
);
$args{OptionParser}->set('show-inactive', !$new_val); $args{OptionParser}->set('show-inactive', !$new_val);
$obj->set_show_inactive(!$new_val);
$args{OptionParser}->get("current_group_by_obj")
->set_show_inactive(!$new_val);
return; return;
} }

View File

@@ -33,7 +33,7 @@ $o->get_opts();
my $obj = new Diskstats(OptionParser => $o); my $obj = new Diskstats(OptionParser => $o);
can_ok( $obj, qw( can_ok( $obj, qw(
column_regex device_regex filename columns_regex devices_regex filename
block_size ordered_devs clear_state clear_ordered_devs block_size ordered_devs clear_state clear_ordered_devs
stats_for prev_stats_for first_stats_for stats_for prev_stats_for first_stats_for
has_stats design_print_formats parse_diskstats_line has_stats design_print_formats parse_diskstats_line
@@ -46,8 +46,8 @@ can_ok( $obj, qw(
for my $attr ( for my $attr (
[ filename => (File::Temp::tempfile($0.'diskstats.XXXXXX', [ filename => (File::Temp::tempfile($0.'diskstats.XXXXXX',
OPEN=>0, UNLINK=>1))[1] ], OPEN=>0, UNLINK=>1))[1] ],
[ column_regex => qr/!!!/ ], [ columns_regex => qr/!!!/ ],
[ device_regex => qr/!!!/ ], [ devices_regex => qr/!!!/ ],
[ block_size => 215 ], [ block_size => 215 ],
[ show_inactive => 1 ], [ show_inactive => 1 ],
[ sample_time => 1 ], [ sample_time => 1 ],
@@ -159,7 +159,7 @@ like(
my @columns_in_order = @Diskstats::columns_in_order; my @columns_in_order = @Diskstats::columns_in_order;
$obj->set_column_regex(qr/./); $obj->set_columns_regex(qr/./);
my ($header, $rows, $cols) = $obj->design_print_formats(); my ($header, $rows, $cols) = $obj->design_print_formats();
is_deeply( is_deeply(
$cols, $cols,
@@ -168,15 +168,15 @@ is_deeply(
); );
# qr/ \A (?!.*io_s$|\s*[qs]time$) /x # qr/ \A (?!.*io_s$|\s*[qs]time$) /x
$obj->set_column_regex(qr/cnc|rt|busy|prg|[mk]b|[dr]_s|mrg/); $obj->set_columns_regex(qr/cnc|rt|busy|prg|[mk]b|[dr]_s|mrg/);
($header, $rows, $cols) = $obj->design_print_formats(); ($header, $rows, $cols) = $obj->design_print_formats();
is( is(
$header, $header,
join(" ", q{%5s %-6s}, grep { $_ =~ $obj->column_regex() } map { $_->[0] } @columns_in_order), join(" ", q{%5s %-6s}, grep { $_ =~ $obj->columns_regex() } map { $_->[0] } @columns_in_order),
"design_print_formats: sanity check for defaults" "design_print_formats: sanity check for defaults"
); );
$obj->set_column_regex(qr/./); $obj->set_columns_regex(qr/./);
($header, $rows, $cols) = $obj->design_print_formats(max_device_length => 10); ($header, $rows, $cols) = $obj->design_print_formats(max_device_length => 10);
my $all_columns_format = join(" ", q{%5s %-10s}, map { $_->[0] } @columns_in_order); my $all_columns_format = join(" ", q{%5s %-10s}, map { $_->[0] } @columns_in_order);
is( is(
@@ -185,15 +185,15 @@ is(
"design_print_formats: max_device_length works" "design_print_formats: max_device_length works"
); );
$obj->set_column_regex(qr/(?!)/); # Will never match $obj->set_columns_regex(qr/(?!)/); # Will never match
($header, $rows, $cols) = $obj->design_print_formats(max_device_length => 10); ($header, $rows, $cols) = $obj->design_print_formats(max_device_length => 10);
is( is(
$header, $header,
q{%5s %-10s }, q{%5s %-10s },
"design_print_formats respects column_regex" "design_print_formats respects columns_regex"
); );
$obj->set_column_regex(qr/./); $obj->set_columns_regex(qr/./);
($header, $rows, $cols) = $obj->design_print_formats( ($header, $rows, $cols) = $obj->design_print_formats(
max_device_length => 10, max_device_length => 10,
columns => [] columns => []
@@ -204,7 +204,7 @@ is(
"...unless we pass an explicit column array" "...unless we pass an explicit column array"
); );
$obj->set_column_regex(qr/./); $obj->set_columns_regex(qr/./);
($header, $rows, $cols) = $obj->design_print_formats( ($header, $rows, $cols) = $obj->design_print_formats(
max_device_length => 10, max_device_length => 10,
columns => [qw( busy )] columns => [qw( busy )]
@@ -470,7 +470,7 @@ for my $test (
my $obj = $test->{class}->new(OptionParser => $o, show_inactive => 1); my $obj = $test->{class}->new(OptionParser => $o, show_inactive => 1);
my $prefix = $test->{results_file_prefix}; my $prefix = $test->{results_file_prefix};
$obj->set_column_regex(qr/ \A (?!.*io_s$|\s*[qs]time$) /x); $obj->set_columns_regex(qr/ \A (?!.*io_s$|\s*[qs]time$) /x);
$obj->set_show_inactive(1); $obj->set_show_inactive(1);
for my $filename ( map "diskstats-00$_.txt", 1..5 ) { for my $filename ( map "diskstats-00$_.txt", 1..5 ) {

View File

@@ -9,7 +9,7 @@ BEGIN {
use strict; use strict;
use warnings FATAL => 'all'; use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Test::More tests => 16; use Test::More tests => 19;
use File::Temp (); use File::Temp ();
@@ -24,7 +24,9 @@ require "$trunk/bin/pt-diskstats";
# of this file about *DATA. Please don't close it. # of this file about *DATA. Please don't close it.
{ {
sub Test::TIEHANDLE { sub Test::TIEHANDLE {
return bless {}, "Test"; my ($class, @cmds) = @_;
push @cmds, "q";
return bless \@cmds, $class;
} }
sub Test::FILENO { sub Test::FILENO {
@@ -32,19 +34,21 @@ sub Test::FILENO {
} }
sub Test::READLINE { sub Test::READLINE {
return "q"; my ($self) = @_;
return shift @$self;
} }
} }
sub test_diskstats_file { sub test_diskstats_file {
my (%args) = @_; my (%args) = @_;
my $file = "$trunk/t/pt-diskstats/samples/$args{file}"; my $file = "$trunk/t/pt-diskstats/samples/$args{file}";
my @commands = @{ $args{commands} || [qw( q )] };
die "$file does not exist" unless -f $file; die "$file does not exist" unless -f $file;
foreach my $groupby ( qw(all disk sample) ) { foreach my $groupby ( qw(all disk sample) ) {
ok( ok(
no_diff( no_diff(
sub { sub {
tie local *STDIN, "Test"; tie local *STDIN, Test => @commands;
pt_diskstats::main( pt_diskstats::main(
qw(--show-inactive --group-by), $groupby, qw(--show-inactive --group-by), $groupby,
'--columns-regex','cnc|rt|mb|busy|prg', '--columns-regex','cnc|rt|mb|busy|prg',
@@ -62,6 +66,11 @@ foreach my $file ( map "diskstats-00$_.txt", 1..5 ) {
test_diskstats_file(file => $file); test_diskstats_file(file => $file);
} }
test_diskstats_file(
file => "switch_to_sample.txt",
commands => [ qw( S q ) ]
);
# ########################################################################### # ###########################################################################
# --save-samples and --iterations # --save-samples and --iterations
# ########################################################################### # ###########################################################################