2022-03-10 01:56:25 -03:00
|
|
|
//! Access the native system.
|
2023-03-04 05:37:11 +01:00
|
|
|
use crate::graphics::compositor;
|
2023-03-05 06:35:20 +01:00
|
|
|
use crate::runtime::system::{Action, Information};
|
2024-06-14 01:47:39 +02:00
|
|
|
use crate::runtime::{self, Task};
|
2022-04-14 11:15:54 -03:00
|
|
|
|
2022-03-10 01:56:25 -03:00
|
|
|
/// Query for available system information.
|
2024-06-14 01:47:39 +02:00
|
|
|
pub fn fetch_information() -> Task<Information> {
|
2024-07-05 01:13:28 +02:00
|
|
|
runtime::task::oneshot(|channel| {
|
2024-06-14 01:47:39 +02:00
|
|
|
runtime::Action::System(Action::QueryInformation(channel))
|
|
|
|
|
})
|
2022-03-10 01:56:25 -03:00
|
|
|
}
|
2022-04-14 11:15:54 -03:00
|
|
|
|
2022-04-27 16:18:27 -03:00
|
|
|
pub(crate) fn information(
|
2022-04-27 15:40:29 -03:00
|
|
|
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();
|
|
|
|
|
|
2023-03-07 07:22:48 +01:00
|
|
|
let cpu = system.global_cpu_info();
|
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(),
|
2022-04-14 11:15:54 -03:00
|
|
|
cpu_brand: cpu.brand().into(),
|
|
|
|
|
cpu_cores: system.physical_core_count(),
|
|
|
|
|
memory_total: system.total_memory(),
|
|
|
|
|
memory_used,
|
2022-04-27 15:40:29 -03:00
|
|
|
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
|
|
|
}
|