From 59f2f01f22f07257d23bc46b7a396686d3cf6736 Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Mon, 19 Apr 2021 14:03:16 +0200 Subject: [PATCH] spdk_top: make checking interface resize into a function Creates new function to check interface resize. This will be used in the next patch. Signed-off-by: Krzysztof Karas Change-Id: I147145be2db4fdab6f97b67baf3c2936abf7f6a3 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7499 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- app/spdk_top/spdk_top.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/app/spdk_top/spdk_top.c b/app/spdk_top/spdk_top.c index c071bb1e6..80d867a06 100644 --- a/app/spdk_top/spdk_top.c +++ b/app/spdk_top/spdk_top.c @@ -2131,6 +2131,27 @@ change_sorting(uint8_t tab, int winnum, bool *pstop_loop) } } +static void +check_resize_interface(uint8_t active_tab, uint8_t *current_page) +{ + int max_row, max_col; + uint16_t required_size = WINDOW_HEADER + 1; + + /* Check if interface has to be resized (terminal size changed) */ + getmaxyx(stdscr, max_row, max_col); + + if (max_row != g_max_row || max_col != g_max_col) { + if (max_row != g_max_row) { + *current_page = 0; + } + g_max_row = spdk_max(max_row, required_size); + g_max_col = max_col; + g_data_win_size = g_max_row - required_size + 1; + g_max_data_rows = g_max_row - WINDOW_HEADER; + resize_interface(active_tab); + } +} + static void change_refresh_rate(void) { @@ -2882,11 +2903,9 @@ show_stats(pthread_t *data_thread) long int time_last, time_dif; struct timespec time_now; int c; - int max_row, max_col; uint8_t active_tab = THREADS_TAB; uint8_t current_page = 0; uint8_t max_pages = 1; - uint16_t required_size = WINDOW_HEADER + 1; uint64_t i; char current_page_str[CURRENT_PAGE_STR_LEN]; bool force_refresh = true; @@ -2897,19 +2916,7 @@ show_stats(pthread_t *data_thread) switch_tab(THREADS_TAB); while (1) { - /* Check if interface has to be resized (terminal size changed) */ - getmaxyx(stdscr, max_row, max_col); - - if (max_row != g_max_row || max_col != g_max_col) { - if (max_row != g_max_row) { - current_page = 0; - } - g_max_row = spdk_max(max_row, required_size); - g_max_col = max_col; - g_data_win_size = g_max_row - required_size + 1; - g_max_data_rows = g_max_row - WINDOW_HEADER; - resize_interface(active_tab); - } + check_resize_interface(active_tab, ¤t_page); clock_gettime(CLOCK_MONOTONIC, &time_now); time_dif = time_now.tv_sec - time_last;