Function cpu_count

Source
pub fn cpu_count(logical: bool) -> Option<usize>
Expand description

Return the number of CPUs in the system or None if undetermined. If the param is set to true, the result will be the number of logical CPUs, false will return the number of physical CPUs.

Examples:

// Get the number of logical CPUs.
let logical = rpsutil::cpu::cpu_count(true);

// Get the number of physical CPUs.
let physical = rpsutil::cpu::cpu_count(false);
Examples found in repository?
examples/cpu.rs (line 5)
3fn main() {
4    // --- CPU count ---
5    println!("logical cpu count: {}", cpu::cpu_count(true).unwrap());
6    println!("physical cpu count: {}", cpu::cpu_count(false).unwrap());
7
8    // --- CPU times ---
9    // system
10    println!("system: {:?}", cpu::system_time());
11    // per cpu
12    for (idx, cpu_time) in cpu::per_cpu_time().iter().enumerate() {
13        println!("cpu {}: {:?}", idx + 1, cpu_time);
14    }
15}