workhorsy / py-cpuinfo

A module for getting CPU info with pure Python
MIT License
312 stars 59 forks source link

Add sources kwarg/flag #195

Open jacobtomlinson opened 1 year ago

jacobtomlinson commented 1 year ago

Potential workaround for #155 by allowing you to specify which sources to use when collecting data.

# Example of removing the slow CPUID source in Python
from cpuinfo import get_cpu_info, SOURCES

SOURCES.remove("CPUID")
info = get_cpu_info(sources=SOURCES)

or

$ # Example using just a few sources via the CLI flag 
$ python -m cpuinfo --sources LSCPU,PROC_CPUINFO,DMESG
Python Version: 3.9.15.final.0 (64 bit)
Cpuinfo Version: 9.0.0
Vendor ID Raw: GenuineIntel
...

Benchmarks


$ # With CPUID
$ time python -m cpuinfo --sources WMIC,REGISTRY,PROC_CPUINFO,CPUFREQ_INFO,LSCPU,SYSCTL,KSTAT,DMESG,DMESG_BOOT,LSPROP,SYSINFO,UNAME,CPUID > /dev/null
python -m cpuinfo --sources  > /dev/null  1.07s user 0.12s system 101% cpu 1.173 total

$ # Without CPUID
$ time python -m cpuinfo --sources WMIC,REGISTRY,PROC_CPUINFO,CPUFREQ_INFO,LSCPU,SYSCTL,KSTAT,DMESG,DMESG_BOOT,LSPROP,SYSINFO,UNAME > /dev/null      
python -m cpuinfo --sources  > /dev/null  0.10s user 0.02s system 80% cpu 0.149 total