ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE->CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
This commit is contained in:
parent
c350485b18
commit
f246dc7f57
@ -445,7 +445,7 @@ typedef struct {
|
|||||||
char state[4];
|
char state[4];
|
||||||
unsigned long rss;
|
unsigned long rss;
|
||||||
int ppid;
|
int ppid;
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
unsigned pcpu;
|
unsigned pcpu;
|
||||||
unsigned pscpu;
|
unsigned pscpu;
|
||||||
unsigned long stime, utime;
|
unsigned long stime, utime;
|
||||||
|
@ -72,7 +72,7 @@ extern procps_status_t * procps_scan(int save_user_arg0)
|
|||||||
"%c %d "
|
"%c %d "
|
||||||
"%*s %*s %*s %*s " /* pgrp, session, tty, tpgid */
|
"%*s %*s %*s %*s " /* pgrp, session, tty, tpgid */
|
||||||
"%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
|
"%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
"%lu %lu "
|
"%lu %lu "
|
||||||
#else
|
#else
|
||||||
"%*s %*s "
|
"%*s %*s "
|
||||||
@ -83,12 +83,12 @@ extern procps_status_t * procps_scan(int save_user_arg0)
|
|||||||
"%*s " /* vsize */
|
"%*s " /* vsize */
|
||||||
"%ld",
|
"%ld",
|
||||||
curstatus.state, &curstatus.ppid,
|
curstatus.state, &curstatus.ppid,
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
&curstatus.utime, &curstatus.stime,
|
&curstatus.utime, &curstatus.stime,
|
||||||
#endif
|
#endif
|
||||||
&tasknice,
|
&tasknice,
|
||||||
&curstatus.rss);
|
&curstatus.rss);
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
if(n != 6)
|
if(n != 6)
|
||||||
#else
|
#else
|
||||||
if(n != 4)
|
if(n != 4)
|
||||||
|
@ -57,7 +57,7 @@ config CONFIG_TOP
|
|||||||
The top program provides a dynamic real-time view of a running
|
The top program provides a dynamic real-time view of a running
|
||||||
system.
|
system.
|
||||||
|
|
||||||
config ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
config CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
bool " Support showing CPU usage percentage (add 2k bytes)"
|
bool " Support showing CPU usage percentage (add 2k bytes)"
|
||||||
default y
|
default y
|
||||||
depends on CONFIG_TOP
|
depends on CONFIG_TOP
|
||||||
|
32
procps/top.c
32
procps/top.c
@ -35,9 +35,9 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
//#define ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE /* + 2k */
|
//#define CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE /* + 2k */
|
||||||
|
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -62,7 +62,7 @@ static int mem_sort (procps_status_t *P, procps_status_t *Q)
|
|||||||
return (int)(Q->rss - P->rss);
|
return (int)(Q->rss - P->rss);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
|
|
||||||
#define sort_depth 3
|
#define sort_depth 3
|
||||||
static cmp_t sort_function[sort_depth];
|
static cmp_t sort_function[sort_depth];
|
||||||
@ -279,7 +279,7 @@ static void do_stats(void)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static cmp_t sort_function;
|
static cmp_t sort_function;
|
||||||
#endif /* ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE */
|
#endif /* CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE */
|
||||||
|
|
||||||
/* display generic info (meminfo / loadavg) */
|
/* display generic info (meminfo / loadavg) */
|
||||||
static unsigned long display_generic(void)
|
static unsigned long display_generic(void)
|
||||||
@ -368,7 +368,7 @@ static void display_status(int count, int col)
|
|||||||
char rss_str_buf[8];
|
char rss_str_buf[8];
|
||||||
unsigned long total_memory = display_generic();
|
unsigned long total_memory = display_generic();
|
||||||
|
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
/* what info of the processes is shown */
|
/* what info of the processes is shown */
|
||||||
printf("\n\e[7m PID USER STATUS RSS PPID %%CPU %%MEM COMMAND\e[0m\n");
|
printf("\n\e[7m PID USER STATUS RSS PPID %%CPU %%MEM COMMAND\e[0m\n");
|
||||||
#else
|
#else
|
||||||
@ -386,7 +386,7 @@ static void display_status(int count, int col)
|
|||||||
sprintf(rss_str_buf, "%6ldM", s->rss/1024);
|
sprintf(rss_str_buf, "%6ldM", s->rss/1024);
|
||||||
else
|
else
|
||||||
sprintf(rss_str_buf, "%7ld", s->rss);
|
sprintf(rss_str_buf, "%7ld", s->rss);
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
printf("%5d %-8s %s %s %5d %2d.%d %2u.%u ",
|
printf("%5d %-8s %s %s %5d %2d.%d %2u.%u ",
|
||||||
s->pid, s->user, s->state, rss_str_buf, s->ppid,
|
s->pid, s->user, s->state, rss_str_buf, s->ppid,
|
||||||
s->pcpu/10, s->pcpu%10, pmem/10, pmem%10);
|
s->pcpu/10, s->pcpu%10, pmem/10, pmem%10);
|
||||||
@ -422,7 +422,7 @@ static void reset_term(void)
|
|||||||
tcsetattr(0, TCSANOW, (void *) &initial_settings);
|
tcsetattr(0, TCSANOW, (void *) &initial_settings);
|
||||||
#ifdef CONFIG_FEATURE_CLEAN_UP
|
#ifdef CONFIG_FEATURE_CLEAN_UP
|
||||||
clearmems();
|
clearmems();
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
free(save_history);
|
free(save_history);
|
||||||
#endif
|
#endif
|
||||||
#endif /* CONFIG_FEATURE_CLEAN_UP */
|
#endif /* CONFIG_FEATURE_CLEAN_UP */
|
||||||
@ -463,7 +463,7 @@ int top_main(int argc, char **argv)
|
|||||||
/* Default to 25 lines - 5 lines for status */
|
/* Default to 25 lines - 5 lines for status */
|
||||||
lines = 25 - 5;
|
lines = 25 - 5;
|
||||||
/* Default CMD format size */
|
/* Default CMD format size */
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
col = 35 - 6;
|
col = 35 - 6;
|
||||||
#else
|
#else
|
||||||
col = 35;
|
col = 35;
|
||||||
@ -491,7 +491,7 @@ int top_main(int argc, char **argv)
|
|||||||
get_terminal_width_height(0, &col, &lines);
|
get_terminal_width_height(0, &col, &lines);
|
||||||
if (lines > 4) {
|
if (lines > 4) {
|
||||||
lines -= 5;
|
lines -= 5;
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
col = col - 80 + 35 - 6;
|
col = col - 80 + 35 - 6;
|
||||||
#else
|
#else
|
||||||
col = col - 80 + 35;
|
col = col - 80 + 35;
|
||||||
@ -499,13 +499,13 @@ int top_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_FEATURE_USE_TERMIOS */
|
#endif /* CONFIG_FEATURE_USE_TERMIOS */
|
||||||
|
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
sort_function[0] = pcpu_sort;
|
sort_function[0] = pcpu_sort;
|
||||||
sort_function[1] = mem_sort;
|
sort_function[1] = mem_sort;
|
||||||
sort_function[2] = time_sort;
|
sort_function[2] = time_sort;
|
||||||
#else
|
#else
|
||||||
sort_function = mem_sort;
|
sort_function = mem_sort;
|
||||||
#endif /* ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE */
|
#endif /* CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE */
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* read process IDs & status for all the processes */
|
/* read process IDs & status for all the processes */
|
||||||
@ -520,7 +520,7 @@ int top_main(int argc, char **argv)
|
|||||||
if (ntop == 0) {
|
if (ntop == 0) {
|
||||||
bb_perror_msg_and_die("scandir('/proc')");
|
bb_perror_msg_and_die("scandir('/proc')");
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
if(!Hertz) {
|
if(!Hertz) {
|
||||||
init_Hertz_value();
|
init_Hertz_value();
|
||||||
do_stats();
|
do_stats();
|
||||||
@ -531,7 +531,7 @@ int top_main(int argc, char **argv)
|
|||||||
do_stats();
|
do_stats();
|
||||||
#else
|
#else
|
||||||
qsort(top, ntop, sizeof(procps_status_t), (void*)sort_function);
|
qsort(top, ntop, sizeof(procps_status_t), (void*)sort_function);
|
||||||
#endif /* ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE */
|
#endif /* CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE */
|
||||||
opt = lines;
|
opt = lines;
|
||||||
if (opt > ntop) {
|
if (opt > ntop) {
|
||||||
opt = ntop;
|
opt = ntop;
|
||||||
@ -551,7 +551,7 @@ int top_main(int argc, char **argv)
|
|||||||
if(c == 'q' || c == initial_settings.c_cc[VINTR])
|
if(c == 'q' || c == initial_settings.c_cc[VINTR])
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
if(c == 'M') {
|
if(c == 'M') {
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
sort_function[0] = mem_sort;
|
sort_function[0] = mem_sort;
|
||||||
sort_function[1] = pcpu_sort;
|
sort_function[1] = pcpu_sort;
|
||||||
sort_function[2] = time_sort;
|
sort_function[2] = time_sort;
|
||||||
@ -559,7 +559,7 @@ int top_main(int argc, char **argv)
|
|||||||
sort_function = mem_sort;
|
sort_function = mem_sort;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
if(c == 'P') {
|
if(c == 'P') {
|
||||||
sort_function[0] = pcpu_sort;
|
sort_function[0] = pcpu_sort;
|
||||||
sort_function[1] = mem_sort;
|
sort_function[1] = mem_sort;
|
||||||
@ -572,7 +572,7 @@ int top_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(c == 'N') {
|
if(c == 'N') {
|
||||||
#ifdef ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
sort_function[0] = pid_sort;
|
sort_function[0] = pid_sort;
|
||||||
#else
|
#else
|
||||||
sort_function = pid_sort;
|
sort_function = pid_sort;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user