removed languages.json and territories.json
Some checks failed
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Failing after 6m9s
Build Zenyx ⚡ / 🏗️ Build aarch64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
Some checks failed
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Failing after 6m9s
Build Zenyx ⚡ / 🏗️ Build aarch64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
lib.rs is separated into src/modules now for cleaner code optimized error handling to -> (storage.rs, uptime.rs, meta.rs, memory.rs, os.rs, network.rs) optimized struct types to -> (storage.rs, uptime.rs, meta.rs, memory.rs, os.rs, network.rs)
This commit is contained in:
parent
91c80d0f91
commit
528d4b03a3
28 changed files with 1261 additions and 1726 deletions
131
subcrates/telemetry/src/modules/gpu/mod.rs
Normal file
131
subcrates/telemetry/src/modules/gpu/mod.rs
Normal file
|
@ -0,0 +1,131 @@
|
|||
use super::Defaults::Unknown;
|
||||
use serde::Serialize;
|
||||
use serde_json::{Value, json};
|
||||
use wgpu;
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::{ActiveEventLoop, EventLoop},
|
||||
window::WindowId,
|
||||
};
|
||||
|
||||
mod vram;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct DriverInfo {
|
||||
version: String,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct AdapterInfo {
|
||||
vendor: String,
|
||||
model: String,
|
||||
driver: DriverInfo,
|
||||
vram: String,
|
||||
display: DisplayInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct GPUInfo {
|
||||
supported_backends: Vec<String>,
|
||||
gpus: Vec<AdapterInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Default)]
|
||||
pub struct DisplayInfo {
|
||||
resolution: String,
|
||||
refresh_rate: String,
|
||||
}
|
||||
|
||||
impl ApplicationHandler for DisplayInfo {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
if let Some(monitor) = event_loop.primary_monitor() {
|
||||
let size = monitor.size();
|
||||
let refresh_rate = monitor.refresh_rate_millihertz();
|
||||
|
||||
self.resolution = format!("{}x{}", size.width, size.height);
|
||||
self.refresh_rate = if let Some(refresh) = refresh_rate {
|
||||
format!("{} hz", refresh / 1000)
|
||||
} else {
|
||||
Unknown.into()
|
||||
}
|
||||
} else {
|
||||
self.resolution = Unknown.into();
|
||||
self.refresh_rate = Unknown.into();
|
||||
}
|
||||
|
||||
event_loop.exit();
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
&mut self,
|
||||
_event_loop: &ActiveEventLoop,
|
||||
_window_id: WindowId,
|
||||
_event: WindowEvent,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
fn vendor_name(vendor: u32) -> &'static str {
|
||||
match vendor {
|
||||
0x10DE => "NVIDIA",
|
||||
0x1002 => "AMD(Advanced Micro Devices), Inc.",
|
||||
0x8086 => "Intel(integrated electronics)",
|
||||
0x13B5 => "ARM(Advanced RISC Machines)",
|
||||
0x5143 => "Qualcomm(Quality Communications)",
|
||||
0x1010 => "Apple Inc.",
|
||||
_ => "Unknown",
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_struct() -> GPUInfo {
|
||||
let mut gpu_data: Vec<AdapterInfo> = Vec::new();
|
||||
let mut backends: Vec<String> = Vec::new();
|
||||
let instance_descriptor = wgpu::InstanceDescriptor {
|
||||
backends: wgpu::Backends::all(),
|
||||
flags: wgpu::InstanceFlags::empty(),
|
||||
backend_options: Default::default(),
|
||||
};
|
||||
let instance = wgpu::Instance::new(&instance_descriptor);
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let mut app = DisplayInfo::default();
|
||||
|
||||
event_loop.run_app(&mut app).unwrap();
|
||||
|
||||
for adapter in instance.enumerate_adapters(wgpu::Backends::all()) {
|
||||
let info = adapter.get_info();
|
||||
|
||||
if !backends.contains(&info.backend.to_string()) {
|
||||
backends.push(info.backend.to_string());
|
||||
}
|
||||
if info.driver.is_empty() || info.driver_info.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
gpu_data.push(AdapterInfo {
|
||||
vendor: vendor_name(info.vendor).to_string(),
|
||||
model: info.name,
|
||||
driver: DriverInfo {
|
||||
version: info.driver_info,
|
||||
name: info.driver,
|
||||
},
|
||||
vram: vram::get(info.vendor, info.device),
|
||||
display: DisplayInfo {
|
||||
resolution: app.resolution.to_string(),
|
||||
refresh_rate: app.refresh_rate.to_string(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
GPUInfo {
|
||||
supported_backends: backends,
|
||||
gpus: gpu_data,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_json() -> Value {
|
||||
json!(get_struct())
|
||||
}
|
67
subcrates/telemetry/src/modules/gpu/vram.rs
Normal file
67
subcrates/telemetry/src/modules/gpu/vram.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
use super::super::Defaults::Unknown;
|
||||
use ash::vk::{API_VERSION_1_2, ApplicationInfo, InstanceCreateInfo, MemoryHeapFlags};
|
||||
use humansize::{DECIMAL, make_format};
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub fn get_metal() -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn get_metal() -> u64 {
|
||||
use metal::Device as MetalDevice;
|
||||
|
||||
let device = MetalDevice::system_default().expect("No Metal-compatible GPU found");
|
||||
device.recommended_max_working_set_size()
|
||||
}
|
||||
|
||||
pub fn get_vulkan(device_id: u32) -> u64 {
|
||||
let entry = unsafe { ash::Entry::load().unwrap() };
|
||||
let app_info = ApplicationInfo {
|
||||
p_application_name: std::ptr::null(),
|
||||
application_version: 0,
|
||||
p_engine_name: std::ptr::null(),
|
||||
engine_version: 0,
|
||||
api_version: API_VERSION_1_2,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let create_info = InstanceCreateInfo {
|
||||
p_application_info: &app_info,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let instance = unsafe { entry.create_instance(&create_info, None).unwrap() };
|
||||
|
||||
let physical_devices = unsafe { instance.enumerate_physical_devices().unwrap() };
|
||||
let mut total_vram = 0;
|
||||
|
||||
for device in physical_devices {
|
||||
let memory_properties = unsafe { instance.get_physical_device_memory_properties(device) };
|
||||
let device_properties = unsafe { instance.get_physical_device_properties(device) };
|
||||
|
||||
if device_id != device_properties.device_id {
|
||||
continue;
|
||||
}
|
||||
|
||||
for heap in memory_properties.memory_heaps {
|
||||
if heap.flags.contains(MemoryHeapFlags::DEVICE_LOCAL) {
|
||||
total_vram += heap.size;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
total_vram
|
||||
}
|
||||
|
||||
pub fn get(vendor: u32, device_id: u32) -> String {
|
||||
let formatter = make_format(DECIMAL);
|
||||
|
||||
match vendor {
|
||||
0x10DE | 0x1002 | 0x8086 | 0x5143 => formatter(get_vulkan(device_id)),
|
||||
0x1010 => formatter(get_metal()),
|
||||
_ => Unknown.into(),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue