From adaed7a3359cbf71d49a3b3eff566d4c23a0ae4e Mon Sep 17 00:00:00 2001 From: provokateurin Date: Mon, 12 Aug 2024 13:58:30 +0200 Subject: [PATCH] fix: Display threads and not cores Signed-off-by: provokateurin --- lib/OperatingSystems/FreeBSD.php | 8 ++++---- lib/OperatingSystems/Linux.php | 8 ++++---- tests/lib/LinuxTest.php | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/OperatingSystems/FreeBSD.php b/lib/OperatingSystems/FreeBSD.php index 23428ff9..b45fee85 100644 --- a/lib/OperatingSystems/FreeBSD.php +++ b/lib/OperatingSystems/FreeBSD.php @@ -78,12 +78,12 @@ public function getCpuName(): string { try { $model = $this->executeCommand('/sbin/sysctl -n hw.model'); - $cores = $this->executeCommand('/sbin/sysctl -n kern.smp.cpus'); + $threads = $this->executeCommand('/sbin/sysctl -n kern.smp.cpus'); - if ((int)$cores === 1) { - $data = $model . ' (1 core)'; + if ((int)$threads === 1) { + $data = $model . ' (1 thread)'; } else { - $data = $model . ' (' . $cores . ' cores)'; + $data = $model . ' (' . $threads . ' threads)'; } } catch (RuntimeException $e) { return $data; diff --git a/lib/OperatingSystems/Linux.php b/lib/OperatingSystems/Linux.php index 740ad9ae..46d367c4 100644 --- a/lib/OperatingSystems/Linux.php +++ b/lib/OperatingSystems/Linux.php @@ -109,12 +109,12 @@ public function getCpuName(): string { $pattern = '/processor\s+:\s(.+)/'; preg_match_all($pattern, $cpuinfo, $matches); - $cores = count($matches[1]); + $threads = count($matches[1]); - if ($cores === 1) { - $data = $model . ' (1 core)'; + if ($threads === 1) { + $data = $model . ' (1 thread)'; } else { - $data = $model . ' (' . $cores . ' cores)'; + $data = $model . ' (' . $threads . ' threads)'; } return $data; diff --git a/tests/lib/LinuxTest.php b/tests/lib/LinuxTest.php index 27a72c6c..7c5d431d 100644 --- a/tests/lib/LinuxTest.php +++ b/tests/lib/LinuxTest.php @@ -85,7 +85,7 @@ public function testGetCpuName(): void { ->with('/proc/cpuinfo') ->willReturn(file_get_contents(__DIR__ . '/../data/linux_cpuinfo')); - $this->assertEquals('Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (4 cores)', $this->os->getCpuName()); + $this->assertEquals('Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (4 threads)', $this->os->getCpuName()); } public function testGetCpuNameOneCore(): void { @@ -93,7 +93,7 @@ public function testGetCpuNameOneCore(): void { ->with('/proc/cpuinfo') ->willReturn(file_get_contents(__DIR__ . '/../data/linux_cpuinfo_one_core')); - $this->assertEquals('Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (1 core)', $this->os->getCpuName()); + $this->assertEquals('Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (1 thread)', $this->os->getCpuName()); } public function testGetCpuNamePi3b(): void { @@ -101,7 +101,7 @@ public function testGetCpuNamePi3b(): void { ->with('/proc/cpuinfo') ->willReturn(file_get_contents(__DIR__ . '/../data/linux_cpuinfo_pi3b')); - $this->assertEquals('Raspberry Pi 3 Model B Rev 1.2 (4 cores)', $this->os->getCpuName()); + $this->assertEquals('Raspberry Pi 3 Model B Rev 1.2 (4 threads)', $this->os->getCpuName()); } public function testGetCpuNamePi4b(): void { @@ -109,7 +109,7 @@ public function testGetCpuNamePi4b(): void { ->with('/proc/cpuinfo') ->willReturn(file_get_contents(__DIR__ . '/../data/linux_cpuinfo_pi4b')); - $this->assertEquals('Raspberry Pi 4 Model B Rev 1.2 (4 cores)', $this->os->getCpuName()); + $this->assertEquals('Raspberry Pi 4 Model B Rev 1.2 (4 threads)', $this->os->getCpuName()); } public function testGetCpuNameOpenPower(): void { @@ -117,7 +117,7 @@ public function testGetCpuNameOpenPower(): void { ->with('/proc/cpuinfo') ->willReturn(file_get_contents(__DIR__ . '/../data/linux_cpuinfo_openpower')); - $this->assertEquals('POWER9, altivec supported (176 cores)', $this->os->getCpuName()); + $this->assertEquals('POWER9, altivec supported (176 threads)', $this->os->getCpuName()); } public function testGetCpuNameNoData(): void {