()
| 99 | |
| 100 | impl SystemInfo { |
| 101 | pub fn new() -> Result<Self> { |
| 102 | let os = SupportedOs::from_os(std::env::consts::OS)?; |
| 103 | let arch = System::cpu_arch(); |
| 104 | let user = get_user()?; |
| 105 | let host = System::host_name().ok_or(anyhow!("Failed to get host name"))?; |
| 106 | |
| 107 | let s = System::new_with_specifics( |
| 108 | RefreshKind::nothing() |
| 109 | .with_cpu(CpuRefreshKind::everything()) |
| 110 | .with_memory(MemoryRefreshKind::everything()), |
| 111 | ); |
| 112 | let cpu_cores = |
| 113 | System::physical_core_count().ok_or(anyhow!("Failed to get CPU core count"))?; |
| 114 | let total_memory_gb = s.total_memory().div_ceil(1024_u64.pow(3)); |
| 115 | |
| 116 | // take the first CPU to get the brand, name and vendor id |
| 117 | let cpu = s |
| 118 | .cpus() |
| 119 | .iter() |
| 120 | .next() |
| 121 | .ok_or(anyhow!("Failed to get CPU info"))?; |
| 122 | let cpu_brand = { |
| 123 | let brand = cpu.brand().to_string(); |
| 124 | if brand.is_empty() { |
| 125 | "unknown".to_string() |
| 126 | } else { |
| 127 | brand |
| 128 | } |
| 129 | }; |
| 130 | let cpu_name = cpu.name().to_string(); |
| 131 | let cpu_vendor_id = cpu.vendor_id().to_string(); |
| 132 | |
| 133 | let cpu_flags = get_cpu_flags(); |
| 134 | |
| 135 | Ok(SystemInfo { |
| 136 | os, |
| 137 | arch, |
| 138 | host, |
| 139 | user, |
| 140 | cpu_brand, |
| 141 | cpu_name, |
| 142 | cpu_vendor_id, |
| 143 | cpu_cores, |
| 144 | total_memory_gb, |
| 145 | cpu_flags, |
| 146 | }) |
| 147 | } |
| 148 | } |
nothing calls this directly
no test coverage detected