iced-yoda/winit/src/system.rs

37 lines
1.1 KiB
Rust
Raw Normal View History

//! Access the native system.
use crate::graphics::compositor;
2023-03-05 06:35:20 +01:00
use crate::runtime::system::{Action, Information};
use crate::runtime::{self, Task};
2022-04-14 11:15:54 -03:00
2022-04-27 16:18:27 -03:00
pub(crate) fn information(
graphics_info: compositor::Information,
2022-04-27 16:18:27 -03:00
) -> Information {
2024-02-01 07:15:59 -05:00
use sysinfo::{Process, System};
2022-04-14 11:15:54 -03:00
let mut system = System::new_all();
system.refresh_all();
let cpu_brand = system
.cpus()
.first()
.map(|cpu| cpu.brand().to_string())
.unwrap_or_default();
2022-04-14 11:15:54 -03:00
let memory_used = sysinfo::get_current_pid()
.and_then(|pid| system.process(pid).ok_or("Process not found"))
2024-02-01 07:15:59 -05:00
.map(Process::memory)
2022-04-14 11:15:54 -03:00
.ok();
2022-04-27 16:18:27 -03:00
Information {
2024-02-01 07:15:59 -05:00
system_name: System::name(),
system_kernel: System::kernel_version(),
system_version: System::long_os_version(),
system_short_version: System::os_version(),
cpu_brand,
2022-04-14 11:15:54 -03:00
cpu_cores: system.physical_core_count(),
memory_total: system.total_memory(),
memory_used,
graphics_adapter: graphics_info.adapter,
graphics_backend: graphics_info.backend,
2022-04-27 16:18:27 -03:00
}
2022-04-14 11:15:54 -03:00
}