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

Integrate FidryCpuCoreCounter #2047

Merged
merged 1 commit into from Dec 11, 2022

Conversation

theofidry
Copy link
Contributor

See theofidry/cpu-core-counter#11 for the motivations.

The code should be sensibly the same, the notable differences are:

  • fixed the deprecated usage of hw.ncpu
  • /proc/cpuinfo is check last
  • nproc is checked first (before was not checked at all, it's considered to be more accurate and less convoluted than cpuinfo though)
  • not sure about the return 2, but this was not too clear here neither. I could otherwise change the fallback value to return 1 if proc_open doesn't exist and 2 otherwise

I would also wait on 1.x before merging this if you're happy with it. Technically the current version is fine, I'm just looking for a round of feedback before publishing 1.0.

@ondrejmirtes
Copy link
Member

One idea I have - it should differentiate between physical and virtual cores, offer different getters for that. That'd be really valuable. I want to use the virtual cores, no matter the operating system.

I understand that on systems with hyperthreading, virtual cores = 2 * physical cores. The CPU wouldn't be fully utilized if I used only the physical cores.

But of course it might be more complicated, I'm not a hardware expert.

@ondrejmirtes
Copy link
Member

And if PHPStan should be able to use this library, right now it needs to support PHP 7.2+.

@theofidry
Copy link
Contributor Author

@ondrejmirtes should be good; there is now a distinction possible between physical and logical cores. The default picked is logical (as PHP source does and as was done previously here).

If you fancy checking out what finder finds what, to find a bug or play around with the order or something, I can recommend those commands

@ondrejmirtes
Copy link
Member

I really like your work, the library looks nice!

But it looks like there's a related failure: https://github.com/phpstan/phpstan-src/actions/runs/3647730351/jobs/6160310175

src/Process/CpuCoreCounter.php Outdated Show resolved Hide resolved
@theofidry
Copy link
Contributor Author

Indeed and the failure is related I think. It's curious though as this is a piece of code coming from Infection and I thought I tested the case where the commands would fail... will look into it, but will probably have to rely on the CI here for that, at least partially

@theofidry
Copy link
Contributor Author

Nevermind it's windows related, I'll be able to check that on a machine at home soon :)

@theofidry
Copy link
Contributor Author

@ondrejmirtes green

@ondrejmirtes
Copy link
Member

See theofidry/cpu-core-counter#11 for the motivations.

The code should be sensibly the same, the notable differences are:

- fixed the deprecated usage of `hw.ncpu`
- /proc/cpuinfo is check _last_
- nproc is checked first (before was not checked at all, it's considered to be more accurate and less convoluted than cpuinfo though)
- not sure about the `return 2`, but this was not too clear [here](phpstan#514 (review)) neither. I could otherwise change the fallback value to return `1` if `proc_open` doesn't exist and 2 otherwise
- add more ways to find the CPU cores count
@theofidry
Copy link
Contributor Author

@ondrejmirtes FINALLY it is green

@ondrejmirtes
Copy link
Member

Nice :) Please definitely be ready for a round of feedback once this is released, maybe we broke some scenario that isn't in the test suite, but that's fine, it's an "unknown unknown", so if we learn about it, the better :)

@ondrejmirtes ondrejmirtes merged commit 323451a into phpstan:1.9.x Dec 11, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@theofidry theofidry deleted the featuer/cpu-core-counter branch December 11, 2022 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants