Skip to content

Commit

Permalink
Add NProcessor based finders (#67)
Browse files Browse the repository at this point in the history
Closes #58
  • Loading branch information
theofidry authored Dec 7, 2022
1 parent 1bd4c79 commit 1513193
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
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();
}
}

0 comments on commit 1513193

Please sign in to comment.