Debian Codegraph @

src/collection/cpu/sysinfo.rs

raw symbols SCIP
1 //! CPU stats through sysinfo.
2
3 use superrust-analyzer cargo bottom 0.14.9 collection/cpu/::{CpuDatarust-analyzer cargo bottom 0.14.9 collection/cpu/CpuData#, CpuDataTyperust-analyzer cargo bottom 0.14.9 collection/cpu/CpuDataType#, CpuHarvestrust-analyzer cargo bottom 0.14.9 collection/cpu/CpuHarvest#};
4 use craterust-analyzer cargo bottom 0.14.9 crate/::collectionrust-analyzer cargo bottom 0.14.9 collection/::{DataCollectorrust-analyzer cargo bottom 0.14.9 collection/DataCollector#, errorrust-analyzer cargo bottom 0.14.9 collection/error/::CollectionResultrust-analyzer cargo bottom 0.14.9 collection/error/CollectionResult#};
5
6 pub fn get_cpu_data_listrust-analyzer cargo bottom 0.14.9 collection/cpu/sysinfo/get_cpu_data_list().(collector: &DataCollectorrust-analyzer cargo bottom 0.14.9 collection/DataCollector#) -> CollectionResultrust-analyzer cargo bottom 0.14.9 collection/error/CollectionResult#<CpuHarvestrust-analyzer cargo bottom 0.14.9 collection/cpu/CpuHarvest#> {
7 let sys = &collector.sysrust-analyzer cargo bottom 0.14.9 collection/DataCollector#sys..systemrust-analyzer cargo bottom 0.14.9 collection/SysinfoSource#system.;
8 let show_average_cpu = collector.show_average_cpurust-analyzer cargo bottom 0.14.9 collection/DataCollector#show_average_cpu.;
9
10 let mut cpus = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
11
12 if show_average_cpu {
13 cfg_selectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/cfg_select!! {
14 target_os = "linux" => {
15 cpus.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(CpuDatarust-analyzer cargo bottom 0.14.9 collection/cpu/CpuData# {
16 data_typerust-analyzer cargo bottom 0.14.9 collection/cpu/CpuData#data_type.: CpuDataTyperust-analyzer cargo bottom 0.14.9 collection/cpu/CpuDataType#::Avgrust-analyzer cargo bottom 0.14.9 collection/cpu/CpuDataType#Avg#,
17 usagerust-analyzer cargo bottom 0.14.9 collection/cpu/CpuData#usage.: collector.cgroup_cpu_datarust-analyzer cargo bottom 0.14.9 collection/DataCollector#cgroup_cpu_data..avg_cpu_percentrust-analyzer cargo bottom 0.14.9 collection/linux/cgroups/CgroupCpuCollector#avg_cpu_percent..unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| sys.global_cpu_usagerust-analyzer cargo sysinfo 0.39.6 common/system/impl#[System]global_cpu_usage().()),
18 });
19 }
20 _ => {
21 cpus.push(CpuData {
22 data_type: CpuDataType::Avg,
23 usage: sys.global_cpu_usage(),
24 })
25 }
26 }
27 }
28
29 cpus.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(
30 sys.cpusrust-analyzer cargo sysinfo 0.39.6 common/system/impl#[System]cpus().()
31 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
32 .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().()
33 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, cpu)| CpuDatarust-analyzer cargo bottom 0.14.9 collection/cpu/CpuData# {
34 data_typerust-analyzer cargo bottom 0.14.9 collection/cpu/CpuData#data_type.: CpuDataTyperust-analyzer cargo bottom 0.14.9 collection/cpu/CpuDataType#::Cpurust-analyzer cargo bottom 0.14.9 collection/cpu/CpuDataType#Cpu#(i),
35 usagerust-analyzer cargo bottom 0.14.9 collection/cpu/CpuData#usage.: cpu.cpu_usagerust-analyzer cargo sysinfo 0.39.6 common/system/impl#[Cpu]cpu_usage().(),
36 })
37 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(),
38 );
39
40 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(cpus)
41 }
42
43 #[cfg(unix)]
44 pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn get_load_avgrust-analyzer cargo bottom 0.14.9 collection/cpu/sysinfo/get_load_avg().() -> craterust-analyzer cargo bottom 0.14.9 crate/::collectionrust-analyzer cargo bottom 0.14.9 collection/::cpurust-analyzer cargo bottom 0.14.9 collection/cpu/::LoadAvgHarvestrust-analyzer cargo bottom 0.14.9 collection/cpu/LoadAvgHarvest# {
45 // The API for sysinfo apparently wants you to call it like this, rather than
46 // using a &System.
47 let sysinforust-analyzer cargo sysinfo 0.39.6 crate/::LoadAvgrust-analyzer cargo sysinfo 0.39.6 common/system/LoadAvg# { onerust-analyzer cargo sysinfo 0.39.6 common/system/LoadAvg#one., fiverust-analyzer cargo sysinfo 0.39.6 common/system/LoadAvg#five., fifteenrust-analyzer cargo sysinfo 0.39.6 common/system/LoadAvg#fifteen. } = sysinforust-analyzer cargo sysinfo 0.39.6 crate/::Systemrust-analyzer cargo sysinfo 0.39.6 common/system/System#::load_averagerust-analyzer cargo sysinfo 0.39.6 common/system/impl#[System]load_average().();
48
49 [one as f32, five as f32, fifteen as f32]
50 }