psutil module?In Python, psutil (Python system and process utilities) is a Python package that retrieves information on ongoing processes and system usage (CPU, memory, storage, network, and sensors). It is mostly used for system monitoring, profiling, restricting process resources, and process management.
The module can be installed via pip, as follows:
pip install psutil
cpu_freq methodThe cpu_freq method returns the CPU frequency as a named tuple with the following attributes:
current: This represents the current CPU frequency.min: This represents the minimum CPU frequency.max: This represents the maximum CPU frequency.All attributes above are reported in Mhz. If min and max values cannot be determined, they are set to zero.
psutil.cpu_freq(percpu=False)
percpu: We use this if the system supports the per-CPU frequency. Setting percpu to True makes the method return the CPU frequency of every CPU.The method has no parameters.
import psutilprint("The CPU frequency of the current CPU:")print(psutil.cpu_freq())print("The CPU frequency of all the CPUs:")print(psutil.cpu_freq(True))
psutil module.