Tools: update top.

This commit is contained in:
fengbojiang 2019-07-25 22:33:42 +08:00
parent 7f55b7899f
commit cea0be3c81
4 changed files with 63 additions and 55 deletions

View File

@ -99,10 +99,10 @@ static uint16_t rss_reta_size[RTE_MAX_ETHPORTS];
static inline int send_single_packet(struct rte_mbuf *m, uint8_t port); static inline int send_single_packet(struct rte_mbuf *m, uint8_t port);
struct ff_msg_ring { struct ff_msg_ring {
char ring_name[FF_MAX][RTE_RING_NAMESIZE]; char ring_name[FF_MSG_NUM][RTE_RING_NAMESIZE];
/* ring[0] for lcore recv msg, other send */ /* ring[0] for lcore recv msg, other send */
/* ring[1] for lcore send msg, other read */ /* ring[1] for lcore send msg, other read */
struct rte_ring *ring[FF_MAX]; struct rte_ring *ring[FF_MSG_NUM];
} __rte_cache_aligned; } __rte_cache_aligned;
static struct ff_msg_ring msg_ring[RTE_MAX_LCORE]; static struct ff_msg_ring msg_ring[RTE_MAX_LCORE];
@ -447,7 +447,7 @@ init_msg_ring(void)
if (msg_ring[i].ring[0] == NULL) if (msg_ring[i].ring[0] == NULL)
rte_panic("create ring::%s failed!\n", msg_ring[i].ring_name[0]); rte_panic("create ring::%s failed!\n", msg_ring[i].ring_name[0]);
for (j = FF_SYSCTL; j < FF_MAX; j++) { for (j = FF_SYSCTL; j < FF_MSG_NUM; j++) {
snprintf(msg_ring[i].ring_name[j], RTE_RING_NAMESIZE, snprintf(msg_ring[i].ring_name[j], RTE_RING_NAMESIZE,
"%s%u_%u", FF_MSG_RING_OUT, i, j); "%s%u_%u", FF_MSG_RING_OUT, i, j);
msg_ring[i].ring[j] = create_ring(msg_ring[i].ring_name[j], msg_ring[i].ring[j] = create_ring(msg_ring[i].ring_name[j],

View File

@ -46,9 +46,9 @@ enum FF_MSG_TYPE {
FF_TRAFFIC, FF_TRAFFIC,
/* /*
* to add other msg type before FF_MAX * to add other msg type before FF_MSG_NUM
*/ */
FF_MAX, FF_MSG_NUM,
}; };
struct ff_sysctl_args { struct ff_sysctl_args {

View File

@ -110,23 +110,23 @@ Examples:
|---------|---------|---------|---------|---------------| |---------|---------|---------|---------|---------------|
| proc_id| idle| sys| usr| loop| | proc_id| idle| sys| usr| loop|
|---------|---------|---------|---------|---------------| |---------|---------|---------|---------|---------------|
| total| 99.89%| 0.00%| 0.11%| 26384| | 0| 92.44%| 4.00%| 3.56%| 13427|
| 0| 99.88%| 0.00%| 0.11%| 6597| | 1| 92.18%| 4.21%| 3.61%| 14035|
| 1| 99.89%| 0.00%| 0.11%| 6598| | 2| 92.19%| 4.19%| 3.62%| 13929|
| 2| 99.89%| 0.00%| 0.11%| 6593| | 3| 92.33%| 4.14%| 3.53%| 13938|
| 3| 99.89%| 0.00%| 0.11%| 6596| | total| 369.14%| 16.54%| 14.32%| 55329|
| | | | | | | | | | | |
| total| 99.89%| 0.00%| 0.11%| 26385| | 0| 92.27%| 4.10%| 3.63%| 13438|
| 0| 99.89%| 0.00%| 0.11%| 6597| | 1| 92.03%| 4.27%| 3.70%| 13906|
| 1| 99.89%| 0.00%| 0.11%| 6596| | 2| 92.08%| 4.24%| 3.68%| 13817|
| 2| 99.89%| 0.00%| 0.11%| 6597| | 3| 92.28%| 4.15%| 3.57%| 13759|
| 3| 99.88%| 0.00%| 0.12%| 6595| | total| 368.65%| 16.77%| 14.58%| 54920|
| | | | | | | | | | | |
| total| 99.89%| 0.00%| 0.11%| 26390| | 0| 91.88%| 4.30%| 3.81%| 13802|
| 0| 99.89%| 0.00%| 0.11%| 6599| | 1| 91.94%| 4.32%| 3.74%| 13928|
| 1| 99.89%| 0.00%| 0.11%| 6597| | 2| 92.10%| 4.24%| 3.66%| 13856|
| 2| 99.89%| 0.00%| 0.11%| 6598| | 3| 92.30%| 4.14%| 3.56%| 13708|
| 3| 99.89%| 0.00%| 0.11%| 6596| | total| 368.22%| 17.00%| 14.77%| 55294|
| | | | | | | | | | | |
``` ```

View File

@ -5,7 +5,8 @@ void
usage(void) usage(void)
{ {
printf("Usage:\n"); printf("Usage:\n");
printf(" top [-p <f-stack proc_id>] [-P <max proc_id>] [-d <secs>] [-n <num]>\n"); printf(" top [-p <f-stack proc_id>] [-P <max proc_id>] "
"[-d <secs>] [-n <num>]\n");
} }
int cpu_status(struct ff_top_args *top) int cpu_status(struct ff_top_args *top)
@ -51,15 +52,16 @@ int main(int argc, char **argv)
{ {
int ch, delay = 1, n = 0; int ch, delay = 1, n = 0;
unsigned int i, j; unsigned int i, j;
struct ff_top_args top = {0, 0, 0, 0, 0}, otop; struct ff_top_args top, otop;
struct ff_top_args ptop[RTE_MAX_LCORE], potop[RTE_MAX_LCORE];; struct ff_top_args ptop[RTE_MAX_LCORE], potop[RTE_MAX_LCORE];
int proc_id = 0, max_proc_id = -1; int proc_id = 0, max_proc_id = -1;
float sys, usr, idle;
float psys, pusr, pidle; float psys, pusr, pidle;
unsigned long loops, ploops;
ff_ipc_init(); ff_ipc_init();
#define TOP_DIFF(member) (top.member - otop.member) #define TOP_DIFF(member) (top.member - otop.member)
#define TOP_ADD_P(member) (top.member += ptop[j].member - potop[j].member)
#define TOP_DIFF_P(member) (ptop[j].member - potop[j].member) #define TOP_DIFF_P(member) (ptop[j].member - potop[j].member)
while ((ch = getopt(argc, argv, "hp:P:d:n:")) != -1) { while ((ch = getopt(argc, argv, "hp:P:d:n:")) != -1) {
@ -102,53 +104,59 @@ int main(int argc, char **argv)
} }
if (i) { if (i) {
psys = TOP_DIFF(sys_tsc) / (TOP_DIFF(work_tsc) / 100.0); sys = TOP_DIFF(sys_tsc) / (TOP_DIFF(work_tsc) / 100.0);
pusr = TOP_DIFF(usr_tsc) / (TOP_DIFF(work_tsc) / 100.0); usr = TOP_DIFF(usr_tsc) / (TOP_DIFF(work_tsc) / 100.0);
pidle = TOP_DIFF(idle_tsc) / (TOP_DIFF(work_tsc) / 100.0); idle = TOP_DIFF(idle_tsc) / (TOP_DIFF(work_tsc) / 100.0);
printf("|%8.2f%%|%8.2f%%|%8.2f%%|%15lu|\n", pidle, psys, pusr, TOP_DIFF(loops)); printf("|%8.2f%%|%8.2f%%|%8.2f%%|%15lu|\n",
idle, sys, usr, TOP_DIFF(loops));
} }
}else { }else {
/* /*
* get and show cpu usage from proc_id to max_proc_id. * get and show cpu usage from proc_id to max_proc_id.
*/ */
if (i % (40 / (max_proc_id - proc_id + 2)) == 0) {
printf("|---------|---------|---------|"
"---------|---------------|\n");
printf("|%9s|%9s|%9s|%9s|%15s|\n",
"proc_id", "idle", "sys", "usr", "loop");
printf("|---------|---------|---------|"
"---------|---------------|\n");
}
sys = usr = idle = loops = 0;
for (j = proc_id; j <= max_proc_id; j++) { for (j = proc_id; j <= max_proc_id; j++) {
potop[j] = ptop[j];
ff_set_proc_id(j); ff_set_proc_id(j);
if (cpu_status(&ptop[j])) { if (cpu_status(&ptop[j])) {
printf("fstack ipc message error, proc id:%d!\n", j); printf("fstack ipc message error, proc id:%d!\n", j);
return -1; return -1;
} }
TOP_ADD_P(idle_tsc); if (i) {
TOP_ADD_P(loops); psys = TOP_DIFF_P(sys_tsc) / \
TOP_ADD_P(sys_tsc); (TOP_DIFF_P(work_tsc) / 100.0);
TOP_ADD_P(usr_tsc); pusr = TOP_DIFF_P(usr_tsc) / \
TOP_ADD_P(work_tsc); (TOP_DIFF_P(work_tsc) / 100.0);
} pidle = TOP_DIFF_P(idle_tsc) / \
(TOP_DIFF_P(work_tsc) / 100.0);
ploops = TOP_DIFF_P(loops);
printf("|%9d|%8.2f%%|%8.2f%%|%8.2f%%|%15lu|\n",
j, pidle, psys, pusr, ploops);
if (i % (40 / (max_proc_id - proc_id + 2)) == 0) { sys += psys;
printf("|---------|---------|---------|---------|---------------|\n"); usr += pusr;
printf("|%9s|%9s|%9s|%9s|%15s|\n", "proc_id", "idle", "sys", "usr", "loop"); idle += pidle;
printf("|---------|---------|---------|---------|---------------|\n"); loops += ploops;
}
if (i) { if (j == max_proc_id) {
psys = TOP_DIFF(sys_tsc) / (TOP_DIFF(work_tsc) / 100.0); printf("|%9s|%8.2f%%|%8.2f%%|%8.2f%%|%15lu|\n",
pusr = TOP_DIFF(usr_tsc) / (TOP_DIFF(work_tsc) / 100.0); "total", idle, sys, usr, loops);
pidle = TOP_DIFF(idle_tsc) / (TOP_DIFF(work_tsc) / 100.0); printf("| | | |"
printf("|%9s|%8.2f%%|%8.2f%%|%8.2f%%|%15lu|\n", "total", pidle, psys, pusr, TOP_DIFF(loops)); " | |\n");
}
for (j = proc_id; j <= max_proc_id; j++) {
psys = TOP_DIFF_P(sys_tsc) / (TOP_DIFF_P(work_tsc) / 100.0);
pusr = TOP_DIFF_P(usr_tsc) / (TOP_DIFF_P(work_tsc) / 100.0);
pidle = TOP_DIFF_P(idle_tsc) / (TOP_DIFF_P(work_tsc) / 100.0);
printf("|%9d|%8.2f%%|%8.2f%%|%8.2f%%|%15lu|\n", j, pidle, psys, pusr, TOP_DIFF_P(loops));
} }
printf("| | | | | |\n");
}
for (j = proc_id; j <= max_proc_id; j++) {
potop[j] = ptop[j];
} }
} }