From 96fbedff7280e8d4a7ca8ccb76047003ab7abefb Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Tue, 25 Apr 2023 23:05:47 +0200 Subject: [PATCH] Adding stop after dumping option --- mysqltuner.pl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 765aea2..b9d27a5 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -111,6 +111,7 @@ my %opt = ( "defaults-extra-file" => '', "protocol" => '', "dumpdir" => '', + "stop-after-dumping" => 0, ); # Gather the options from the command line @@ -143,6 +144,7 @@ GetOptions( 'idxstat', 'noidxstat', 'server-log=s', 'protocol=s', 'defaults-extra-file=s', 'dumpdir=s', + 'stop-after-dumping' ) or pod2usage( -exitval => 1, @@ -1035,17 +1037,35 @@ sub select_array { return @result; } +# MySQL Request Array +sub select_array_with_headers { + my $req = shift; + debugprint "PERFORM: $req "; + my @result = `$mysqlcmd $mysqllogin -Bs --column-name -e "\\w$req" 2>>/dev/null`; + if ( $? != 0 ) { + badprint "Failed to execute: $req"; + badprint "FAIL Execute SQL / return code: $?"; + debugprint "CMD : $mysqlcmd"; + debugprint "OPTIONS: $mysqllogin"; + debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`; + + #exit $?; + } + debugprint "select_array: return code : $?"; + chomp(@result); + return @result; +} # MySQL Request Array sub select_csv_file { my $tfile = shift; my $req = shift; debugprint "PERFORM: $req CSV into $tfile"; - my @result = select_array($req); + my @result = select_array_with_headers($req); open( my $fh, '>', $tfile ) or die "Could not open file '$tfile' $!"; for my $l (@result) { $l =~ s/\t/","/g; $l =~ s/^/"/; - $l =~ s/$/"/; + $l =~ s/$/"\n/; print $fh $l; } close $fh; @@ -2653,6 +2673,7 @@ sub calculations { exit 2; } + # Per-thread memory # Per-thread memory if ( mysql_version_ge(4) ) { $mycalc{'per_thread_buffers'} = @@ -3951,6 +3972,7 @@ sub mysqsl_pfs { ); } } + exit 0 if ( $opt{stop-after-dumping} == 1 ); # Top user per connection subheaderprint "Performance schema: Top 5 user per connection";