#How to get Bevy GPU usage?

21 messages · Page 1 of 1 (latest)

ruby aurora
#

My attempt at getting the bevy GPU usage :

fn update_gpu_usage(mut rate_query: Query<&mut Text, With<GpuUsage>>) {
    let Ok(mut text) = rate_query.single_mut() else {
        return;
    };

    text.0 = format!("{:?}", machine.0.graphics_status());
}

use machine_info::Machine;
#[derive(Resource)]
struct MachineInfo(Machine);

impl Default for MachineInfo {
    fn default() -> MachineInfo {
        let mut m = Machine::new();
        let pid = match get_current_pid() {
            Ok(pid) => pid.as_u32() as i32,
            Err(e) => {
                panic!("failed to get current pid: {}", e);
            }
        };
        info!("{}", pid);
        m.track_process(pid).unwrap();
        MachineInfo(m)
    }
}

use sysinfo::get_current_pid;
fn setup_machine_info(mut commands: Commands) {
    commands.init_resource::<MachineInfo>();
}

I'm using the machine info caret to get the gpu usage

#

unfortunately it crashes because it cant find the process:

thread 'main' panicked at src\ui\dev_ui.rs:193:30:
called `Result::unwrap()` on an `Err` value: The system cannot find the path specified. (os error 3)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic when applying buffers for system `waritmonia::ui::dev_ui::setup_machine_info`!
2025-05-16T14:26:28.723131Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply?
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
error: process didn't exit successfully: `target\debug\waritmonia.exe` (exit code: 101)
#

which is weird because bevy get the process pid in the same way by using sysinfo::fet_current_pid

ruby aurora
#

Is there a built in way to do this ?

ruby aurora
#

mchineinfo probably wont work on windows

#

and it does support amd gpu

indigo flume
#

What are you looking for in terms of GPU usage?

#

You're better off looking at GPU + CPU timings imo

#

E.g. 4ms per frame of CPU time, 3ms of GPU time

ruby aurora
indigo flume
#

That number is rarely meaningful. That's why I suggest using frame timings, or really just profiling.

ruby aurora
#

i know its not meaningful

#

but i want to replicate something like this in game :

#

and i need to know the gpu load

livid vapor
#

if you get it working I'd appreciate how 😄

ruby aurora
#

after digging a bit

#

its not possible to measure the gpu usage in a global maner

#

because of the different type of graphics card and operating system

#

at least not in an easy way

#

the only way is by interacting with the driver api for each vendor

#

nvidia has an easy wrapper