Skip to content

Commit dd2ed72

Browse files
committed
Indenting mysqltuner at 2024-02-06T17:58:52+01:00
1 parent 30d1d9e commit dd2ed72

File tree

1 file changed

+88
-78
lines changed

1 file changed

+88
-78
lines changed

mysqltuner.pl

Lines changed: 88 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ package main;
196196
$opt{pass} = $opt{password} if ( $opt{pass} eq 0 and $opt{password} ne 0 );
197197

198198
if ( $opt{dumpdir} ne '' ) {
199-
$opt{dumpdir}= abs_path($opt{dumpdir});
199+
$opt{dumpdir} = abs_path( $opt{dumpdir} );
200200
if ( !-d $opt{dumpdir} ) {
201201
mkdir $opt{dumpdir} or die "Cannot create directory $opt{dumpdir}: $!";
202202
}
@@ -237,8 +237,9 @@ package main;
237237
if ( not defined( $opt{structstat} ) or $opt{nostructstat} == 1 )
238238
; # Don't print table struct information
239239
$opt{myisamstat} = 1
240-
if ( not defined( $opt{myisamstat} ));
241-
$opt{myisamstat} = 0 if ($opt{nomyisamstat} == 1 ); # Don't print MyISAM table information
240+
if ( not defined( $opt{myisamstat} ) );
241+
$opt{myisamstat} = 0
242+
if ( $opt{nomyisamstat} == 1 ); # Don't print MyISAM table information
242243

243244
# for RPM distributions
244245
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
@@ -814,7 +815,8 @@ sub mysql_setup {
814815
if ( $opt{socket} ne 0 ) {
815816
if ( $opt{port} ne 0 ) {
816817
$remotestring = " -S $opt{socket} -P $opt{port}";
817-
} else {
818+
}
819+
else {
818820
$remotestring = " -S $opt{socket}";
819821
}
820822
}
@@ -1579,7 +1581,9 @@ sub log_file_recommendations {
15791581
$numLi++;
15801582
debugprint "$numLi: $logLi"
15811583
if $logLi =~ /warning|error/i and $logLi !~ /Logging to/;
1582-
$nbErrLog++ if $logLi =~ /error/i and $logLi !~ /(Logging to|\[Warning\].*ERROR_FOR_DIVISION_BY_ZERO)/;
1584+
$nbErrLog++
1585+
if $logLi =~ /error/i
1586+
and $logLi !~ /(Logging to|\[Warning\].*ERROR_FOR_DIVISION_BY_ZERO)/;
15831587
$nbWarnLog++ if $logLi =~ /warning/i;
15841588
push @lastShutdowns, $logLi
15851589
if $logLi =~ /Shutdown complete/ and $logLi !~ /Innodb/i;
@@ -3179,7 +3183,7 @@ sub calculations {
31793183
unless defined $mystat{'Innodb_buffer_pool_reads'};
31803184
$mycalc{'pct_read_efficiency'} = percentage(
31813185
$mystat{'Innodb_buffer_pool_read_requests'},
3182-
(
3186+
(
31833187
$mystat{'Innodb_buffer_pool_read_requests'} +
31843188
$mystat{'Innodb_buffer_pool_reads'}
31853189
)
@@ -3210,11 +3214,12 @@ sub calculations {
32103214
$mystat{'Innodb_buffer_pool_pages_total'}
32113215
) if defined $mystat{'Innodb_buffer_pool_pages_total'};
32123216

3213-
$mycalc{'innodb_buffer_alloc_pct'}=select_one(
3214-
"select round( 100* sum(allocated)/( select VARIABLE_VALUE ".
3215-
"FROM performance_schema.global_variables " .
3216-
"WHERE VARIABLE_NAME='innodb_buffer_pool_size' ) ,2)".
3217-
'FROM sys.x\$innodb_buffer_stats_by_table;');
3217+
$mycalc{'innodb_buffer_alloc_pct'} = select_one(
3218+
"select round( 100* sum(allocated)/( select VARIABLE_VALUE "
3219+
. "FROM performance_schema.global_variables "
3220+
. "WHERE VARIABLE_NAME='innodb_buffer_pool_size' ) ,2)"
3221+
. 'FROM sys.x\$innodb_buffer_stats_by_table;' );
3222+
32183223
# Binlog Cache
32193224
if ( $myvar{'log_bin'} ne 'OFF' ) {
32203225
$mycalc{'pct_binlog_cache'} = percentage(
@@ -6360,59 +6365,60 @@ sub mysql_innodb {
63606365
. ") if possible." );
63616366
}
63626367

6363-
# select round( 100* sum(allocated)/( select VARIABLE_VALUE
6364-
# FROM performance_schema.global_variables
6365-
# where VARIABLE_NAME='innodb_buffer_pool_size' )
6366-
# ,2) as "PCT ALLOC/BUFFER POOL"
6367-
#from sys.x$innodb_buffer_stats_by_table;
6368+
# select round( 100* sum(allocated)/( select VARIABLE_VALUE
6369+
# FROM performance_schema.global_variables
6370+
# where VARIABLE_NAME='innodb_buffer_pool_size' )
6371+
# ,2) as "PCT ALLOC/BUFFER POOL"
6372+
#from sys.x$innodb_buffer_stats_by_table;
63686373

6369-
if ($mycalc{innodb_buffer_alloc_pct} < 80) {
6370-
badprint "Ratio Buffer Pool allocated / Buffer Pool Size: ".
6371-
$mycalc{'innodb_buffer_alloc_pct'} . '%';
6372-
} else {
6373-
goodprint "Ratio Buffer Pool allocated / Buffer Pool Size: ".
6374-
$mycalc{'innodb_buffer_alloc_pct'} . '%';
6374+
if ( $mycalc{innodb_buffer_alloc_pct} < 80 ) {
6375+
badprint "Ratio Buffer Pool allocated / Buffer Pool Size: "
6376+
. $mycalc{'innodb_buffer_alloc_pct'} . '%';
6377+
}
6378+
else {
6379+
goodprint "Ratio Buffer Pool allocated / Buffer Pool Size: "
6380+
. $mycalc{'innodb_buffer_alloc_pct'} . '%';
63756381
}
63766382
if ( $mycalc{'innodb_log_size_pct'} < 20
63776383
or $mycalc{'innodb_log_size_pct'} > 30 )
63786384
{
6379-
if ( defined $myvar{'innodb_redo_log_capacity'} ) {
6380-
badprint
6381-
"Ratio InnoDB redo log capacity / InnoDB Buffer pool size ("
6382-
. $mycalc{'innodb_log_size_pct'} . "%): "
6383-
. hr_bytes( $myvar{'innodb_redo_log_capacity'} ) . " / "
6384-
. hr_bytes( $myvar{'innodb_buffer_pool_size'} )
6385-
. " should be equal to 25%";
6386-
push( @adjvars,
6387-
"innodb_redo_log_capacity should be (="
6388-
. hr_bytes_rnd( $myvar{'innodb_buffer_pool_size'} / 4 )
6389-
. ") if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size."
6390-
);
6391-
push( @generalrec,
6392-
"Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
6393-
);
6394-
}
6395-
else {
6396-
badprint "Ratio InnoDB log file size / InnoDB Buffer pool size ("
6397-
. $mycalc{'innodb_log_size_pct'} . "%): "
6398-
. hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
6399-
. $myvar{'innodb_log_files_in_group'} . " / "
6400-
. hr_bytes( $myvar{'innodb_buffer_pool_size'} )
6401-
. " should be equal to 25%";
6402-
push(
6403-
@adjvars,
6404-
"innodb_log_file_size should be (="
6405-
. hr_bytes_rnd(
6406-
$myvar{'innodb_buffer_pool_size'} /
6407-
$myvar{'innodb_log_files_in_group'} / 4
6408-
)
6409-
. ") if possible, so InnoDB total log file size equals 25% of buffer pool size."
6410-
);
6411-
push( @generalrec,
6412-
"Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
6413-
);
6414-
}
6415-
if ( mysql_version_le( 5, 6, 2 ) ) {
6385+
if ( defined $myvar{'innodb_redo_log_capacity'} ) {
6386+
badprint
6387+
"Ratio InnoDB redo log capacity / InnoDB Buffer pool size ("
6388+
. $mycalc{'innodb_log_size_pct'} . "%): "
6389+
. hr_bytes( $myvar{'innodb_redo_log_capacity'} ) . " / "
6390+
. hr_bytes( $myvar{'innodb_buffer_pool_size'} )
6391+
. " should be equal to 25%";
6392+
push( @adjvars,
6393+
"innodb_redo_log_capacity should be (="
6394+
. hr_bytes_rnd( $myvar{'innodb_buffer_pool_size'} / 4 )
6395+
. ") if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size."
6396+
);
6397+
push( @generalrec,
6398+
"Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
6399+
);
6400+
}
6401+
else {
6402+
badprint "Ratio InnoDB log file size / InnoDB Buffer pool size ("
6403+
. $mycalc{'innodb_log_size_pct'} . "%): "
6404+
. hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
6405+
. $myvar{'innodb_log_files_in_group'} . " / "
6406+
. hr_bytes( $myvar{'innodb_buffer_pool_size'} )
6407+
. " should be equal to 25%";
6408+
push(
6409+
@adjvars,
6410+
"innodb_log_file_size should be (="
6411+
. hr_bytes_rnd(
6412+
$myvar{'innodb_buffer_pool_size'} /
6413+
$myvar{'innodb_log_files_in_group'} / 4
6414+
)
6415+
. ") if possible, so InnoDB total log file size equals 25% of buffer pool size."
6416+
);
6417+
push( @generalrec,
6418+
"Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
6419+
);
6420+
}
6421+
if ( mysql_version_le( 5, 6, 2 ) ) {
64166422
push( @generalrec,
64176423
"For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB."
64186424
);
@@ -6533,15 +6539,17 @@ sub mysql_innodb {
65336539
. $mycalc{'pct_read_efficiency'} . "% ("
65346540
. $mystat{'Innodb_buffer_pool_read_requests'}
65356541
. " hits / "
6536-
. ( $mystat{'Innodb_buffer_pool_reads'} + $mystat{'Innodb_buffer_pool_read_requests'} )
6542+
. ( $mystat{'Innodb_buffer_pool_reads'} +
6543+
$mystat{'Innodb_buffer_pool_read_requests'} )
65376544
. " total)";
65386545
}
65396546
else {
65406547
goodprint "InnoDB Read buffer efficiency: "
65416548
. $mycalc{'pct_read_efficiency'} . "% ("
65426549
. $mystat{'Innodb_buffer_pool_read_requests'}
65436550
. " hits / "
6544-
. ( $mystat{'Innodb_buffer_pool_reads'} + $mystat{'Innodb_buffer_pool_read_requests'} )
6551+
. ( $mystat{'Innodb_buffer_pool_reads'} +
6552+
$mystat{'Innodb_buffer_pool_read_requests'} )
65456553
. " total)";
65466554
}
65476555

@@ -6557,7 +6565,7 @@ sub mysql_innodb {
65576565
. $mystat{'Innodb_log_write_requests'}
65586566
. " total)";
65596567
push( @adjvars,
6560-
"innodb_log_buffer_size (> "
6568+
"innodb_log_buffer_size (> "
65616569
. hr_bytes_rnd( $myvar{'innodb_log_buffer_size'} )
65626570
. ")" );
65636571
}
@@ -6709,20 +6717,21 @@ sub mysql_databases {
67096717
percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%";
67106718
$result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3];
67116719
print "\n" unless ( $opt{'silent'} or $opt{'json'} );
6712-
my $nbViews=0;
6713-
my $nbTables=0;
6720+
my $nbViews = 0;
6721+
my $nbTables = 0;
6722+
67146723
foreach (@dblist) {
67156724
my @dbinfo = split /\s/,
67166725
select_one(
67176726
"SELECT TABLE_SCHEMA, SUM(TABLE_ROWS), SUM(DATA_LENGTH), SUM(INDEX_LENGTH), SUM(DATA_LENGTH+INDEX_LENGTH), COUNT(DISTINCT ENGINE), COUNT(TABLE_NAME), COUNT(DISTINCT(TABLE_COLLATION)), COUNT(DISTINCT(ENGINE)) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$_' GROUP BY TABLE_SCHEMA ORDER BY TABLE_SCHEMA"
67186727
);
67196728
next unless defined $dbinfo[0];
6720-
6721-
infoprint "Database: " . $dbinfo[0] . "";
6722-
$nbTables=select_one(
6729+
6730+
infoprint "Database: " . $dbinfo[0] . "";
6731+
$nbTables = select_one(
67236732
"SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$_'"
6724-
);
6725-
infoprint " +-- TABLE : $nbTables";
6733+
);
6734+
infoprint " +-- TABLE : $nbTables";
67266735
infoprint " +-- VIEW : "
67276736
. select_one(
67286737
"SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='VIEW' AND TABLE_SCHEMA='$_'"
@@ -6778,10 +6787,10 @@ sub mysql_databases {
67786787
) . " TABLE(s)";
67796788
}
67806789

6781-
if ( $nbTables == 0 ) {
6782-
badprint " No table in $dbinfo[0] database";
6783-
next;
6784-
}
6790+
if ( $nbTables == 0 ) {
6791+
badprint " No table in $dbinfo[0] database";
6792+
next;
6793+
}
67856794
badprint "Index size is larger than data size for $dbinfo[0] \n"
67866795
if ( $dbinfo[2] ne 'NULL' )
67876796
and ( $dbinfo[3] ne 'NULL' )
@@ -6792,7 +6801,7 @@ sub mysql_databases {
67926801
. " storage engines. Be careful. \n";
67936802
push @generalrec,
67946803
"Select one storage engine (InnoDB is a good choice) for all tables in $dbinfo[0] database ($dbinfo[5] engines detected)";
6795-
}
6804+
}
67966805
$result{'Databases'}{ $dbinfo[0] }{'Rows'} = $dbinfo[1];
67976806
$result{'Databases'}{ $dbinfo[0] }{'Tables'} = $dbinfo[6];
67986807
$result{'Databases'}{ $dbinfo[0] }{'Collations'} = $dbinfo[7];
@@ -7096,12 +7105,13 @@ sub mysql_indexes {
70967105
infoprint " +-- COMMENT : " . $info[5] if defined $info[5];
70977106
$found++;
70987107
}
7099-
my $nbTables=select_one(
7108+
my $nbTables = select_one(
71007109
"SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$dbname'"
7101-
);
7102-
badprint "No index found for $dbname database" if $found == 0 and $nbTables>1;
7110+
);
7111+
badprint "No index found for $dbname database"
7112+
if $found == 0 and $nbTables > 1;
71037113
push @generalrec, "Add indexes on tables from $dbname database"
7104-
if $found == 0 and $nbTables>1;
7114+
if $found == 0 and $nbTables > 1;
71057115
}
71067116
return
71077117
unless ( defined( $myvar{'performance_schema'} )

0 commit comments

Comments
 (0)