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

Make CpuInfo iterable #276

Open
conqp opened this issue Jul 3, 2023 · 2 comments · May be fixed by #277
Open

Make CpuInfo iterable #276

conqp opened this issue Jul 3, 2023 · 2 comments · May be fixed by #277

Comments

@conqp
Copy link

conqp commented Jul 3, 2023

I have a use case where I want to check all cores in /proc/cpuinfo for certain properties.
While it is currently possible to iterate over the cores by iterating over the range of CPUs and then accessing each one with the respective getter functions that take the index, this is very ugly and cumbersome.

Hence, I suggest to implement an iterator for CpuInfo that yields structs representing information of the respective core.

conqp pushed a commit to conqp/procfs that referenced this issue Jul 3, 2023
@conqp conqp linked a pull request Jul 3, 2023 that will close this issue
@eminence
Copy link
Owner

Hi 👋

Sorry, I'm not quite understanding your use-case, and why it's cumbersome with the current API. Can you elaborate? It's not obvious to me why iterating over CpuInfo is better than iterating over the CpuInfo.cpus

@conqp
Copy link
Author

conqp commented Aug 18, 2023

Iterating over the public Vec CpuInfo.cpus's values will only yield raw HashMap<String, String>s instead of objects that have parsed properties of the actual CPU core.
As I want to be able to e.g. access core.model_name() for each core, I cannot do this with your current API, since CpuInfo.model_name() currently requires the passing of the index of the desired core, in which case I did not have to iterate in the first place, but would have to check CpuInfo.cpus's length and iterate over an appropriate range to call CpuInfo.model_name() on each and every index.
Anyhow, I meanwhile wrote an own crate, that fits my needs: https://github.com/conqp/proc_cpuinfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants