diff options
author | bde <bde@FreeBSD.org> | 2006-05-04 03:56:31 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 2006-05-04 03:56:31 +0000 |
commit | c729a35120b54eabc514263fc466c2bf47b8e837 (patch) | |
tree | 63848bdeb82b0d0ae28394c5f2d187520bee26c0 /usr.bin/top | |
parent | 22a2f7851bc06a12021172e38fcf829f6274bf90 (diff) | |
download | FreeBSD-src-c729a35120b54eabc514263fc466c2bf47b8e837.zip FreeBSD-src-c729a35120b54eabc514263fc466c2bf47b8e837.tar.gz |
Move the formatting of the NICE column to a new function format_nice()
so that it can be more easily unbroken and extended.
Try to use `static', `const' (as appropriate), prototypes declared together,
and parameter names in prototypes for all private functions, not just the
new one.
Diffstat (limited to 'usr.bin/top')
-rw-r--r-- | usr.bin/top/machine.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index d7521a4..fb1823e 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -51,15 +51,12 @@ #include "screen.h" #include "utils.h" -static void getsysctl(char *, void *, size_t); - #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) #define SMPUNAMELEN 13 #define UPUNAMELEN 15 extern struct process_select ps; extern char* printable(char *); -int swapmode(int *retavail, int *retfree); static int smpmode; enum displaymodes displaymode; static int namelength = 8; @@ -67,7 +64,6 @@ static int cmdlengthdelta; /* Prototypes for top internals */ void quit(int); -int compare_pid(const void *a, const void *b); /* get_process_info passes back a handle. This is what it looks like: */ @@ -109,7 +105,7 @@ static char smp_header[] = " PID %-*.*s " "PRI NICE SIZE RES STATE C TIME %6s COMMAND"; #define smp_Proc_format \ - "%5d %-*.*s %s%3d %4d%7s %6s %-6.6s %1x%7s %5.2f%% %.*s" + "%5d %-*.*s %s%3d %4s%7s %6s %-6.6s %1x%7s %5.2f%% %.*s" static char up_header_thr[] = " PID %-*.*s THR PRI NICE SIZE RES STATE TIME %6s COMMAND"; @@ -117,7 +113,7 @@ static char up_header[] = " PID %-*.*s " "PRI NICE SIZE RES STATE TIME %6s COMMAND"; #define up_Proc_format \ - "%5d %-*.*s %s%3d %4d%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s" + "%5d %-*.*s %s%3d %4s%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s" /* process state names for the "STATE" column of the display */ @@ -218,6 +214,11 @@ char *ordernames[] = { }; #endif +static int compare_pid(const void *a, const void *b); +static const char *format_nice(const struct kinfo_proc *pp); +static void getsysctl(const char *name, void *ptr, size_t len); +static int swapmode(int *retavail, int *retfree); + int machine_init(struct statics *statics) { @@ -767,17 +768,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int)) namelength, namelength, (*get_userid)(pp->ki_ruid), thr_buf, pp->ki_pri.pri_level - PZERO, - - /* - * normal time -> nice value -20 - +20 - * real time 0 - 31 -> nice value -52 - -21 - * idle time 0 - 31 -> nice value +21 - +52 - */ - (pp->ki_pri.pri_class == PRI_TIMESHARE ? - pp->ki_nice - NZERO : - (PRI_IS_REALTIME(pp->ki_pri.pri_class) ? - (PRIO_MIN - 1 - (PRI_MAX_REALTIME - pp->ki_pri.pri_level)) : - (PRIO_MAX + 1 + pp->ki_pri.pri_level - PRI_MIN_IDLE))), + format_nice(pp), format_k2(PROCSIZE(pp)), format_k2(pagetok(pp->ki_rssize)), status, @@ -792,7 +783,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int)) } static void -getsysctl(char *name, void *ptr, size_t len) +getsysctl(const char *name, void *ptr, size_t len) { size_t nlen = len; @@ -808,9 +799,28 @@ getsysctl(char *name, void *ptr, size_t len) } } +static +const char *format_nice(const struct kinfo_proc *pp) +{ + static char nicebuf[5]; + + snprintf(nicebuf, sizeof(nicebuf), "%4d", + /* + * normal time -> nice value -20 - +20 + * real time 0 - 31 -> nice value -52 - -21 + * idle time 0 - 31 -> nice value +21 - +52 + */ + (pp->ki_pri.pri_class == PRI_TIMESHARE ? + pp->ki_nice - NZERO : + (PRI_IS_REALTIME(pp->ki_pri.pri_class) ? + (PRIO_MIN - 1 - (PRI_MAX_REALTIME - pp->ki_pri.pri_level)) : + (PRIO_MAX + 1 + pp->ki_pri.pri_level - PRI_MIN_IDLE)))); + return (nicebuf); +} + /* comparison routines for qsort */ -int +static int compare_pid(const void *p1, const void *p2) { const struct kinfo_proc * const *pp1 = p1; @@ -1143,7 +1153,7 @@ proc_owner(int pid) return (-1); } -int +static int swapmode(int *retavail, int *retfree) { int n; |