mirror of https://github.com/F-Stack/f-stack.git
Tools: top tool support display all cpu usage of multi-processes.
This commit is contained in:
parent
a8ea1bed90
commit
7f55b7899f
|
@ -102,26 +102,32 @@ For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?route).
|
|||
# top
|
||||
Usage:
|
||||
```
|
||||
top [-p <f-stack proc_id>] [-d <secs>] [-n num]
|
||||
top [-p <f-stack proc_id>] [-P <max proc_id>] [-d <secs>] [-n num]
|
||||
```
|
||||
Examples:
|
||||
```
|
||||
./sbin/top
|
||||
|
||||
|---------|---------|---------|---------------|
|
||||
| idle| sys| usr| loop|
|
||||
|---------|---------|---------|---------------|
|
||||
| 99.69%| 0.00%| 0.31%| 8214640|
|
||||
| 99.77%| 0.00%| 0.23%| 8205713|
|
||||
| 5.02%| 45.19%| 49.79%| 769435|
|
||||
| 0.00%| 19.88%| 80.12%| 393|
|
||||
| 0.00%| 20.28%| 79.72%| 395|
|
||||
| 0.00%| 15.50%| 84.50%| 403|
|
||||
| 0.00%| 31.31%| 68.69%| 427|
|
||||
| 32.07%| 8.78%| 59.15%| 2342862|
|
||||
| 99.79%| 0.00%| 0.21%| 9974439|
|
||||
| 99.81%| 0.00%| 0.19%| 7336153|
|
||||
| 99.79%| 0.00%| 0.21%| 8147676|
|
||||
./sbin/top -p 0 -P 3
|
||||
|---------|---------|---------|---------|---------------|
|
||||
| proc_id| idle| sys| usr| loop|
|
||||
|---------|---------|---------|---------|---------------|
|
||||
| total| 99.89%| 0.00%| 0.11%| 26384|
|
||||
| 0| 99.88%| 0.00%| 0.11%| 6597|
|
||||
| 1| 99.89%| 0.00%| 0.11%| 6598|
|
||||
| 2| 99.89%| 0.00%| 0.11%| 6593|
|
||||
| 3| 99.89%| 0.00%| 0.11%| 6596|
|
||||
| | | | | |
|
||||
| total| 99.89%| 0.00%| 0.11%| 26385|
|
||||
| 0| 99.89%| 0.00%| 0.11%| 6597|
|
||||
| 1| 99.89%| 0.00%| 0.11%| 6596|
|
||||
| 2| 99.89%| 0.00%| 0.11%| 6597|
|
||||
| 3| 99.88%| 0.00%| 0.12%| 6595|
|
||||
| | | | | |
|
||||
| total| 99.89%| 0.00%| 0.11%| 26390|
|
||||
| 0| 99.89%| 0.00%| 0.11%| 6599|
|
||||
| 1| 99.89%| 0.00%| 0.11%| 6597|
|
||||
| 2| 99.89%| 0.00%| 0.11%| 6598|
|
||||
| 3| 99.89%| 0.00%| 0.11%| 6596|
|
||||
| | | | | |
|
||||
```
|
||||
|
||||
# netstat
|
||||
|
|
|
@ -5,7 +5,7 @@ void
|
|||
usage(void)
|
||||
{
|
||||
printf("Usage:\n");
|
||||
printf(" top [-p <f-stack 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)
|
||||
|
@ -50,17 +50,30 @@ int cpu_status(struct ff_top_args *top)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
int ch, delay = 1, n = 0;
|
||||
unsigned int i;
|
||||
struct ff_top_args top, otop;
|
||||
unsigned int i, j;
|
||||
struct ff_top_args top = {0, 0, 0, 0, 0}, otop;
|
||||
struct ff_top_args ptop[RTE_MAX_LCORE], potop[RTE_MAX_LCORE];;
|
||||
int proc_id = 0, max_proc_id = -1;
|
||||
float psys, pusr, pidle;
|
||||
|
||||
ff_ipc_init();
|
||||
|
||||
#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)
|
||||
|
||||
while ((ch = getopt(argc, argv, "hp:d:n:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "hp:P:d:n:")) != -1) {
|
||||
switch(ch) {
|
||||
case 'p':
|
||||
ff_set_proc_id(atoi(optarg));
|
||||
proc_id = atoi(optarg);
|
||||
ff_set_proc_id(proc_id);
|
||||
break;
|
||||
case 'P':
|
||||
max_proc_id = atoi(optarg);
|
||||
if (max_proc_id < 0 || max_proc_id >= RTE_MAX_LCORE) {
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
delay = atoi(optarg) ?: 1;
|
||||
|
@ -76,23 +89,67 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
if (cpu_status(&top)) {
|
||||
printf("fstack ipc message error !\n");
|
||||
return -1;
|
||||
}
|
||||
if (max_proc_id == -1) {
|
||||
if (cpu_status(&top)) {
|
||||
printf("fstack ipc message error !\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (i % 40 == 0) {
|
||||
printf("|---------|---------|---------|---------------|\n");
|
||||
printf("|%9s|%9s|%9s|%15s|\n", "idle", "sys", "usr", "loop");
|
||||
printf("|---------|---------|---------|---------------|\n");
|
||||
}
|
||||
if (i % 40 == 0) {
|
||||
printf("|---------|---------|---------|---------------|\n");
|
||||
printf("|%9s|%9s|%9s|%15s|\n", "idle", "sys", "usr", "loop");
|
||||
printf("|---------|---------|---------|---------------|\n");
|
||||
}
|
||||
|
||||
if (i) {
|
||||
float psys = TOP_DIFF(sys_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
float pusr = TOP_DIFF(usr_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
float pidle = TOP_DIFF(idle_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
if (i) {
|
||||
psys = TOP_DIFF(sys_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
pusr = TOP_DIFF(usr_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
pidle = 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", pidle, psys, pusr, TOP_DIFF(loops));
|
||||
}
|
||||
}else {
|
||||
/*
|
||||
* get and show cpu usage from proc_id to max_proc_id.
|
||||
*/
|
||||
for (j = proc_id; j <= max_proc_id; j++) {
|
||||
ff_set_proc_id(j);
|
||||
if (cpu_status(&ptop[j])) {
|
||||
printf("fstack ipc message error, proc id:%d!\n", j);
|
||||
return -1;
|
||||
}
|
||||
|
||||
TOP_ADD_P(idle_tsc);
|
||||
TOP_ADD_P(loops);
|
||||
TOP_ADD_P(sys_tsc);
|
||||
TOP_ADD_P(usr_tsc);
|
||||
TOP_ADD_P(work_tsc);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
if (i) {
|
||||
psys = TOP_DIFF(sys_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
pusr = TOP_DIFF(usr_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
pidle = TOP_DIFF(idle_tsc) / (TOP_DIFF(work_tsc) / 100.0);
|
||||
printf("|%9s|%8.2f%%|%8.2f%%|%8.2f%%|%15lu|\n", "total", pidle, psys, pusr, TOP_DIFF(loops));
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
if (n && i >= n) {
|
||||
|
|
Loading…
Reference in New Issue