Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] fix: Display threads and not cores #660

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/OperatingSystems/FreeBSD.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/OperatingSystems/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/LinuxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,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
Loading