Skip to content

Commit

Permalink
fix: Display threads and not cores
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Aug 12, 2024
1 parent d1384c2 commit dd38673
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/OperatingSystems/FreeBSD.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,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;
Expand Down
8 changes: 4 additions & 4 deletions lib/OperatingSystems/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,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;
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/LinuxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,39 @@ 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 {
$this->os->method('readContent')
->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 {
$this->os->method('readContent')
->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 {
$this->os->method('readContent')
->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 {
$this->os->method('readContent')
->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 {
Expand Down

0 comments on commit dd38673

Please sign in to comment.