Skip to content

Commit

Permalink
tui, gui, smi: UiArgs
Browse files Browse the repository at this point in the history
add "--hide-fdinfo" option for TUI mode

Resolved: #108
  • Loading branch information
Umio-Yasuno committed Dec 17, 2024
1 parent d1fe413 commit b226526
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 63 deletions.
28 changes: 14 additions & 14 deletions crates/amdgpu_top_gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use libamdgpu_top::{
},
AppDeviceInfo,
DevicePath,
GuiWgpuBackend,
Sampling,
UiArgs,
PCI,
};

Expand Down Expand Up @@ -61,22 +63,20 @@ static PCI_BUS_ID: LazyLock<egui::Id> = LazyLock::new(|| {
egui::Id::new("pci_bus")
});

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum GuiWgpuBackend {
Gl,
Vulkan,
}

pub fn run(
app_name: &str,
title_with_version: &str,
device_path_list: &[DevicePath],
selected_pci_bus: PCI::BUS_INFO,
update_process_index_interval: u64,
no_pc: bool,
is_dark_mode: Option<bool>,
gui_wgpu_backend: GuiWgpuBackend,
UiArgs {
selected_device_path,
device_path_list,
update_process_index,
no_pc,
is_dark_mode,
gui_wgpu_backend,
..
}: UiArgs,
) {
let selected_pci_bus = selected_device_path.pci;
let localizer = localizer();
let requested_languages = DesktopLanguageRequester::requested_languages();

Expand All @@ -85,7 +85,7 @@ pub fn run(
}

let (mut vec_app, mut suspended_devices) = AppAmdgpuTop::create_app_and_suspended_list(
device_path_list,
&device_path_list,
&Default::default(),
);

Expand All @@ -104,7 +104,7 @@ pub fn run(
device_paths.push(xdna_device_path.clone());
}

stat::spawn_update_index_thread(device_paths, update_process_index_interval);
stat::spawn_update_index_thread(device_paths, update_process_index);
}

let mut vec_data: Vec<_> = vec_app.iter().map(GuiAppData::new).collect();
Expand Down
25 changes: 15 additions & 10 deletions crates/amdgpu_top_tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cursive::view::{Nameable, Scrollable};
use cursive::{event::Key, menu, traits::With};
use cursive::theme::{BorderStyle, Theme, Palette};

use libamdgpu_top::{app::AppAmdgpuTop, DevicePath, Sampling};
use libamdgpu_top::{app::AppAmdgpuTop, DevicePath, Sampling, UiArgs};
use libamdgpu_top::stat::{self, FdInfoSortType, PCType};

mod view;
Expand Down Expand Up @@ -56,17 +56,22 @@ type Opt = Arc<Mutex<ToggleOptions>>;

pub fn run(
title: &str,
selected_device_path: DevicePath,
device_path_list: &[DevicePath],
interval: u64,
no_pc: bool,
is_dark_mode: bool,
UiArgs {
selected_device_path,
device_path_list,
update_process_index,
no_pc,
is_dark_mode,
hide_fdinfo,
..
}: UiArgs,
) {
let is_dark_mode = is_dark_mode == Some(true); // The default theme for TUI is light.
let title = title.to_string();
let mut toggle_opt = ToggleOptions { is_dark_mode, ..Default::default() };
let mut toggle_opt = ToggleOptions { is_dark_mode, fdinfo: !hide_fdinfo, ..Default::default() };

let (vec_app, suspended_devices) = AppAmdgpuTop::create_app_and_suspended_list(
device_path_list,
&device_path_list,
&Default::default(),
);
let mut vec_app: Vec<_> = vec_app
Expand All @@ -88,7 +93,7 @@ pub fn run(
toggle_opt.indexes = vec_app.iter().map(|app| app.index).collect();

{
let mut device_paths: Vec<DevicePath> = device_path_list.to_vec();
let mut device_paths: Vec<DevicePath> = device_path_list;

if let Some(xdna_device_path) = vec_app
.iter()
Expand All @@ -97,7 +102,7 @@ pub fn run(
device_paths.push(xdna_device_path.clone());
}

stat::spawn_update_index_thread(device_paths, interval);
stat::spawn_update_index_thread(device_paths, update_process_index);
}

let mut siv = cursive::default();
Expand Down
15 changes: 11 additions & 4 deletions crates/amdgpu_top_tui/src/smi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cursive::view::{Nameable, Scrollable};
use cursive::views::{HideableView, LinearLayout, TextContent, TextView, Panel};

use libamdgpu_top::AMDGPU::MetricsInfo;
use libamdgpu_top::{stat, DevicePath, Sampling};
use libamdgpu_top::{stat, DevicePath, Sampling, UiArgs};
use stat::{GfxoffMonitor, GfxoffStatus, FdInfoSortType};

use crate::{Text, AppTextView};
Expand Down Expand Up @@ -271,10 +271,17 @@ impl SuspendedSmiApp {
}
}

pub fn run_smi(title: &str, device_path_list: &[DevicePath], interval: u64) {
pub fn run_smi(
title: &str,
UiArgs {
device_path_list,
update_process_index,
..
}: UiArgs,
) {
let sample = Sampling::low();
let (vec_app, suspended) = AppAmdgpuTop::create_app_and_suspended_list(
device_path_list,
&device_path_list,
&Default::default(),
);
let mut vec_app: Vec<_> = vec_app
Expand Down Expand Up @@ -331,7 +338,7 @@ pub fn run_smi(title: &str, device_path_list: &[DevicePath], interval: u64) {

{
let device_paths: Vec<DevicePath> = device_path_list.to_vec();
stat::spawn_update_index_thread(device_paths, interval);
stat::spawn_update_index_thread(device_paths, update_process_index);
}

siv.add_global_callback('q', cursive::Cursive::quit);
Expand Down
17 changes: 17 additions & 0 deletions crates/libamdgpu_top/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ pub use drm_mode::*;
mod ppfeaturemask;
pub use ppfeaturemask::*;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum GuiWgpuBackend {
Gl,
Vulkan,
}

#[derive(Debug, Clone)]
pub struct UiArgs {
pub selected_device_path: DevicePath,
pub device_path_list: Vec<DevicePath>,
pub update_process_index: u64,
pub no_pc: bool,
pub is_dark_mode: Option<bool>, // TUI, GUI
pub hide_fdinfo: bool, // TUI
pub gui_wgpu_backend: GuiWgpuBackend,
}

pub struct Sampling {
pub count: usize,
pub delay: Duration,
Expand Down
4 changes: 4 additions & 0 deletions docs/amdgpu_top.1
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ Set to the dark mode.
Set to the light mode.
(TUI/GUI)
.TP
\f[B]--hide-fdinfo\f[R]
Hide fdinfo panel and launch.
(TUI)
.TP
\f[B]--gl\f[R], \f[B]--opengl\f[R]
Use OpenGL API to the GUI backend.
.TP
Expand Down
3 changes: 3 additions & 0 deletions docs/man.amdgpu_top.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ The tool displays information gathered from performance counters (GRBM, GRBM2),
**\-\-light**, **\-\-light-mode**
: Set to the light mode. (TUI/GUI)

**\-\-hide-fdinfo**
: Hide fdinfo panel and launch. (TUI)

**\-\-gl**, **\-\-opengl**
: Use OpenGL API to the GUI backend.

Expand Down
13 changes: 6 additions & 7 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use libamdgpu_top::PCI;
#[cfg(feature = "gui")]
use amdgpu_top_gui::GuiWgpuBackend;
use libamdgpu_top::{GuiWgpuBackend, PCI};

pub struct MainOpt {
pub instance: Option<usize>, // index
Expand All @@ -16,7 +14,7 @@ pub struct MainOpt {
pub no_pc: bool,
pub is_dark_mode: Option<bool>,
pub decode_gpu_metrics: Option<String>,
#[cfg(feature = "gui")]
pub hide_fdinfo: bool,
pub wgpu_backend: GuiWgpuBackend,
}

Expand All @@ -36,7 +34,7 @@ impl Default for MainOpt {
no_pc: false,
is_dark_mode: None,
decode_gpu_metrics: None,
#[cfg(feature = "gui")]
hide_fdinfo: false,
wgpu_backend: GuiWgpuBackend::Gl,
}
}
Expand Down Expand Up @@ -120,6 +118,8 @@ const HELP_MSG: &str = concat!(
" Set to the dark mode. (TUI/GUI)\n",
" --light, --light-mode\n",
" Set to the light mode. (TUI/GUI)\n",
" --hide-fdinfo\n",
" Hide fdinfo panel and launch. (TUI)\n",
" --gl, --opengl\n",
" Use OpenGL API to the GUI backend.\n",
" --vk, --vulkan\n",
Expand Down Expand Up @@ -343,9 +343,8 @@ impl MainOpt {
"--light" | "--light-mode" => {
opt.is_dark_mode = Some(false);
},
#[cfg(feature = "gui")]
"--hide-fdinfo" => opt.hide_fdinfo = true,
"--gl" | "--opengl" => opt.wgpu_backend = GuiWgpuBackend::Gl,
#[cfg(feature = "gui")]
"--vk" | "--vulkan" => opt.wgpu_backend = GuiWgpuBackend::Vulkan,
"--xdna" => {
opt.dump_mode = DumpMode::Xdna;
Expand Down
46 changes: 18 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use libamdgpu_top::DevicePath;
use libamdgpu_top::{DevicePath, UiArgs};

#[cfg(feature = "gui")]
const APP_NAME: &str = env!("CARGO_PKG_NAME");
Expand Down Expand Up @@ -133,36 +133,30 @@ fn main() {
},
}

let ui_args = UiArgs {
selected_device_path: device_path,
device_path_list,
update_process_index: main_opt.update_process_index,
no_pc: main_opt.no_pc,
is_dark_mode: main_opt.is_dark_mode,
hide_fdinfo: main_opt.hide_fdinfo,
gui_wgpu_backend: main_opt.wgpu_backend,
};

match main_opt.app_mode {
AppMode::TUI => {
#[cfg(feature = "tui")]
{
amdgpu_top_tui::run(
TITLE,
device_path,
&device_path_list,
main_opt.update_process_index,
main_opt.no_pc,
main_opt.is_dark_mode == Some(true), // The default theme for TUI is light.
)
amdgpu_top_tui::run(TITLE, ui_args)
}
#[cfg(not(feature = "tui"))]
{
eprintln!("\"tui\" feature is not enabled for this build.");
dump_info::dump(&device_path, main_opt.opt_dump_mode);
dump_info::dump(&ui_args.device_path, main_opt.opt_dump_mode);
}
},
#[cfg(feature = "gui")]
AppMode::GUI => amdgpu_top_gui::run(
APP_NAME,
TITLE,
&device_path_list,
device_path.pci,
main_opt.update_process_index,
main_opt.no_pc,
main_opt.is_dark_mode,
main_opt.wgpu_backend,
),
AppMode::GUI => amdgpu_top_gui::run(APP_NAME, TITLE, ui_args),
#[cfg(feature = "json")]
AppMode::JSON => unreachable!(),
#[cfg(feature = "json")]
Expand All @@ -189,21 +183,17 @@ fn main() {

let mut j = amdgpu_top_json::JsonApp::new(
TITLE,
&device_path_list,
&ui_args.device_path_list,
main_opt.refresh_period,
main_opt.update_process_index,
ui_args.update_process_index,
main_opt.json_iterations,
main_opt.no_pc,
ui_args.no_pc,
);

j.run_fifo(path);
},
#[cfg(feature = "tui")]
AppMode::SMI => amdgpu_top_tui::run_smi(
TITLE,
&device_path_list,
main_opt.update_process_index,
),
AppMode::SMI => amdgpu_top_tui::run_smi(TITLE, ui_args),
}
}

Expand Down

0 comments on commit b226526

Please sign in to comment.