Skip to content

Commit efa6494

Browse files
committed
style: tidy mysqltuner.pl
1 parent ae7f08e commit efa6494

1 file changed

Lines changed: 46 additions & 25 deletions

File tree

mysqltuner.pl

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ package main;
4343
use strict;
4444
use warnings;
4545

46-
4746
use POSIX;
4847
use File::Spec;
4948
use Getopt::Long;
@@ -927,8 +926,8 @@ sub cpu_cores {
927926
my %cores;
928927
if ( open( my $proc_cpuinfo, '<', '/proc/cpuinfo' ) ) {
929928
while (<$proc_cpuinfo>) {
930-
if ( /^physical id\s*:\s*(.*)/ ) { $cpus{$1} = 1; }
931-
if ( /^core id\s*:\s*(.*)/ ) { $cores{$1} = 1; }
929+
if (/^physical id\s*:\s*(.*)/) { $cpus{$1} = 1; }
930+
if (/^core id\s*:\s*(.*)/) { $cores{$1} = 1; }
932931
}
933932
close $proc_cpuinfo;
934933
my $cntCPU = ( scalar keys %cpus ) * ( scalar keys %cores );
@@ -951,7 +950,7 @@ sub cpu_cores {
951950
if ($is_win) {
952951
my $cntCPU =
953952
execute_system_command(
954-
'wmic cpu get NumberOfCores| perl -ne "s/[^0-9]//g; print if /[0-9]+/;"'
953+
'wmic cpu get NumberOfCores| perl -ne "s/[^0-9]//g; print if /[0-9]+/;"'
955954
);
956955
chomp $cntCPU;
957956
return $cntCPU + 0;
@@ -989,7 +988,7 @@ sub logical_cpu_cores {
989988
if ($is_win) {
990989
my $cntCPU =
991990
execute_system_command(
992-
'wmic cpu get NumberOfLogicalProcessors| perl -ne "s/[^0-9]//g; print if /[0-9]+/;"'
991+
'wmic cpu get NumberOfLogicalProcessors| perl -ne "s/[^0-9]//g; print if /[0-9]+/;"'
993992
);
994993
chomp $cntCPU;
995994
return $cntCPU + 0;
@@ -1161,8 +1160,8 @@ sub os_setup {
11611160
if ( $os =~ /Linux|CYGWIN/ ) {
11621161
if ( $prefix eq '' && open( my $meminfo, '<', '/proc/meminfo' ) ) {
11631162
while (<$meminfo>) {
1164-
if (/^MemTotal:\s+(\d+)/i) { $physical_memory = $1 * 1024; }
1165-
if (/^SwapTotal:\s+(\d+)/i) { $swap_memory = $1 * 1024; }
1163+
if (/^MemTotal:\s+(\d+)/i) { $physical_memory = $1 * 1024; }
1164+
if (/^SwapTotal:\s+(\d+)/i) { $swap_memory = $1 * 1024; }
11661165
}
11671166
close $meminfo;
11681167
}
@@ -1643,8 +1642,11 @@ sub mysql_setup {
16431642
$defaults_options = "--defaults-file=\"$opt{'defaults-file'}\"";
16441643
debugprint "Using defaults-file: $opt{'defaults-file'}";
16451644
}
1646-
elsif ( ( $opt{'defaults-extra-file'} // '0' ) ne '0' && -r $opt{'defaults-extra-file'} ) {
1647-
$defaults_options = "--defaults-extra-file=\"$opt{'defaults-extra-file'}\"";
1645+
elsif ( ( $opt{'defaults-extra-file'} // '0' ) ne '0'
1646+
&& -r $opt{'defaults-extra-file'} )
1647+
{
1648+
$defaults_options =
1649+
"--defaults-extra-file=\"$opt{'defaults-extra-file'}\"";
16481650
debugprint "Using defaults-extra-file: $opt{'defaults-extra-file'}";
16491651
}
16501652

@@ -1734,7 +1736,8 @@ sub mysql_setup {
17341736
if ( ( $ENV{MARIADB_ROOT_PASSWORD} // '' ) ne ''
17351737
|| ( $ENV{MYSQL_ROOT_PASSWORD} // '' ) ne '' )
17361738
{
1737-
$opt{pass} = $ENV{MARIADB_ROOT_PASSWORD} || $ENV{MYSQL_ROOT_PASSWORD};
1739+
$opt{pass} =
1740+
$ENV{MARIADB_ROOT_PASSWORD} || $ENV{MYSQL_ROOT_PASSWORD};
17381741
debugprint "Detected password from container environment";
17391742
}
17401743
}
@@ -1854,8 +1857,9 @@ sub mysql_setup {
18541857
}
18551858
}
18561859
elsif ( $defaults_options ne '' ) {
1860+
18571861
# defaults-file or defaults-extra-file
1858-
$mysqllogin = "$defaults_options $remotestring";
1862+
$mysqllogin = "$defaults_options $remotestring";
18591863
my $loginstatus =
18601864
execute_system_command("$mysqladmincmd $mysqllogin ping");
18611865
if ( $loginstatus =~ /mysqld is alive/ ) {
@@ -2795,7 +2799,7 @@ sub get_process_memory {
27952799
if ( $line =~ /^\d+\s+(\d+)/ ) {
27962800
my $rss_pages = $1;
27972801

2798-
# Get page size (default to 4096 if uncertain, but usually 4096 on Linux)
2802+
# Get page size (default to 4096 if uncertain, but usually 4096 on Linux)
27992803
my $pagesize = POSIX::sysconf(POSIX::_SC_PAGESIZE) || 4096;
28002804
debugprint "Memory for PID $pid from /proc: "
28012805
. ( $rss_pages * $pagesize );
@@ -2963,7 +2967,7 @@ sub is_virtual_machine {
29632967
if ( $prefix eq '' && open( my $cpuinfo, '<', '/proc/cpuinfo' ) ) {
29642968
my $isVm = 0;
29652969
while (<$cpuinfo>) {
2966-
if ( /^flags.*\ hypervisor / ) { $isVm = 1; last; }
2970+
if (/^flags.*\ hypervisor /) { $isVm = 1; last; }
29672971
}
29682972
close $cpuinfo;
29692973
return $isVm;
@@ -3150,16 +3154,22 @@ sub get_system_info {
31503154
}
31513155

31523156
$result{'OS'}{'Type'} =
3153-
$is_win ? 'Windows' : ( $prefix eq '' ? $sysname : execute_system_command('uname -o') );
3157+
$is_win
3158+
? 'Windows'
3159+
: ( $prefix eq '' ? $sysname : execute_system_command('uname -o') );
31543160
infoprint "Operating System Type : "
3155-
. ( $is_win ? 'Windows' : ( $prefix eq '' ? $sysname : execute_system_command('uname -o') ) );
3161+
. ( $is_win
3162+
? 'Windows'
3163+
: ( $prefix eq '' ? $sysname : execute_system_command('uname -o') ) );
31563164

31573165
$result{'OS'}{'Kernel'} =
31583166
$is_win
31593167
? execute_system_command('ver')
31603168
: ( $prefix eq '' ? $release : execute_system_command('uname -r') );
31613169
infoprint "Kernel Release : "
3162-
. ( $is_win ? execute_system_command('ver') : ( $prefix eq '' ? $release : execute_system_command('uname -r') ) );
3170+
. ( $is_win
3171+
? execute_system_command('ver')
3172+
: ( $prefix eq '' ? $release : execute_system_command('uname -r') ) );
31633173

31643174
$result{'OS'}{'Hostname'} =
31653175
( !$is_win && $prefix eq '' ) ? $nodename : Sys::Hostname::hostname();
@@ -3170,7 +3180,9 @@ sub get_system_info {
31703180
'ipconfig |perl -ne "if (/IPv. Address/) {print s/^.*?([\\d\\.]*)\\s*$/$1/r; exit; }"'
31713181
)
31723182
: execute_system_command('hostname -I');
3173-
infoprint "Hostname : " . ( ( !$is_win && $prefix eq '' ) ? $nodename : Sys::Hostname::hostname() );
3183+
infoprint "Hostname : "
3184+
. (
3185+
( !$is_win && $prefix eq '' ) ? $nodename : Sys::Hostname::hostname() );
31743186
infoprint "Network Cards : ";
31753187

31763188
if ( which( "ip", $ENV{'PATH'} ) ) {
@@ -3179,7 +3191,10 @@ sub get_system_info {
31793191
elsif ( which( "ifconfig", $ENV{'PATH'} ) ) {
31803192
infocmd_tab "ifconfig| grep -A1 mtu";
31813193
}
3182-
infoprint "Internal IP : " . ( ( !$is_win && $prefix eq '' ) ? execute_system_command('hostname -I') : infocmd_one "hostname -I" );
3194+
infoprint "Internal IP : "
3195+
. ( ( !$is_win && $prefix eq '' )
3196+
? execute_system_command('hostname -I')
3197+
: infocmd_one "hostname -I" );
31833198
if ( which( "ip", $ENV{'PATH'} ) ) {
31843199
$result{'Network'}{'Internal Ip'} =
31853200
execute_system_command('ip addr | grep -A1 mtu');
@@ -3197,7 +3212,8 @@ sub get_system_info {
31973212
$ext_ip = infocmd_one "$httpcli -s -m 3 ipecho.net/plain";
31983213
}
31993214
elsif ( $httpcli =~ /wget$/ ) {
3200-
$ext_ip = infocmd_one "$httpcli -q -t 1 -T 3 -q -O - ipecho.net/plain";
3215+
$ext_ip =
3216+
infocmd_one "$httpcli -q -t 1 -T 3 -q -O - ipecho.net/plain";
32013217
}
32023218
}
32033219
infoprint "External IP : " . $ext_ip;
@@ -3215,7 +3231,8 @@ sub get_system_info {
32153231
$ns_str = join( ', ', @ns_list );
32163232
}
32173233
else {
3218-
$ns_str = infocmd_one "grep 'nameserver' /etc/resolv.conf \| awk '{print \$2}'";
3234+
$ns_str =
3235+
infocmd_one "grep 'nameserver' /etc/resolv.conf \| awk '{print \$2}'";
32193236
}
32203237
infoprint "Name Servers : " . $ns_str;
32213238

@@ -3901,7 +3918,7 @@ sub check_architecture {
39013918
$arch = $opt{defaultarch};
39023919
return;
39033920
}
3904-
elsif ( $is_win ) {
3921+
elsif ($is_win) {
39053922
if ( execute_system_command('wmic os get osarchitecture') =~ /64/ ) {
39063923
goodprint "Operating on 64-bit architecture";
39073924
$arch = 64;
@@ -3910,7 +3927,8 @@ sub check_architecture {
39103927
else {
39113928
my ( $sysname, $nodename, $release, $version, $machine );
39123929
if ( $prefix eq '' ) {
3913-
( $sysname, $nodename, $release, $version, $machine ) = POSIX::uname();
3930+
( $sysname, $nodename, $release, $version, $machine ) =
3931+
POSIX::uname();
39143932
}
39153933
else {
39163934
$sysname = execute_system_command('uname');
@@ -3942,12 +3960,14 @@ sub check_architecture {
39423960
}
39433961
}
39443962
elsif ( $sysname =~ /Darwin/ && $machine =~ /Power Macintosh/ ) {
3945-
# Darwin box.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu1228.15.4~1/RELEASE_PPC Power Macintosh
3963+
3964+
# Darwin box.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu1228.15.4~1/RELEASE_PPC Power Macintosh
39463965
$arch = 64;
39473966
goodprint "Operating on 64-bit architecture";
39483967
}
39493968
elsif ( $sysname =~ /Darwin/ && $machine =~ /x86_64/ ) {
3950-
# Darwin gibas.local 12.6.0 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
3969+
3970+
# Darwin gibas.local 12.6.0 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
39513971
$arch = 64;
39523972
goodprint "Operating on 64-bit architecture";
39533973
}
@@ -3962,7 +3982,8 @@ sub check_architecture {
39623982
"Switch to 64-bit OS - MySQL cannot currently use all of your RAM";
39633983
}
39643984
else {
3965-
goodprint "Operating on 32-bit architecture with less than 2GB RAM";
3985+
goodprint
3986+
"Operating on 32-bit architecture with less than 2GB RAM";
39663987
}
39673988
}
39683989
}

0 commit comments

Comments
 (0)