From b20db895320b9edeceb49b5d7a014367a8e315f5 Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Tue, 18 May 2021 14:35:10 +0200 Subject: [PATCH] spdk_top: move sort_threads function This function is going to be needed in get_data() in the next patch. Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7947 (master) (cherry picked from commit e2b6cf2f960e8c457f38a57a4ec28aab6ba9e3ac) Change-Id: I9368b4567a92ca20d830c3475e3120ee691b84c1 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8108 Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris --- app/spdk_top/spdk_top.c | 115 ++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/app/spdk_top/spdk_top.c b/app/spdk_top/spdk_top.c index 84a2e20a3b..def4b1049d 100644 --- a/app/spdk_top/spdk_top.c +++ b/app/spdk_top/spdk_top.c @@ -546,6 +546,64 @@ rpc_send_req(char *rpc_name, struct spdk_jsonrpc_client_response **resp) return 0; } + +static int +sort_threads(const void *p1, const void *p2) +{ + const struct rpc_thread_info *thread_info1 = *(struct rpc_thread_info **)p1; + const struct rpc_thread_info *thread_info2 = *(struct rpc_thread_info **)p2; + uint64_t count1, count2; + + /* thread IDs may not be allocated contiguously, so we need + * to account for NULL thread_info pointers */ + if (thread_info1 == NULL && thread_info2 == NULL) { + return 0; + } else if (thread_info1 == NULL) { + return 1; + } else if (thread_info2 == NULL) { + return -1; + } + + switch (g_current_sort_col[THREADS_TAB]) { + case 0: /* Sort by name */ + return strcmp(thread_info1->name, thread_info2->name); + case 1: /* Sort by core */ + count2 = thread_info1->core_num; + count1 = thread_info2->core_num; + break; + case 2: /* Sort by active pollers number */ + count1 = thread_info1->active_pollers_count; + count2 = thread_info2->active_pollers_count; + break; + case 3: /* Sort by timed pollers number */ + count1 = thread_info1->timed_pollers_count; + count2 = thread_info2->timed_pollers_count; + break; + case 4: /* Sort by paused pollers number */ + count1 = thread_info1->paused_pollers_count; + count2 = thread_info2->paused_pollers_count; + break; + case 5: /* Sort by idle time */ + count1 = thread_info1->idle - thread_info1->last_idle; + count2 = thread_info2->idle - thread_info2->last_idle; + break; + case 6: /* Sort by busy time */ + count1 = thread_info1->busy - thread_info1->last_busy; + count2 = thread_info2->busy - thread_info2->last_busy; + break; + default: + return 0; + } + + if (count2 > count1) { + return 1; + } else if (count2 < count1) { + return -1; + } else { + return 0; + } +} + static int get_data(void) { @@ -797,63 +855,6 @@ get_time_str(uint64_t ticks, char *time_str) snprintf(time_str, MAX_TIME_STR_LEN, "%" PRIu64, time); } -static int -sort_threads(const void *p1, const void *p2) -{ - const struct rpc_thread_info *thread_info1 = *(struct rpc_thread_info **)p1; - const struct rpc_thread_info *thread_info2 = *(struct rpc_thread_info **)p2; - uint64_t count1, count2; - - /* thread IDs may not be allocated contiguously, so we need - * to account for NULL thread_info pointers */ - if (thread_info1 == NULL && thread_info2 == NULL) { - return 0; - } else if (thread_info1 == NULL) { - return 1; - } else if (thread_info2 == NULL) { - return -1; - } - - switch (g_current_sort_col[THREADS_TAB]) { - case 0: /* Sort by name */ - return strcmp(thread_info1->name, thread_info2->name); - case 1: /* Sort by core */ - count2 = thread_info1->core_num; - count1 = thread_info2->core_num; - break; - case 2: /* Sort by active pollers number */ - count1 = thread_info1->active_pollers_count; - count2 = thread_info2->active_pollers_count; - break; - case 3: /* Sort by timed pollers number */ - count1 = thread_info1->timed_pollers_count; - count2 = thread_info2->timed_pollers_count; - break; - case 4: /* Sort by paused pollers number */ - count1 = thread_info1->paused_pollers_count; - count2 = thread_info2->paused_pollers_count; - break; - case 5: /* Sort by idle time */ - count1 = thread_info1->idle - thread_info1->last_idle; - count2 = thread_info2->idle - thread_info2->last_idle; - break; - case 6: /* Sort by busy time */ - count1 = thread_info1->busy - thread_info1->last_busy; - count2 = thread_info2->busy - thread_info2->last_busy; - break; - default: - return 0; - } - - if (count2 > count1) { - return 1; - } else if (count2 < count1) { - return -1; - } else { - return 0; - } -} - static void draw_row_background(uint8_t item_index, uint8_t tab) {