eminence / procfs

Rust library for reading the Linux procfs filesystem
Other
358 stars 105 forks source link

Make CpuInfo iterable #276

Open conqp opened 1 year ago

conqp commented 1 year ago

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.

eminence commented 11 months ago

Hi :wave:

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 commented 11 months ago

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