Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal Performance HUD #7

Open
Angelk90 opened this issue Jan 8, 2025 · 8 comments
Open

Metal Performance HUD #7

Angelk90 opened this issue Jan 8, 2025 · 8 comments

Comments

@Angelk90
Copy link

Angelk90 commented Jan 8, 2025

Hi @JakkuSakura , congrats on a great job.

Could you post an example of an animated graph like this, I don't know what it shows the cpu usage used by the same program started.

Registrazione.schermo.2025-01-08.alle.18.46.56.mov
use sysinfo::{System, Pid, ProcessesToUpdate};
use std::{thread, time};
fn main() {
    let mut sys = System::new_all();
    let pid = Pid::from(std::process::id() as usize);
    loop {
        sys.refresh_processes(ProcessesToUpdate::All, false);
        if let Some(process) = sys.process(pid) {
            let cpu_usage = process.cpu_usage();
            println!("CPU usage: {:.2}%", cpu_usage);
        } else {
            println!("Process with PID {} not found.", pid);
        }
        thread::sleep(time::Duration::from_millis(500));
    }
}
@JakkuSakura
Copy link
Owner

I believe the graph is called Metal Performance HUD

MTL_HUD_ENABLED=1
Enables the Metal Performance HUD.

MTL_HUD_ENABLED=1 cargo run ...

Will enable it

@JakkuSakura JakkuSakura changed the title Animated graph Metal Performance HUD Jan 11, 2025
@Angelk90
Copy link
Author

@JakkuSakura : What I mean is if you can create an animated graph similar to that.
I don't mean exactly the one you see in the video.
But a graph that allows you to show something similar.

@JakkuSakura
Copy link
Owner

image See examples/animation-cpu.rs

@Angelk90
Copy link
Author

@JakkuSakura : Why does it do this in some places?
It almost seems like some sort of defect.

Maybe a scale issue?
Screenshot 2025-01-14 alle 12 40 20

Finally after a while, the program crashed:

Plot line with 100 points
thread 'main' panicked at examples/animation-cpu.rs:62:24:
called `Result::unwrap()` on an `Err` value: SystemTimeError(1.850171s)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at core/src/panicking.rs:221:5:
panic in a function that cannot unwind
stack backtrace:
   0:        0x1071fb156 - std::backtrace_rs::backtrace::libunwind::trace::hc4ed1a64850536ff
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:        0x1071fb156 - std::backtrace_rs::backtrace::trace_unsynchronized::hb5186e43ac69528f
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1071fb156 - std::sys::backtrace::_print_fmt::h7fc6a14ac3a0a722
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/sys/backtrace.rs:66:9
   3:        0x1071fb156 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h0fd572ca60ee9a4e
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/sys/backtrace.rs:39:26
   4:        0x10721b4a3 - core::fmt::rt::Argument::fmt::hdbc762bbbe87f170
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/fmt/rt.rs:177:76
   5:        0x10721b4a3 - core::fmt::write::hbc078725bba6692a
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/fmt/mod.rs:1186:21
   6:        0x1071f88e2 - std::io::Write::write_fmt::h100f2ae009a3df53
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/io/mod.rs:1839:15
   7:        0x1071faf92 - std::sys::backtrace::BacktraceLock::print::hf0d5a155265a9dd5
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/sys/backtrace.rs:42:9
   8:        0x1071fbfd2 - std::panicking::default_hook::{{closure}}::h5499fb85b118791b
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:268:22
   9:        0x1071fbe1c - std::panicking::default_hook::h3be9b9b36bd75e8f
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:295:9
  10:        0x1071fc7e7 - std::panicking::rust_panic_with_hook::h10014b4a7f4c072b
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:801:13
  11:        0x1071fc465 - std::panicking::begin_panic_handler::{{closure}}::hc871510d12acad65
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:667:13
  12:        0x1071fb639 - std::sys::backtrace::__rust_end_short_backtrace::hca0d49bc0c1e56d3
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/sys/backtrace.rs:170:18
  13:        0x1071fc0dc - rust_begin_unwind
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
  14:        0x107247764 - core::panicking::panic_nounwind_fmt::runtime::h2d661ea9a33dcb14
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:112:18
  15:        0x107247764 - core::panicking::panic_nounwind_fmt::ha58383cd2a83ddb2
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:122:5
  16:        0x10724780a - core::panicking::panic_nounwind::h0343eb3636eafe8a
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:221:5
  17:        0x107247972 - core::panicking::panic_cannot_unwind::hcdafe2afae6ec249
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:310:5
  18:        0x10704721b - gpui::platform::mac::window::step::h07b334d639cb0f26
                               at /Users/NAMEUSER/.cargo/git/checkouts/zed-23861290b5d2093f/8317c92/crates/gpui/src/platform/mac/window.rs:1636:1
  19:     0x7ff80e87b59a - <unknown>
  20:     0x7ff80e87e0c7 - <unknown>
  21:     0x7ff80e88e6f8 - <unknown>
  22:     0x7ff80e8877eb - <unknown>
  23:     0x7ff80e8874f2 - <unknown>
  24:     0x7ff80eb3e056 - <unknown>
  25:     0x7ff80eafd2b5 - <unknown>
  26:     0x7ff80eafc352 - <unknown>
  27:     0x7ff81939e9d9 - <unknown>
  28:     0x7ff81939e7e6 - <unknown>
  29:     0x7ff81939e531 - <unknown>
  30:     0x7ff81210c885 - <unknown>
  31:     0x7ff812a00348 - <unknown>
  32:     0x7ff8120fddfa - <unknown>
  33:        0x1070bce11 - <() as objc::message::MessageArguments>::invoke::h46a851a2fec725fc
                               at /Users/NAMEUSER/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/message/mod.rs:128:17
  34:        0x1070bc2ad - objc::message::platform::send_unverified::hdf8a448765866cf9
                               at /Users/NAMEUSER/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/message/apple/mod.rs:27:9
  35:        0x1070ac307 - objc::message::send_message::hee539337fc753be5
                               at /Users/NAMEUSER/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-0.2.7/src/message/mod.rs:178:5
  36:        0x1070ac307 - <*mut objc::runtime::Object as cocoa::appkit::NSApplication>::run::hae7725e69cac3654
                               at /Users/NAMEUSER/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cocoa-0.26.0/src/appkit.rs:628:9
  37:        0x106fb5c51 - <gpui::platform::mac::platform::MacPlatform as gpui::platform::Platform>::run::h1a9247d59ca37b8e
                               at /Users/NAMEUSER/.cargo/git/checkouts/zed-23861290b5d2093f/8317c92/crates/gpui/src/platform/mac/platform.rs:453:13
  38:        0x106bd82d0 - gpui::app::App::run::h9deedb4ffa2ebad1
                               at /Users/NAMEUSER/.cargo/git/checkouts/zed-23861290b5d2093f/8317c92/crates/gpui/src/app.rs:166:9
  39:        0x106bec091 - animation_cpu::main::hbc7145102123e939
                               at /Users/NAMEUSER/Desktop/plotters-gpui/examples/animation-cpu.rs:125:5
  40:        0x106bd34ae - core::ops::function::FnOnce::call_once::h919c5805224cfe29
                               at /Users/NAMEUSER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  41:        0x106bcb021 - std::sys::backtrace::__rust_begin_short_backtrace::h811052531c855415
                               at /Users/NAMEUSER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:154:18
  42:        0x106bcb3f4 - std::rt::lang_start::{{closure}}::he41626e3f53b3f86
                               at /Users/NAMEUSER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:195:18
  43:        0x1071f4a2f - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h6252623bb1cf9e24
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/ops/function.rs:284:13
  44:        0x1071f4a2f - std::panicking::try::do_call::h802b6be37fdfe7d1
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:557:40
  45:        0x1071f4a2f - std::panicking::try::ha98b44516eed09a1
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:520:19
  46:        0x1071f4a2f - std::panic::catch_unwind::he7beae4d941b6394
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panic.rs:358:14
  47:        0x1071f4a2f - std::rt::lang_start_internal::{{closure}}::h8779fe794c920b47
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/rt.rs:174:48
  48:        0x1071f4a2f - std::panicking::try::do_call::h303ea4dd61246a28
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:557:40
  49:        0x1071f4a2f - std::panicking::try::h46cbd0a758d8b110
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:520:19
  50:        0x1071f4a2f - std::panic::catch_unwind::hd768c1931bcc381d
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panic.rs:358:14
  51:        0x1071f4a2f - std::rt::lang_start_internal::hed9c3972c1d4ad97
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/rt.rs:174:20
  52:        0x106bcb3c7 - std::rt::lang_start::ha40374548e7ad8e3
                               at /Users/NAMEUSER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:194:17
  53:        0x106bec0b8 - _main
  54:     0x7ff80e69a3a6 - <unknown>
thread caused non-unwinding panic. aborting.
[1]    9469 abort      cargo run --example animation-cpu

@JakkuSakura
Copy link
Owner

It's a rendering precision issue. There's an open PR pending that could fix this.

I'll double check the crash soon

@Angelk90
Copy link
Author

@JakkuSakura : There shouldn't be time on the x-axis, right?

But it seems to give problems, after a while it resets again.

@JakkuSakura
Copy link
Owner

I'm not sure how to render time on x axis property, so I converted time difference to f32.

@JakkuSakura
Copy link
Owner

Finally after a while, the program crashed: SystemTime error

Maybe at this time your MacBook synced time with NTP and SystemTime reversed

JakkuSakura added a commit that referenced this issue Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants