add build glue and local fixes

This commit is contained in:
christos 2008-07-16 00:36:14 +00:00
parent 10dd2532a5
commit 2b60e3f28a
12 changed files with 1105 additions and 292 deletions

5
external/bsd/top/Makefile vendored Normal file
View File

@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2008/07/16 00:36:14 christos Exp $
SUBDIR= usr.bin
.include <bsd.subdir.mk>

View File

@ -501,6 +501,7 @@ renice_procs(char *str)
if (procnum == -1 || prio < PRIO_MIN || prio > PRIO_MAX)
{
message_error(" renice: bad priority value");
return;
}
#endif
@ -508,6 +509,7 @@ renice_procs(char *str)
if ((str = next_field(str)) == NULL)
{
message_error(" remice: no processes specified");
return;
}
#ifdef HAVE_SETPRIORITY
@ -900,6 +902,16 @@ cmd_threads(globalstate *gstate)
return CMD_NA;
}
int
cmd_percpustates(globalstate *gstate)
{
gstate->percpustates = !gstate->percpustates;
gstate->fulldraw = Yes;
gstate->max_topn += display_setmulti(gstate->percpustates);
return CMD_REFRESH;
}
/* forward reference for cmd_help, as it needs to see the command_table */
int cmd_help(globalstate *gstate);
@ -909,6 +921,7 @@ command command_table[] = {
{ ' ', cmd_update, "update screen" },
{ '?', cmd_help, "help; show this text" },
{ 'h', cmd_help, NULL },
{ '1', cmd_percpustates, "toggle the detail per cpu of cpustates" },
{ 'C', cmd_color, "toggle the use of color" },
{ 'H', cmd_threads, "toggle the display of individual threads" },
{ 't', cmd_threads, NULL },

View File

@ -80,6 +80,7 @@ extern int overstrike;
static int lmpid = -1;
static int display_width = MAX_COLS;
static int ncpu = 0;
/* cursor positions of key points on the screen are maintained here */
/* layout.h has static definitions, but we may change our minds on some
@ -118,6 +119,7 @@ static char *screenbuf = NULL;
static char *colorbuf = NULL;
static char scratchbuf[MAX_COLS];
static int bufsize = 0;
static int multi = 0;
/* lineindex tells us where the beginning of a line is in the buffer */
#define lineindex(l) ((l)*MAX_COLS)
@ -746,7 +748,42 @@ display_columns()
*/
int
display_init(struct statics *statics)
display_setmulti(int m)
{
int i;
if (m == multi)
return 0;
if ((multi = m) != 0) {
for (i = 1; i < ncpu; i++)
{
/* adjust screen placements */
y_kernel++;
y_mem++;
y_swap++;
y_message++;
y_header++;
y_idlecursor++;
y_procs++;
}
return (ncpu - 1);
} else {
for (i = 1; i < ncpu; i++)
{
/* adjust screen placements */
y_kernel--;
y_mem--;
y_swap--;
y_message--;
y_header--;
y_idlecursor--;
y_procs--;
}
return -(ncpu - 1);
}
}
int
display_init(struct statics *statics, int percpuinfo)
{
register int top_lines;
@ -758,6 +795,7 @@ display_init(struct statics *statics)
/* certain things may influence the screen layout,
so look at those first */
ncpu = statics->ncpu ? statics->ncpu : 1;
/* a kernel line shifts parts of the display down */
kernel_names = statics->kernel_names;
if ((num_kernel = string_count(kernel_names)) > 0)
@ -771,6 +809,8 @@ display_init(struct statics *statics)
y_procs++;
}
(void)display_setmulti(percpuinfo);
/* a swap line shifts parts of the display down one */
swap_names = statics->swap_names;
if ((num_swap = string_count(swap_names)) > 0)
@ -795,7 +835,7 @@ display_init(struct statics *statics)
cpustate_names = statics->cpustate_names;
num_cpustates = string_count(cpustate_names);
lcpustates = (int *)calloc(num_cpustates, sizeof(int));
lcpustates = (int *)calloc(num_cpustates, sizeof(int) * ncpu);
cpustate_columns = (int *)calloc(num_cpustates, sizeof(int));
memory_names = statics->memory_names;
num_memory = string_count(memory_names);
@ -1102,17 +1142,20 @@ u_procstates(int total, int *brkdn, int threads)
/* cpustates_tag() calculates the correct tag to use to label the line */
char *
cpustates_tag()
cpustates_tag(int c)
{
register char *use;
static char *short_tag = "CPU: ";
static char *long_tag = "CPU states: ";
static char fmttag[100];
char *short_tag = ncpu > 1 && multi ? "CPU%d: " : "CPU: ";
char *long_tag = ncpu > 1 && multi ? "CPU%d states: " : "CPU states: ";
/* if length + strlen(long_tag) >= screen_width, then we have to
use the shorter tag (we subtract 2 to account for ": ") */
if (cpustate_total_length + (int)strlen(long_tag) - 2 >= screen_width)
if (cpustate_total_length + (int)strlen(long_tag) - 2 - ((ncpu > 1) ? 1 : 0)
>= screen_width)
{
use = short_tag;
}
@ -1121,9 +1164,11 @@ cpustates_tag()
use = long_tag;
}
snprintf(fmttag, sizeof(fmttag), use, c);
/* set x_cpustates accordingly then return result */
x_cpustates = strlen(use);
return(use);
x_cpustates = strlen(fmttag);
return(fmttag);
}
void
@ -1138,43 +1183,54 @@ i_cpustates(int *states)
#ifdef ENABLE_COLOR
int *cidx = cpustate_cidx;
#endif
int c, i;
/* initialize */
names = cpustate_names;
colp = cpustate_columns;
/* print tag */
display_write(0, y_cpustates, 0, 0, cpustates_tag());
/* now walk thru the names and print the line */
while ((thisname = *names++) != NULL)
if (multi == 0 && ncpu > 1)
{
if (*thisname != '\0')
for (c = 1; c < ncpu; c++)
for (i = 0; i < num_cpustates; i++)
states[i] += states[c * num_cpustates + i];
for (i = 0; i < num_cpustates; i++)
states[i] /= ncpu;
}
for (c = 0; c < (multi ? ncpu : 1); c++)
{
/* print tag */
display_write(0, y_cpustates + c, 0, 0, cpustates_tag(c));
colp = cpustate_columns;
/* now walk thru the names and print the line */
for (i = 0, names = cpustate_names; ((thisname = *names++) != NULL);)
{
/* retrieve the value and remember it */
value = *states;
if (*thisname != '\0')
{
/* retrieve the value and remember it */
value = *states;
#ifdef ENABLE_COLOR
/* determine color number to use */
color = color_test(*cidx++, value/10);
/* determine color number to use */
color = color_test(*cidx++, value/10);
#endif
/* if percentage is >= 1000, print it as 100% */
display_fmt(x_cpustates + *colp, y_cpustates,
color, 0,
(value >= 1000 ? "%4.0f%% %s%s" : "%4.1f%% %s%s"),
((float)value)/10.,
thisname,
*names != NULL ? ", " : "");
/* if percentage is >= 1000, print it as 100% */
display_fmt(x_cpustates + *colp, y_cpustates + c,
color, 0,
(value >= 1000 ? "%4.0f%% %s%s" : "%4.1f%% %s%s"),
((float)value)/10.,
thisname,
*names != NULL ? ", " : "");
}
/* increment */
colp++;
states++;
}
/* increment */
colp++;
states++;
}
/* copy over values into "last" array */
memcpy(lcpustates, states, num_cpustates * sizeof(int));
memcpy(lcpustates, states, num_cpustates * sizeof(int) * ncpu);
}
void
@ -1182,7 +1238,7 @@ u_cpustates(int *states)
{
int value;
char **names = cpustate_names;
char **names;
char *thisname;
int *lp;
int *colp;
@ -1190,44 +1246,57 @@ u_cpustates(int *states)
#ifdef ENABLE_COLOR
int *cidx = cpustate_cidx;
#endif
int c, i;
lp = lcpustates;
colp = cpustate_columns;
/* we could be much more optimal about this */
while ((thisname = *names++) != NULL)
if (multi == 0 && ncpu > 1)
{
if (*thisname != '\0')
for (c = 1; c < ncpu; c++)
for (i = 0; i < num_cpustates; i++)
states[i] += states[c * num_cpustates + i];
for (i = 0; i < num_cpustates; i++)
states[i] /= ncpu;
}
for (c = 0; c < (multi ? ncpu : 1); c++)
{
colp = cpustate_columns;
/* we could be much more optimal about this */
for (names = cpustate_names; (thisname = *names++) != NULL;)
{
/* did the value change since last time? */
if (*lp != *states)
if (*thisname != '\0')
{
/* yes, change it */
/* retrieve value and remember it */
value = *states;
/* did the value change since last time? */
if (*lp != *states)
{
/* yes, change it */
/* retrieve value and remember it */
value = *states;
#ifdef ENABLE_COLOR
/* determine color number to use */
color = color_test(*cidx, value/10);
/* determine color number to use */
color = color_test(*cidx, value/10);
#endif
/* if percentage is >= 1000, print it as 100% */
display_fmt(x_cpustates + *colp, y_cpustates, color, 0,
(value >= 1000 ? "%4.0f" : "%4.1f"),
((double)value)/10.);
/* if percentage is >= 1000, print it as 100% */
display_fmt(x_cpustates + *colp, y_cpustates + c, color, 0,
(value >= 1000 ? "%4.0f" : "%4.1f"),
((double)value)/10.);
/* remember it for next time */
*lp = value;
/* remember it for next time */
*lp = value;
}
#ifdef ENABLE_COLOR
cidx++;
#endif
}
#ifdef ENABLE_COLOR
cidx++;
#endif
}
/* increment and move on */
lp++;
states++;
colp++;
/* increment and move on */
lp++;
states++;
colp++;
}
}
}
@ -1235,26 +1304,29 @@ void
z_cpustates()
{
register int i = 0;
register int i, c;
register char **names = cpustate_names;
register char *thisname;
register int *lp;
/* print tag */
display_write(0, y_cpustates, 0, 0, cpustates_tag());
while ((thisname = *names++) != NULL)
for (c = 0; c < (multi ? ncpu : 1); c++)
{
if (*thisname != '\0')
display_write(0, y_cpustates + c, 0, 0, cpustates_tag(c));
for (i = 0, names = cpustate_names; (thisname = *names++) != NULL;)
{
display_fmt(-1, -1, 0, 0, "%s %% %s", i++ == 0 ? "" : ", ",
thisname);
if (*thisname != '\0')
{
display_fmt(-1, -1, 0, 0, "%s %% %s", i++ == 0 ? "" : ", ",
thisname);
}
}
}
/* fill the "last" array with all -1s, to insure correct updating */
lp = lcpustates;
i = num_cpustates;
i = num_cpustates * ncpu;
while (--i >= 0)
{
*lp++ = -1;

View File

@ -40,8 +40,9 @@
void display_clear();
int display_resize();
int display_lines();
int display_setmulti(int m);
int display_columns();
int display_init(struct statics *statics);
int display_init(struct statics *statics, int percpuinfo);
void i_loadave(int mpid, double *avenrun);
void u_loadave(int mpid, double *avenrun);
void i_minibar(int (*formatter)(char *, int));

View File

@ -55,6 +55,7 @@ typedef struct globalstate {
int use_color;
int smart_terminal;
int interactive;
int percpustates;
char *header_text;
char *order_name; /* only used before call to machine_init */
char *order_namelist;

View File

@ -56,6 +56,7 @@ struct statics
char **kernel_names; /* optional */
time_t boottime; /* optional */
int modemax; /* optional */
int ncpu; /* optional */
struct {
unsigned int fullcmds : 1;
unsigned int idle : 1;

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ top \- display and update information about the top cpu processes
.SH SYNOPSIS
.B top
[
.B \-CISTabcinqtuv
.B \-1CISTabcinqtuv
] [
.BI \-d count
] [
@ -64,6 +64,9 @@ terminal.
.SH OPTIONS
.if \nL==0 Long options are not available on this system.
.TP
.B "\-1, \-\-percpustates"
Display per-cpu states on a multi-processor machine.
.TP
.B "\-C, \-\-color"
Turn off the use of color in the display.
.TP

View File

@ -300,6 +300,7 @@ release_signals(void *parm)
#ifdef HAVE_GETOPT_LONG
static struct option longopts[] = {
{ "percpustates", no_argument, NULL, '1' },
{ "color", no_argument, NULL, 'C' },
{ "debug", no_argument, NULL, 'D' },
{ "system-procs", no_argument, NULL, 'S' },
@ -333,13 +334,18 @@ do_arguments(globalstate *gstate, int ac, char **av)
optind = 1;
#ifdef HAVE_GETOPT_LONG
while ((i = getopt_long(ac, av, "CDSITabcinqtuvs:d:U:o:m:", longopts, NULL)) != -1)
while ((i = getopt_long(ac, av, "1CDSITabcinqtuvs:d:U:o:m:", longopts, NULL)) != -1)
#else
while ((i = getopt(ac, av, "CDSITabcinqtuvs:d:U:o:m:")) != EOF)
while ((i = getopt(ac, av, "1CDSITabcinqtuvs:d:U:o:m:")) != EOF)
#endif
{
switch(i)
{
case '1':
gstate->percpustates = !gstate->percpustates;
gstate->fulldraw = Yes;
gstate->max_topn += display_setmulti(gstate->percpustates);
break;
#ifdef ENABLE_COLOR
case 'C':
gstate->use_color = !gstate->use_color;
@ -755,10 +761,11 @@ main(int argc, char *argv[])
gstate->fulldraw = Yes;
gstate->use_color = Yes;
gstate->interactive = Maybe;
gstate->percpustates = Yes;
/* preset defaults for process selection */
gstate->pselect.idle = Yes;
gstate->pselect.system = No;
gstate->pselect.system = Yes;
gstate->pselect.fullcmd = No;
gstate->pselect.command = NULL;
gstate->pselect.uid = -1;
@ -874,7 +881,7 @@ main(int argc, char *argv[])
gstate->pselect.usernames = gstate->show_usernames;
/* initialize display */
if ((gstate->max_topn = display_init(&statics)) == -1)
if ((gstate->max_topn = display_init(&statics, gstate->percpustates)) == -1)
{
fprintf(stderr, "%s: can't allocate sufficient memory\n", myname);
exit(EX_OSERR);

5
external/bsd/top/usr.bin/Makefile vendored Normal file
View File

@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2008/07/16 00:36:15 christos Exp $
SUBDIR= top
.include <bsd.subdir.mk>

32
external/bsd/top/usr.bin/top/Makefile vendored Normal file
View File

@ -0,0 +1,32 @@
# $NetBSD: Makefile,v 1.1 2008/07/16 00:36:15 christos Exp $
.include <bsd.own.mk>
PROG= top
TOPDIR=${.CURDIR}/../../dist
.PATH: ${TOPDIR} ${TOPDIR}/machine
CPPFLAGS+=-I${.CURDIR} -I${TOPDIR} -I. -DORDER -DHAVE_STRERROR
SRCS= color.c commands.c display.c hash.c screen.c \
top.c username.c utils.c version.c m_netbsd.c
DPSRCS+=sigdesc.h
LDADD+= -ltermcap -lm -lkvm
DPADD+= ${LIBTERMCAP} ${LIBM} ${LIBKVM}
sigdesc.h: ${TOPDIR}/sigconv.awk ${DESTDIR}/usr/include/sys/signal.h
${_MKTARGET_CREATE}
awk -f ${TOPDIR}/sigconv.awk ${DESTDIR}/usr/include/sys/signal.h > \
${.TARGET}
CLEANFILES+= sigdesc.h top.1
top.1: top.1.in
${TOOL_SED} -e s/@DEFAULT_TOPN@/-1/ \
-e s/@DEFAULT_DELAY@/5/ \
-e s/@HAVE_GETOPT_LONG@/1/ \
-e s/@ENABLE_KILL@/1/ \
-e s/@MAN_SUPPLEMENT@// < $? > $@
commands.c: sigdesc.h
.include <bsd.prog.mk>

257
external/bsd/top/usr.bin/top/config.h vendored Normal file
View File

@ -0,0 +1,257 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Support for debugging output */
/* #undef DEBUG */
/* Default delay */
#define DEFAULT_DELAY 5
/* Default number of processes to display */
#define DEFAULT_TOPN -1
/* Enable color */
#define ENABLE_COLOR 1
/* Enable dual architecture */
/* #undef ENABLE_DUALARCH */
/* Enable kill and renice */
#define ENABLE_KILL 1
/* Supports C99 style variadic macros */
#define HAVE_C99_VARIADIC_MACROS 1
/* Define to 1 if you have the <curses.h> header file. */
#define HAVE_CURSES_H 1
/* Define to 1 if you have the declaration of `sys_errlist', and to 0 if you
don't. */
#define HAVE_DECL_SYS_ERRLIST 0
/* Define to 1 if you have the declaration of `sys_signame', and to 0 if you
don't. */
#define HAVE_DECL_SYS_SIGNAME 1
/* Define to 1 if you have the declaration of `tgetent', and to 0 if you
don't. */
#define HAVE_DECL_TGETENT 1
/* Define to 1 if you have the declaration of `tgetflag', and to 0 if you
don't. */
#define HAVE_DECL_TGETFLAG 1
/* Define to 1 if you have the declaration of `tgetnum', and to 0 if you
don't. */
#define HAVE_DECL_TGETNUM 1
/* Define to 1 if you have the declaration of `tgetstr', and to 0 if you
don't. */
#define HAVE_DECL_TGETSTR 1
/* Define to 1 if you have the declaration of `tgoto', and to 0 if you don't.
*/
#define HAVE_DECL_TGOTO 1
/* Define to 1 if you have the declaration of `tputs', and to 0 if you don't.
*/
#define HAVE_DECL_TPUTS 1
/* Platform module */
#define HAVE_FORMAT_PROCESS_HEADER 1
/* Define to 1 if you have the `getopt' function. */
#define HAVE_GETOPT 1
/* Define to 1 if you have the <getopt.h> header file. */
#define HAVE_GETOPT_H 1
/* Define to 1 if you have the `getopt_long' function. */
#define HAVE_GETOPT_LONG 1
/* Define to 1 if you have the `gettimeofday' function. */
#define HAVE_GETTIMEOFDAY 1
/* Supports gnu style variadic macros */
#define HAVE_GNU_VARIADIC_MACROS 1
/* Define to 1 if the system has the type `id_t'. */
#define HAVE_ID_T 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `elf' library (-lelf). */
/* #undef HAVE_LIBELF */
/* Define to 1 if you have the `kstat' library (-lkstat). */
/* #undef HAVE_LIBKSTAT */
/* Define to 1 if you have the `kvm' library (-lkvm). */
#define HAVE_LIBKVM 1
/* Define to 1 if you have the `m' library (-lm). */
#define HAVE_LIBM 1
/* Define to 1 if you have the `mach' library (-lmach). */
/* #undef HAVE_LIBMACH */
/* Define to 1 if you have the `mas' library (-lmas). */
/* #undef HAVE_LIBMAS */
/* Define to 1 if you have the `perfstat' library (-lperfstat). */
/* #undef HAVE_LIBPERFSTAT */
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if the system has the type `lwpid_t'. */
#define HAVE_LWPID_T 1
/* Define to 1 if you have the <math.h> header file. */
#define HAVE_MATH_H 1
/* Define to 1 if you have the `memcpy' function. */
#define HAVE_MEMCPY 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if the system has the type `pid_t'. */
#define HAVE_PID_T 1
/* Define to 1 if you have the `setbuffer' function. */
#define HAVE_SETBUFFER 1
/* Define to 1 if you have the `setpriority' function. */
#define HAVE_SETPRIORITY 1
/* Define to 1 if you have the `setvbuf' function. */
#define HAVE_SETVBUF 1
/* Define to 1 if you have the `sigaction' function. */
#define HAVE_SIGACTION 1
/* Define to 1 if you have the `sighold' function. */
#define HAVE_SIGHOLD 1
/* Define to 1 if you have the `sigprocmask' function. */
#define HAVE_SIGPROCMASK 1
/* Define to 1 if you have the `sigrelse' function. */
#define HAVE_SIGRELSE 1
/* Define to 1 if you have the `snprintf' function. */
#define HAVE_SNPRINTF 1
/* Define to 1 if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strcasecmp' function. */
#define HAVE_STRCASECMP 1
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
/* Define to 1 if you have the `strerror' function. */
#define HAVE_STRERROR 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the `sysconf' function. */
#define HAVE_SYSCONF 1
/* Define to 1 if you have the <sysexits.h> header file. */
#define HAVE_SYSEXITS_H 1
/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <sys/utsname.h> header file. */
#define HAVE_SYS_UTSNAME_H 1
/* Define to 1 if you have the <termcap.h> header file. */
#define HAVE_TERMCAP_H 1
/* Define to 1 if you have the <term.h> header file. */
/* #undef HAVE_TERM_H */
/* Define to 1 if the system has the type `time_t'. */
#define HAVE_TIME_T 1
/* Define to 1 if the system has the type `uid_t'. */
#define HAVE_UID_T 1
/* Define to 1 if you have the `uname' function. */
#define HAVE_UNAME 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the `vsnprintf' function. */
#define HAVE_VSNPRINTF 1
/* Platform module */
#define MODULE "netbsd"
/* Default number of processes to display on non-terminals when topn is all */
#define NOMINAL_TOPN 40
/* Define the major OS revision number. */
#define OSMAJOR 4
/* Define the OS revision. */
#define OSREV 49962
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "top"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "top 3.8beta1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "top"
/* Define to the version of this package. */
#define PACKAGE_VERSION "3.8beta1"
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define as the type for the argument to the putc function of tputs ('int' or
'char') */
#define TPUTS_PUTC_ARGTYPE int
/* Define the system hardware platform */
#define UNAME_HARDWARE "amd64"
/* Include code that utilizes extensions */
/* #undef WITH_EXT */