From 26a42a24d59917cf1cbd161ca6f0182e12da34d6 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Mon, 14 Nov 2011 09:23:47 -0700 Subject: [PATCH] Add back --quiet and test pt-trend. --- bin/pt-trend | 21 +++++++++++++++++---- t/pt-trend/basics.t | 33 +++++++++++++++++++++++++++++++++ t/pt-trend/samples/slow053.txt | 9 +++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 t/pt-trend/basics.t create mode 100644 t/pt-trend/samples/slow053.txt diff --git a/bin/pt-trend b/bin/pt-trend index 34a7e1eb..15de89c9 100755 --- a/bin/pt-trend +++ b/bin/pt-trend @@ -1797,10 +1797,9 @@ sub _d { package pt_trend; use English qw(-no_match_vars); - use constant MKDEBUG => $ENV{MKDEBUG} || 0; +Transformers->import(qw(any_unix_timestamp)); -if ( !caller ) { exit main(@ARGV); } # Run the program. sub main { @ARGV = @_; # set global ARGV for this package @@ -1810,7 +1809,7 @@ sub main { my $o = new OptionParser(); $o->get_specs(); $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->get('progress') ) { eval { Progress->validate_spec($o->get('progress')) }; @@ -1887,7 +1886,10 @@ sub main { return 0; } -Transformers->import(qw(any_unix_timestamp)); +# ############################################################################ +# Subroutines +# ############################################################################ + sub print_report { my ( $stats ) = @_; my $ts = any_unix_timestamp($stats->{ts}); @@ -1903,6 +1905,11 @@ sub _d { 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. # ############################################################################ @@ -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 number of iterations. +=item --quiet + +short form: -q + +Disables L<"--progress">. + =item --version Show version and exit. diff --git a/t/pt-trend/basics.t b/t/pt-trend/basics.t new file mode 100644 index 00000000..4f868629 --- /dev/null +++ b/t/pt-trend/basics.t @@ -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; diff --git a/t/pt-trend/samples/slow053.txt b/t/pt-trend/samples/slow053.txt new file mode 100644 index 00000000..97ceee44 --- /dev/null +++ b/t/pt-trend/samples/slow053.txt @@ -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