Skip to content

Commit 7fb353f

Browse files
authored
Merge pull request major#310 from emphazer/patch-1
Check whether hyperthreading is enabled or not.
2 parents e44c29b + b7e1a99 commit 7fb353f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

mysqltuner.pl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ sub infoprinthcmd {
300300
infoprintcmd "$_[1]";
301301
}
302302

303+
# Calculates the number of phyiscal cores considering HyperThreading
304+
sub cpu_cores {
305+
my $cntCPU = `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+
303309
# Calculates the parameter passed in bytes, then rounds it to one decimal place
304310
sub hr_bytes {
305311
my $num = shift;
@@ -1518,8 +1524,8 @@ sub get_system_info {
15181524
else {
15191525
badprint "Internet : Disconnected";
15201526
}
1521-
$result{'OS'}{'NbCore'} = `nproc`;
1522-
infoprint "Number of Core CPU : " . `nproc`;
1527+
$result{'OS'}{'NbCore'} = cpu_cores;
1528+
infoprint "Number of Core CPU : " . cpu_cores;
15231529
$result{'OS'}{'Type'} = `uname -o`;
15241530
infoprint "Operating System Type : " . infocmd_one "uname -o";
15251531
$result{'OS'}{'Kernel'} = `uname -r`;
@@ -5048,8 +5054,8 @@ sub mariadb_galera {
50485054
having sum(if(c.column_key in ('PRI','UNI'), 1,0)) = 0"
50495055
);
50505056

5051-
if ( get_wsrep_option('wsrep_slave_threads') > `nproc` * 4
5052-
or get_wsrep_option('wsrep_slave_threads') < `nproc` * 3 )
5057+
if ( get_wsrep_option('wsrep_slave_threads') > cpu_cores * 4
5058+
or get_wsrep_option('wsrep_slave_threads') < cpu_cores * 3 )
50535059
{
50545060
badprint
50555061
"wsrep_slave_threads is not equal to 3 or 4 times number of CPU(s)";

0 commit comments

Comments
 (0)