From ff5fce8160f5886ef5fcad5a8a45cf61fc64cc07 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 13 May 2024 12:03:57 +0500 Subject: [PATCH 1/6] Hide process list window --- include/nvtop/interface_layout_selection.h | 3 ++- include/nvtop/interface_options.h | 1 + src/interface.c | 5 ++++- src/interface_layout_selection.c | 9 ++++++--- src/nvtop.c | 8 ++++++++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/nvtop/interface_layout_selection.h b/include/nvtop/interface_layout_selection.h index 7a66f96..c83078b 100644 --- a/include/nvtop/interface_layout_selection.h +++ b/include/nvtop/interface_layout_selection.h @@ -18,6 +18,7 @@ void compute_sizes_from_layout(unsigned monitored_dev_count, unsigned device_hea process_field_displayed process_field_displayed, struct window_position *device_positions, unsigned *num_plots, struct window_position plot_positions[MAX_CHARTS], unsigned *map_device_to_plot, - struct window_position *process_position, struct window_position *setup_position); + struct window_position *process_position, struct window_position *setup_position, + bool process_win_hide); #endif // INTERFACE_LAYOUT_SELECTION_H__ diff --git a/include/nvtop/interface_options.h b/include/nvtop/interface_options.h index c8c1a26..0248693 100644 --- a/include/nvtop/interface_options.h +++ b/include/nvtop/interface_options.h @@ -51,6 +51,7 @@ typedef struct nvtop_interface_option_struct { bool filter_nvtop_pid; // Do not show nvtop pid in the processes list bool has_monitored_set_changed; // True if the set of monitored gpu was modified through the interface bool has_gpu_info_bar; // Show info bar with additional GPU parametres + bool hide_processes_list; // Hide processes list } nvtop_interface_option; inline bool plot_isset_draw_info(enum plot_information check_info, plot_info_to_draw to_draw) { diff --git a/src/interface.c b/src/interface.c index e7fae07..b3ec921 100644 --- a/src/interface.c +++ b/src/interface.c @@ -361,7 +361,7 @@ static void initialize_all_windows(struct nvtop_interface *dwin) { compute_sizes_from_layout(devices_count, dwin->options.has_gpu_info_bar ? 4 : 3, device_length(), rows - 1, cols, dwin->options.gpu_specific_opts, dwin->options.process_fields_displayed, device_positions, &dwin->num_plots, plot_positions, - map_device_to_plot, &process_position, &setup_position); + map_device_to_plot, &process_position, &setup_position, dwin->options.hide_processes_list); alloc_plot_window(devices_count, plot_positions, map_device_to_plot, dwin); @@ -1356,6 +1356,9 @@ static void print_processes_on_screen(all_processes all_procs, struct process_wi static void update_process_option_win(struct nvtop_interface *interface); static void draw_processes(struct list_head *devices, struct nvtop_interface *interface) { + if (interface->options.hide_processes_list) + return; + if (interface->process.process_win == NULL) return; diff --git a/src/interface_layout_selection.c b/src/interface_layout_selection.c index ce755c6..acc4cac 100644 --- a/src/interface_layout_selection.c +++ b/src/interface_layout_selection.c @@ -230,13 +230,12 @@ static void balance_info_on_stacks_preserving_plot_order(unsigned stack_max_cols moving_plot_id--; } } - void compute_sizes_from_layout(unsigned devices_count, unsigned device_header_rows, unsigned device_header_cols, unsigned rows, unsigned cols, const nvtop_interface_gpu_opts *gpuOpts, process_field_displayed process_displayed, struct window_position *device_positions, unsigned *num_plots, struct window_position plot_positions[MAX_CHARTS], unsigned *map_device_to_plot, struct window_position *process_position, - struct window_position *setup_position) { + struct window_position *setup_position, bool process_win_hide) { unsigned min_rows_for_header = 0, header_stacks = 0, num_device_per_row = 0; num_device_per_row = max(1, cols / device_header_cols); @@ -257,6 +256,10 @@ void compute_sizes_from_layout(unsigned devices_count, unsigned device_header_ro min_rows_for_process = 0; } } + + if (process_win_hide) + min_rows_for_process = 0; + unsigned rows_for_header = min_rows_for_header; unsigned rows_for_process = min_rows_for_process; unsigned rows_for_plots = rows - min_rows_for_header - min_rows_for_process; @@ -329,7 +332,7 @@ void compute_sizes_from_layout(unsigned devices_count, unsigned device_header_ro unsigned rows_left_for_process = 0; if (*num_plots > 0) { unsigned rows_per_stack = rows_for_plots / num_plot_stacks; - if (rows_per_stack > 23) + if (!process_win_hide && rows_per_stack > 23) rows_per_stack = 23; unsigned num_plot_done = 0; unsigned currentPosX = 0, currentPosY = rows_for_header; diff --git a/src/nvtop.c b/src/nvtop.c index f2fe31b..a9b9890 100644 --- a/src/nvtop.c +++ b/src/nvtop.c @@ -56,6 +56,7 @@ static const char helpstring[] = "Available options:\n" " -c --config-file : Provide a custom config file location to load/save " "preferences\n" " -p --no-plot : Disable bar plot\n" + " -p --no-processes : Disable process list\n" " -r --reverse-abs : Reverse abscissa: plot the recent data left and " "older on the right\n" " -C --no-color : No colors\n" @@ -79,6 +80,7 @@ static const struct option long_opts[] = { {.name = "gpu-info", .has_arg = no_argument, .flag = NULL, .val = 'i'}, {.name = "encode-hide", .has_arg = required_argument, .flag = NULL, .val = 'E'}, {.name = "no-plot", .has_arg = no_argument, .flag = NULL, .val = 'p'}, + {.name = "no-processes", .has_arg = no_argument, .flag = NULL, .val = 'P'}, {.name = "reverse-abs", .has_arg = no_argument, .flag = NULL, .val = 'r'}, {0, 0, 0, 0}, }; @@ -94,6 +96,7 @@ int main(int argc, char **argv) { bool no_color_option = false; bool use_fahrenheit_option = false; bool hide_plot_option = false; + bool hide_processes_option = false; bool reverse_plot_direction_option = false; bool encode_decode_timer_option_set = false; bool show_gpu_info_bar = false; @@ -151,6 +154,9 @@ int main(int argc, char **argv) { case 'p': hide_plot_option = true; break; + case 'P': + hide_processes_option = true; + break; case 'r': reverse_plot_direction_option = true; break; @@ -230,6 +236,8 @@ int main(int argc, char **argv) { allDevicesOptions.gpu_specific_opts[i].to_draw = 0; } } + if (hide_processes_option) + allDevicesOptions.hide_processes_list = true; if (encode_decode_timer_option_set) { allDevicesOptions.encode_decode_hiding_timer = encode_decode_hide_time; if (allDevicesOptions.encode_decode_hiding_timer < 0.) From 9dfbd544d9b6509102c44eb8ada0f7ea8398fab5 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 13 May 2024 12:19:17 +0500 Subject: [PATCH 2/6] Hide process list window --- src/interface.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/interface.c b/src/interface.c index b3ec921..a956b90 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1562,6 +1562,9 @@ static void draw_process_shortcuts(struct nvtop_interface *interface) { switch (current_state) { case nvtop_option_state_hidden: for (size_t i = 0; i < ARRAY_SIZE(option_selection_hidden); ++i) { + if (interface->options.hide_processes_list && (option_selection_hidden_num[i] == "6" || option_selection_hidden_num[i] == "9")) + continue; + if (process_field_displayed_count(interface->options.process_fields_displayed) > 0 || (i != 1 && i != 2)) { wprintw(win, "F%s", option_selection_hidden_num[i]); wattr_set(win, A_STANDOUT, cyan_color, NULL); From cb93dfac2b575bc62772f37b44926d34540e3739 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 13 May 2024 12:58:18 +0500 Subject: [PATCH 3/6] Hide process list window --- src/interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface.c b/src/interface.c index a956b90..f317aeb 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1562,7 +1562,7 @@ static void draw_process_shortcuts(struct nvtop_interface *interface) { switch (current_state) { case nvtop_option_state_hidden: for (size_t i = 0; i < ARRAY_SIZE(option_selection_hidden); ++i) { - if (interface->options.hide_processes_list && (option_selection_hidden_num[i] == "6" || option_selection_hidden_num[i] == "9")) + if (interface->options.hide_processes_list && (strcmp(option_selection_hidden_num[i], "6") == 0 || strcmp(option_selection_hidden_num[i], "9") == 0)) continue; if (process_field_displayed_count(interface->options.process_fields_displayed) > 0 || (i != 1 && i != 2)) { From 14b74f02d8ef99afd61b82eb73caa97330415088 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Sun, 26 May 2024 20:34:14 +0500 Subject: [PATCH 4/6] Hide process list window --- src/nvtop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvtop.c b/src/nvtop.c index a9b9890..09a1796 100644 --- a/src/nvtop.c +++ b/src/nvtop.c @@ -56,7 +56,7 @@ static const char helpstring[] = "Available options:\n" " -c --config-file : Provide a custom config file location to load/save " "preferences\n" " -p --no-plot : Disable bar plot\n" - " -p --no-processes : Disable process list\n" + " -P --no-processes : Disable process list\n" " -r --reverse-abs : Reverse abscissa: plot the recent data left and " "older on the right\n" " -C --no-color : No colors\n" @@ -85,7 +85,7 @@ static const struct option long_opts[] = { {0, 0, 0, 0}, }; -static const char opts[] = "hvd:c:CfE:pri"; +static const char opts[] = "hvd:c:CfE:pPri"; int main(int argc, char **argv) { (void)setlocale(LC_CTYPE, ""); From 5a4aff0f1f42769487febfb12526297ef7a058f9 Mon Sep 17 00:00:00 2001 From: Maxime Schmitt Date: Sat, 27 Jul 2024 14:05:21 +0200 Subject: [PATCH 5/6] Hide process list option in setup window & config file --- src/interface_options.c | 10 ++++++++++ src/interface_setup_win.c | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/interface_options.c b/src/interface_options.c index c265d1d..e6bc73f 100644 --- a/src/interface_options.c +++ b/src/interface_options.c @@ -176,6 +176,7 @@ static const char chart_section[] = "ChartOption"; static const char chart_value_reverse[] = "ReverseChart"; static const char process_list_section[] = "ProcessListOption"; +static const char process_hide_nvtop_process_list[] = "HideNvtopProcessList"; static const char process_hide_nvtop_process[] = "HideNvtopProcess"; static const char process_value_sortby[] = "SortBy"; static const char process_value_display_field[] = "DisplayField"; @@ -256,6 +257,14 @@ static int nvtop_option_ini_handler(void *user, const char *section, const char } // Process List Options if (strcmp(section, process_list_section) == 0) { + if (strcmp(name, process_hide_nvtop_process_list) == 0) { + if (strcmp(value, "true") == 0) { + ini_data->options->hide_processes_list = true; + } + if (strcmp(value, "false") == 0) { + ini_data->options->hide_processes_list = false; + } + } if (strcmp(name, process_hide_nvtop_process) == 0) { if (strcmp(value, "true") == 0) { ini_data->options->filter_nvtop_pid = true; @@ -398,6 +407,7 @@ bool save_interface_options_to_config_file(unsigned total_dev_count, const nvtop // Process Options fprintf(config_file, "\n[%s]\n", process_list_section); + fprintf(config_file, "%s = %s\n", process_hide_nvtop_process_list, boolean_string(options->hide_processes_list)); fprintf(config_file, "%s = %s\n", process_hide_nvtop_process, boolean_string(options->filter_nvtop_pid)); fprintf(config_file, "%s = %s\n", process_value_sort_order, options->sort_descending_order ? process_sort_descending : process_sort_ascending); diff --git a/src/interface_setup_win.c b/src/interface_setup_win.c index a1aa78e..047809f 100644 --- a/src/interface_setup_win.c +++ b/src/interface_setup_win.c @@ -84,6 +84,7 @@ static const char *setup_chart_gpu_value_descriptions[plot_information_count] = // Process List Options enum setup_proc_list_options { + setup_proc_list_hide_process_list, setup_proc_list_hide_nvtop_process, setup_proc_list_sort_ascending, setup_proc_list_sort_by, @@ -92,7 +93,7 @@ enum setup_proc_list_options { }; static const char *setup_proc_list_option_description[setup_proc_list_options_count] = { - "Hide nvtop process", "Sort Ascending", "Sort by", "Field Displayed"}; + "Don't display the process list", "Hide nvtop in the process list", "Sort Ascending", "Sort by", "Field Displayed"}; static const char *setup_proc_list_value_descriptions[process_field_count] = { "Process Id", "User name", "Device Id", "Workload type", "GPU usage", "Encoder usage", @@ -460,7 +461,14 @@ static void draw_setup_window_proc_list(struct nvtop_interface *interface) { mvwchgat(option_list_win, 0, cur_col, maxcols - cur_col, A_STANDOUT, green_color, NULL); // Sort Ascending - enum option_state option_state = interface->options.filter_nvtop_pid; + enum option_state option_state = interface->options.hide_processes_list; + mvwprintw(option_list_win, setup_proc_list_hide_process_list + 1, 0, "[%c] %s", option_state_char(option_state), + setup_proc_list_option_description[setup_proc_list_hide_process_list]); + if (interface->setup_win.indentation_level == 1 && + interface->setup_win.options_selected[0] == setup_proc_list_hide_process_list) { + mvwchgat(option_list_win, setup_proc_list_hide_process_list + 1, 0, 3, A_STANDOUT, cyan_color, NULL); + } + option_state = interface->options.filter_nvtop_pid; mvwprintw(option_list_win, setup_proc_list_hide_nvtop_process + 1, 0, "[%c] %s", option_state_char(option_state), setup_proc_list_option_description[setup_proc_list_hide_nvtop_process]); if (interface->setup_win.indentation_level == 1 && @@ -796,6 +804,8 @@ void handle_setup_win_keypress(int keyId, struct nvtop_interface *interface) { interface->options.sort_descending_order = !interface->options.sort_descending_order; } else if (interface->setup_win.options_selected[0] == setup_proc_list_hide_nvtop_process) { interface->options.filter_nvtop_pid = !interface->options.filter_nvtop_pid; + } else if (interface->setup_win.options_selected[0] == setup_proc_list_hide_process_list) { + interface->options.hide_processes_list = !interface->options.hide_processes_list; } else if (interface->setup_win.options_selected[0] == setup_proc_list_sort_by) { handle_setup_win_keypress(KEY_RIGHT, interface); } From 2c4b65bae53e7307a5f7c7243a81aee5856f773e Mon Sep 17 00:00:00 2001 From: Maxime Schmitt Date: Sat, 27 Jul 2024 14:05:47 +0200 Subject: [PATCH 6/6] Fix tests with new parameter --- tests/interfaceTests.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/interfaceTests.cpp b/tests/interfaceTests.cpp index 75e69b6..235e45d 100644 --- a/tests/interfaceTests.cpp +++ b/tests/interfaceTests.cpp @@ -144,7 +144,7 @@ bool test_with_terminal_size(unsigned device_count, unsigned header_rows, unsign std::vector map_dev_to_plot(device_count); compute_sizes_from_layout(device_count, header_rows, header_cols, rows, cols, plot_display.data(), proc_display, dev_positions.data(), &num_plots, plot_positions.data(), map_dev_to_plot.data(), - &process_position, &setup_position); + &process_position, &setup_position, false); plot_positions.resize(num_plots); return check_layout(screen, dev_positions, plot_positions, process_position, setup_position); @@ -171,7 +171,7 @@ TEST(InterfaceLayout, CheckEmptyProcessWindow) { std::vector map_dev_to_plot(device_count); compute_sizes_from_layout(device_count, header_rows, header_cols, rows, cols, plot_display.data(), proc_display, dev_positions.data(), &num_plots, plot_positions.data(), map_dev_to_plot.data(), - &process_position, &setup_position); + &process_position, &setup_position, false); plot_positions.resize(num_plots); EXPECT_EQ(num_plots, 0); EXPECT_TRUE(window_is_empty(process_position)); @@ -194,7 +194,7 @@ TEST(InterfaceLayout, FixInfiniteLoop) { std::vector map_dev_to_plot(device_count); compute_sizes_from_layout(device_count, header_rows, header_cols, rows, cols, plot_display.data(), proc_display, dev_positions.data(), &num_plots, plot_positions.data(), map_dev_to_plot.data(), - &process_position, &setup_position); + &process_position, &setup_position, false); plot_positions.resize(num_plots); } @@ -204,7 +204,8 @@ TEST(InterfaceLayout, LayoutSelection_test_fail_case1) { test_with_terminal_size TEST(InterfaceLayout, CheckManyTermSize) { const std::array dev_count_to_test = {0, 1, 2, 3, 6, 16, 32, 64}; - const std::map extra_increment = {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {6, 4}, {16, 6}, {32, 8}, {64, 17}}; + const std::map extra_increment = {{0, 0}, {1, 0}, {2, 0}, {3, 0}, + {6, 4}, {16, 6}, {32, 8}, {64, 17}}; for (unsigned dev_count : dev_count_to_test) { for (unsigned screen_rows = 1; screen_rows < 2048; screen_rows += 1 + extra_increment.at(dev_count)) { for (unsigned screen_cols = 1; screen_cols < 2048; screen_cols += 1 + extra_increment.at(dev_count)) {