More changes as per Baron's review.

Tries to implement a facsimile to http://www.xaprb.com/blog/2011/03/18/how-to-gather-statistics-at-regular-intervals/
For both sampling and rendering.
This commit is contained in:
Brian Fraser
2012-01-18 05:19:48 -03:00
parent 3a66cf5187
commit 5b43ed0d5e
11 changed files with 1263 additions and 69 deletions

View File

@@ -9,7 +9,7 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 19;
use Test::More tests => 22;
use File::Temp ();
@@ -23,32 +23,39 @@ require "$trunk/bin/pt-diskstats";
# All we do is send 'q', the command to quit. See the note in the bottom
# of this file about *DATA. Please don't close it.
{
sub Test::TIEHANDLE {
sub TestInteractive::TIEHANDLE {
my ($class, @cmds) = @_;
push @cmds, "q";
return bless \@cmds, $class;
}
sub Test::FILENO {
sub TestInteractive::FILENO {
return fileno(*DATA);
}
sub Test::READLINE {
sub TestInteractive::READLINE {
my ($self) = @_;
return shift @$self;
my $cmd = shift @$self;
print $cmd if $cmd =~ /\n/;
return $cmd;
}
}
sub test_diskstats_file {
my (%args) = @_;
my $file = "$trunk/t/pt-diskstats/samples/$args{file}";
my @commands = @{ $args{commands} || [qw( q )] };
my (%args) = @_;
my $file = "$trunk/t/pt-diskstats/samples/$args{file}";
my @commands = @{ $args{commands} || [qw( q )] };
my $print_cmds = join "][",
map {
( my $x = $_ ) =~ s/\n/\\n/g;
$x
} @commands;
die "$file does not exist" unless -f $file;
foreach my $groupby ( qw(all disk sample) ) {
ok(
no_diff(
sub {
tie local *STDIN, Test => @commands;
tie local *STDIN, TestInteractive => @commands;
pt_diskstats::main(
qw(--show-inactive --group-by), $groupby,
'--columns-regex','cnc|rt|mb|busy|prg',
@@ -57,11 +64,12 @@ sub test_diskstats_file {
"t/pt-diskstats/expected/${groupby}_int_$args{file}",
keep_output=>1,
),
"$args{file} --group-by $groupby"
"$args{file} --group-by $groupby, commands: [$print_cmds]"
);
}
}
foreach my $file ( map "diskstats-00$_.txt", 1..5 ) {
test_diskstats_file(file => $file);
}
@@ -71,6 +79,11 @@ test_diskstats_file(
commands => [ qw( S q ) ]
);
test_diskstats_file(
file => "commands.txt",
commands => [ "i", "/", "cciss\n", "q" ]
);
# ###########################################################################
# --save-samples and --iterations
# ###########################################################################