Add back --quiet and test pt-trend.

This commit is contained in:
Daniel Nichter
2011-11-14 09:23:47 -07:00
parent bf6f70049a
commit 26a42a24d5
3 changed files with 59 additions and 4 deletions

View File

@@ -1797,10 +1797,9 @@ sub _d {
package pt_trend; package pt_trend;
use English qw(-no_match_vars); use English qw(-no_match_vars);
use constant MKDEBUG => $ENV{MKDEBUG} || 0; use constant MKDEBUG => $ENV{MKDEBUG} || 0;
Transformers->import(qw(any_unix_timestamp));
if ( !caller ) { exit main(@ARGV); } # Run the program.
sub main { sub main {
@ARGV = @_; # set global ARGV for this package @ARGV = @_; # set global ARGV for this package
@@ -1810,7 +1809,7 @@ sub main {
my $o = new OptionParser(); my $o = new OptionParser();
$o->get_specs(); $o->get_specs();
$o->get_opts(); $o->get_opts();
$o->set('progress', undef) if $o->get('q'); $o->set('progress', undef) if $o->get('quiet');
if ( !$o->got('help') ) { if ( !$o->got('help') ) {
if ( $o->get('progress') ) { if ( $o->get('progress') ) {
eval { Progress->validate_spec($o->get('progress')) }; eval { Progress->validate_spec($o->get('progress')) };
@@ -1887,7 +1886,10 @@ sub main {
return 0; return 0;
} }
Transformers->import(qw(any_unix_timestamp)); # ############################################################################
# Subroutines
# ############################################################################
sub print_report { sub print_report {
my ( $stats ) = @_; my ( $stats ) = @_;
my $ts = any_unix_timestamp($stats->{ts}); my $ts = any_unix_timestamp($stats->{ts});
@@ -1903,6 +1905,11 @@ sub _d {
print STDERR "# $package:$line $PID ", join(' ', @_), "\n"; print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
} }
# ############################################################################
# Run the program.
# ############################################################################
if ( !caller ) { exit main(@ARGV); }
1; # Because this is a module as well as a script. 1; # Because this is a module as well as a script.
# ############################################################################ # ############################################################################
@@ -1984,6 +1991,12 @@ parts. The first part can be percentage, time, or iterations; the second part
specifies how often an update should be printed, in percentage, seconds, or specifies how often an update should be printed, in percentage, seconds, or
number of iterations. number of iterations.
=item --quiet
short form: -q
Disables L<"--progress">.
=item --version =item --version
Show version and exit. Show version and exit.

33
t/pt-trend/basics.t Normal file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 1;
use PerconaTest;
require "$trunk/bin/pt-trend";
my $in = "$trunk/t/lib/samples/slowlogs";
my $out = "t/pt-trend/samples/";
my @args = ();
ok(
no_diff(
sub { pt_trend::main(@args, "$in/slow053.txt") },
"$out/slow053.txt",
),
"Analysis for slow053.txt"
);
# #############################################################################
# Done.
# #############################################################################
exit;

View File

@@ -0,0 +1,9 @@
1297191601 1.000000 0.000012 0.000012 0.000012 0.000012
1297191602 1.000000 0.000012 0.000012 0.000012 0.000012
1297191603 1.000000 0.000012 0.000012 0.000012 0.000012
1297191604 1.000000 0.000012 0.000012 0.000012 0.000012
1297191605 1.000000 0.000012 0.000012 0.000012 0.000012
1297191606 1.000000 0.000012 0.000012 0.000012 0.000012
1297191607 1.000000 0.000012 0.000012 0.000012 0.000012
1297191608 1.000000 0.050012 0.050012 0.050012 0.050012
1297191609 1.000000 1.000012 1.000012 1.000012 1.000012