diff --git a/app/spdk_top/spdk_top.c b/app/spdk_top/spdk_top.c index def4b1049d..72b05f6449 100644 --- a/app/spdk_top/spdk_top.c +++ b/app/spdk_top/spdk_top.c @@ -618,6 +618,9 @@ get_data(void) goto end; } + /* Free old threads values before allocating memory for new ones */ + free_rpc_threads_stats(&g_threads_stats); + /* Decode json */ memset(&g_threads_stats, 0, sizeof(g_threads_stats)); if (spdk_json_decode_object(json_resp->result, rpc_threads_stats_decoders, @@ -638,6 +641,9 @@ get_data(void) goto end; } + /* Free old pollers values before allocating memory for new ones */ + free_rpc_pollers_stats(&g_pollers_stats); + /* Decode json */ memset(&g_pollers_stats, 0, sizeof(g_pollers_stats)); if (spdk_json_decode_object(json_resp->result, rpc_pollers_stats_decoders, @@ -653,6 +659,9 @@ get_data(void) goto end; } + /* Free old cores values before allocating memory for new ones */ + free_rpc_cores_stats(&g_cores_stats); + /* Decode json */ memset(&g_cores_stats, 0, sizeof(g_cores_stats)); if (spdk_json_decode_object(json_resp->result, rpc_cores_stats_decoders, @@ -2084,18 +2093,12 @@ show_thread(uint8_t current_page) uint64_t thread_number = current_page * g_max_data_rows + g_selected_row; uint64_t i; - get_data(); - assert(thread_number < g_threads_stats.threads.threads_count); for (i = 0; i < g_threads_stats.threads.threads_count; i++) { thread_info[i] = &g_threads_stats.threads.thread_info[i]; } - qsort(thread_info, g_threads_stats.threads.threads_count, sizeof(thread_info[0]), sort_threads); - display_thread(thread_info[thread_number]); - - free_data(); } static void @@ -2125,8 +2128,6 @@ show_core(uint8_t current_page) bool stop_loop = false; char idle_time[MAX_TIME_STR_LEN], busy_time[MAX_TIME_STR_LEN]; - get_data(); - assert(core_number < g_cores_stats.cores.cores_count); for (i = 0; i < g_cores_stats.cores.cores_count; i++) { core_info[i] = &g_cores_stats.cores.core[i]; @@ -2232,8 +2233,6 @@ show_core(uint8_t current_page) del_panel(core_panel); delwin(core_win); - - free_data(); } static void @@ -2248,8 +2247,6 @@ show_poller(uint8_t current_page) char poller_period[MAX_TIME_STR_LEN]; int c; - get_data(); - prepare_poller_data(current_page, pollers, &count, current_page); assert(poller_number < count); @@ -2315,8 +2312,6 @@ show_poller(uint8_t current_page) del_panel(poller_panel); delwin(poller_win); - - free_data(); } static void @@ -2352,6 +2347,27 @@ show_stats(void) resize_interface(active_tab); } + clock_gettime(CLOCK_REALTIME, &time_now); + time_dif = time_now.tv_sec - time_last; + if (time_dif < 0) { + time_dif = g_sleep_time; + } + + if (time_dif >= g_sleep_time || force_refresh) { + time_last = time_now.tv_sec; + rc = get_data(); + if (rc) { + mvprintw(g_max_row - 1, g_max_col - strlen(refresh_error) - 2, refresh_error); + } + + max_pages = refresh_tab(active_tab, current_page); + + snprintf(current_page_str, CURRENT_PAGE_STR_LEN - 1, "Page: %d/%d", current_page + 1, max_pages); + mvprintw(g_max_row - 1, 1, current_page_str); + + refresh(); + } + c = getch(); if (c == 'q') { free_resources(); @@ -2430,30 +2446,8 @@ show_stats(void) force_refresh = false; break; } - - clock_gettime(CLOCK_REALTIME, &time_now); - time_dif = time_now.tv_sec - time_last; - if (time_dif < 0) { - time_dif = g_sleep_time; - } - - if (time_dif >= g_sleep_time || force_refresh) { - time_last = time_now.tv_sec; - rc = get_data(); - if (rc) { - mvprintw(g_max_row - 1, g_max_col - strlen(refresh_error) - 2, refresh_error); - } - - max_pages = refresh_tab(active_tab, current_page); - - snprintf(current_page_str, CURRENT_PAGE_STR_LEN - 1, "Page: %d/%d", current_page + 1, max_pages); - mvprintw(g_max_row - 1, 1, current_page_str); - - free_data(); - - refresh(); - } } + free_data(); } static void