Skip to content

Commit 213211a

Browse files
committed
improve FreeBSD support a bit (patch included) major#549
1 parent 52d3fc4 commit 213211a

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

mysqltuner.pl

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env perl
2-
# mysqltuner.pl - Version 1.7.27
2+
# mysqltuner.pl - Version 1.7.28
33
# High Performance MySQL Tuning Script
44
# Copyright (C) 2006-2021 Major Hayden - major@mhtx.net
55
#
@@ -56,7 +56,7 @@ package main;
5656
#use Env;
5757

5858
# Set up a few variables for use in the script
59-
my $tunerversion = "1.7.27";
59+
my $tunerversion = "1.7.28";
6060
my ( @adjvars, @generalrec );
6161

6262
# Set defaults
@@ -300,9 +300,18 @@ sub infoprinthcmd {
300300

301301
# Calculates the number of physical cores considering HyperThreading
302302
sub cpu_cores {
303-
my $cntCPU =
304-
`awk -F: '/^core id/ && !P[\$2] { CORES++; P[\$2]=1 }; /^physical id/ && !N[\$2] { CPUs++; N[\$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo`;
305-
return ( $cntCPU == 0 ? `nproc` : $cntCPU );
303+
if ($^O eq 'linux') {
304+
my $cntCPU =
305+
`awk -F: '/^core id/ && !P[\$2] { CORES++; P[\$2]=1 }; /^physical id/ && !N[\$2] { CPUs++; N[\$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo`;
306+
return ( $cntCPU == 0 ? `nproc` : $cntCPU );
307+
}
308+
309+
if ($^O eq 'freebsd') {
310+
my $cntCPU = `sysctl -n kern.smp.cores`;
311+
chomp $cntCPU;
312+
return $cntCPU + 0;
313+
}
314+
return 0;
306315
}
307316

308317
# Calculates the parameter passed in bytes, then rounds it to one decimal place
@@ -1169,7 +1178,7 @@ sub get_all_vars {
11691178
debugprint Dumper(@mysqlenginelist);
11701179

11711180
my @mysqlslave;
1172-
if ($mysqlvermajor eq 8 or ($mysqlvermajor eq 10 and $mysqlverminor ge 5)) {
1181+
if ( mysql_version_eq( 8 ) or mysql_version_ge( 10, 5 ) ) {
11731182
@mysqlslave = select_array("SHOW SLAVE STATUS\\G");
11741183
} else {
11751184
@mysqlslave = select_array("SHOW REPLICA STATUS\\G");
@@ -1178,7 +1187,7 @@ sub get_all_vars {
11781187
$result{'Replication'}{'Status'} = \%myrepl;
11791188

11801189
my @mysqlslaves;
1181-
if ( $mysqlvermajor eq 8 or ($mysqlvermajor eq 10 and $mysqlverminor ge 5) ) {
1190+
if ( mysql_version_eq( 8 ) or mysql_version_ge( 10, 5 ) ) {
11821191
@mysqlslaves= select_array "SHOW SLAVE HOSTS";
11831192
} else {
11841193
@mysqlslaves = select_array("SHOW SLAVE STATUS\\G");
@@ -1578,9 +1587,19 @@ sub merge_hash {
15781587
}
15791588

15801589
sub is_virtual_machine {
1581-
my $isVm = `grep -Ec '^flags.*\ hypervisor\ ' /proc/cpuinfo`;
1582-
return ( $isVm == 0 ? 0 : 1 );
1583-
}
1590+
if ($^O eq 'linux') {
1591+
my $isVm = `grep -Ec '^flags.*\ hypervisor\ ' /proc/cpuinfo`;
1592+
return ( $isVm == 0 ? 0 : 1 );
1593+
}
1594+
1595+
if ($^O eq 'freebsd') {
1596+
my $isVm = `sysctl -n kern.vm_guest`;
1597+
chomp $isVm;
1598+
print "FARK DEBUG isVm=[$isVm]";
1599+
return ( $isVm eq 'none' ? 0 : 1);
1600+
}
1601+
return 0;
1602+
}
15841603

15851604
sub infocmd {
15861605
my $cmd = "@_";
@@ -6511,7 +6530,7 @@ sub which {
65116530
65126531
=head1 NAME
65136532
6514-
MySQLTuner 1.7.27 - MySQL High Performance Tuning Script
6533+
MySQLTuner 1.7.28 - MySQL High Performance Tuning Script
65156534
65166535
=head1 IMPORTANT USAGE GUIDELINES
65176536

0 commit comments

Comments
 (0)