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

Hide process list #295

Merged
merged 6 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/nvtop/interface_layout_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
1 change: 1 addition & 0 deletions include/nvtop/interface_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1559,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 && (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)) {
wprintw(win, "F%s", option_selection_hidden_num[i]);
wattr_set(win, A_STANDOUT, cyan_color, NULL);
Expand Down
9 changes: 6 additions & 3 deletions src/interface_layout_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/interface_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions src/interface_setup_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion src/nvtop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -79,11 +80,12 @@ 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},
};

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, "");
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.)
Expand Down
9 changes: 5 additions & 4 deletions tests/interfaceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool test_with_terminal_size(unsigned device_count, unsigned header_rows, unsign
std::vector<unsigned> 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);
Expand All @@ -171,7 +171,7 @@ TEST(InterfaceLayout, CheckEmptyProcessWindow) {
std::vector<unsigned> 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));
Expand All @@ -194,7 +194,7 @@ TEST(InterfaceLayout, FixInfiniteLoop) {
std::vector<unsigned> 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);
}

Expand All @@ -204,7 +204,8 @@ TEST(InterfaceLayout, LayoutSelection_test_fail_case1) { test_with_terminal_size

TEST(InterfaceLayout, CheckManyTermSize) {
const std::array<unsigned, 8> dev_count_to_test = {0, 1, 2, 3, 6, 16, 32, 64};
const std::map<unsigned, unsigned> extra_increment = {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {6, 4}, {16, 6}, {32, 8}, {64, 17}};
const std::map<unsigned, unsigned> 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)) {
Expand Down