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 <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7947 (master)
(cherry picked from commit e2b6cf2f96
)
Change-Id: I9368b4567a92ca20d830c3475e3120ee691b84c1
Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8108
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
10b7805b0f
commit
b20db89532
@ -546,6 +546,64 @@ rpc_send_req(char *rpc_name, struct spdk_jsonrpc_client_response **resp)
|
|||||||
return 0;
|
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
|
static int
|
||||||
get_data(void)
|
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);
|
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
|
static void
|
||||||
draw_row_background(uint8_t item_index, uint8_t tab)
|
draw_row_background(uint8_t item_index, uint8_t tab)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user