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

Add NProcessor based finders #67

Merged
merged 1 commit into from
Dec 7, 2022
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
2 changes: 2 additions & 0 deletions src/Finder/FinderRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static function getAllVariants(): array
new DummyCpuCoreFinder(1),
new HwLogicalFinder(),
new HwPhysicalFinder(),
new LinuxyNProcessorFinder(),
new NProcessorFinder(),
new NProcFinder(true),
new NProcFinder(false),
new NullCpuCoreFinder(),
Expand Down
27 changes: 27 additions & 0 deletions src/Finder/LinuxyNProcessorFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Fidry CPUCounter Config package.
*
* (c) Théo FIDRY <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Fidry\CpuCoreCounter\Finder;

/**
* Find the number of logical CPU cores for Linux and the likes.
*
* @see https://twitter.com/freebsdfrau/status/1052016199452700678?s=20&t=M2pHkRqmmna-UF68lfL2hw
*/
final class LinuxyNProcessorFinder extends PopenBasedFinder
{
protected function getCommand(): string
{
return 'getconf _NPROCESSORS_ONLN';
}
}
27 changes: 27 additions & 0 deletions src/Finder/NProcessorFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Fidry CPUCounter Config package.
*
* (c) Théo FIDRY <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Fidry\CpuCoreCounter\Finder;

/**
* Find the number of logical CPU cores for FreeSBD, Solaris and the likes.
*
* @see https://twitter.com/freebsdfrau/status/1052016199452700678?s=20&t=M2pHkRqmmna-UF68lfL2hw
*/
final class NProcessorFinder extends PopenBasedFinder
{
protected function getCommand(): string
{
return 'getconf NPROCESSORS_ONLN';
}
}
35 changes: 35 additions & 0 deletions tests/Finder/LinuxyNProcessorFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Fidry CPUCounter Config package.
*
* (c) Théo FIDRY <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Fidry\CpuCoreCounter\Test\Finder;

use Fidry\CpuCoreCounter\Finder\LinuxyNProcessorFinder;
use Fidry\CpuCoreCounter\Finder\PopenBasedFinder;

/**
* @covers \Fidry\CpuCoreCounter\Finder\LinuxyNProcessorFinder
*
* @internal
*/
final class LinuxyNProcessorFinderTest extends PopenBasedFinderTestCase
{
public function test_it_can_describe_itself(): void
{
self::assertSame('LinuxyNProcessorFinder', $this->getFinder()->toString());
}

protected function getFinder(): PopenBasedFinder
{
return new LinuxyNProcessorFinder();
}
}
35 changes: 35 additions & 0 deletions tests/Finder/NProcessorFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Fidry CPUCounter Config package.
*
* (c) Théo FIDRY <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Fidry\CpuCoreCounter\Test\Finder;

use Fidry\CpuCoreCounter\Finder\NProcessorFinder;
use Fidry\CpuCoreCounter\Finder\PopenBasedFinder;

/**
* @covers \Fidry\CpuCoreCounter\Finder\NProcessorFinder
*
* @internal
*/
final class NProcessorFinderTest extends PopenBasedFinderTestCase
{
public function test_it_can_describe_itself(): void
{
self::assertSame('NProcessorFinder', $this->getFinder()->toString());
}

protected function getFinder(): PopenBasedFinder
{
return new NProcessorFinder();
}
}