CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: christos Date: Fri Apr 16 13:02:47 UTC 2021 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: go back to right-aligning the titles for CPU and WCPU. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.24 src/external/bsd/top/dist/machine/m_netbsd.c:1.25 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.24 Sat Apr 3 15:25:38 2021 +++ src/external/bsd/top/dist/machine/m_netbsd.c Fri Apr 16 09:02:47 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.25 2021/04/16 13:02:47 christos Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $ + * $Id: m_netbsd.c,v 1.25 2021/04/16 13:02:47 christos Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.25 2021/04/16 13:02:47 christos Exp $"); #endif #include @@ -103,14 +103,14 @@ struct handle { */ static char Proc_header[] = - " PID XPRI NICE SIZE RES STATE TIME WCPU CPU COMMAND"; + " PID XPRI NICE SIZE RES STATE TIME WCPUCPU COMMAND"; /* 0123456 -- field to fill in starts at header+6 */ #define PROC_UNAME_START 6 #define Proc_format \ "%5d %-8.8s %3d %4d%7s %5s %-9.9s%7s %5.*f%% %5.*f%% %s" static char Thread_header[] = - " PID LID XPRI STATE TIME WCPU CPU NAME COMMAND"; + " PID LID XPRI STATE TIME WCPUCPU NAME COMMAND"; /* 0123456 -- field to fill in starts at header+6 */ #define THREAD_UNAME_START 12 #define Thread_format \
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: christos Date: Sat Apr 3 19:25:38 UTC 2021 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: - Bump field width for state to accommodate > 9 CPUs - When star formatting to adjust the width, count the trailing number of digits starting backwards instead of using strcspn because the lwp name might contain other digits like wm0TxRx/10. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.23 src/external/bsd/top/dist/machine/m_netbsd.c:1.24 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.23 Sat Apr 27 10:10:01 2019 +++ src/external/bsd/top/dist/machine/m_netbsd.c Sat Apr 3 15:25:38 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $ + * $Id: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.24 2021/04/03 19:25:38 christos Exp $"); #endif #include @@ -57,6 +57,7 @@ __RCSID("$NetBSD: m_netbsd.c,v 1.23 2019 #include #include #include +#include #include #include #include @@ -102,18 +103,18 @@ struct handle { */ static char Proc_header[] = - " PID XPRI NICE SIZE RES STATE TIME WCPUCPU COMMAND"; + " PID XPRI NICE SIZE RES STATE TIME WCPU CPU COMMAND"; /* 0123456 -- field to fill in starts at header+6 */ #define PROC_UNAME_START 6 #define Proc_format \ - "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.*f%% %s" + "%5d %-8.8s %3d %4d%7s %5s %-9.9s%7s %5.*f%% %5.*f%% %s" static char Thread_header[] = - " PID LID XPRI STATE TIME WCPUCPU NAME COMMAND"; + " PID LID XPRI STATE TIME WCPU CPU NAME COMMAND"; /* 0123456 -- field to fill in starts at header+6 */ #define THREAD_UNAME_START 12 #define Thread_format \ -"%5d %5d %-8.8s %3d %-8.8s%7s %5.2f%% %5.2f%% %-9.9s %s" +"%5d %5d %-8.8s %3d %-9.9s%7s %5.2f%% %5.2f%% %-9.9s %s" /* * Process state names for the "STATE" column of the display. @@ -879,19 +880,25 @@ format_next_proc(caddr_t handle, char *( } static char * -countable(char *p, size_t l) +countable(char *p, size_t width) { - static const char digits[] = "0123456789"; - size_t first = strcspn(p, digits); // non digits - size_t last = strspn(p + first, digits); // trailing digits - size_t len = first + last; - if (p[len] || last == 0) // should be total and must have digits + size_t len = strlen(p); + if (len < width) { // shorter than width, ok return p; - if (len < l) // if shorter, done + } + size_t first, last = len - 1; + for (first = len - 1; isdigit((unsigned char)p[first]); first--) { + continue; + } + if (first == len - 1) { // no digits, ok return p; - if (l < last + 1) // if not enough for digits, done + } + first++; + last = len - first; + if (width < last + 1) { // if not enough for digits, done return p; - size_t start = l - last - 1; // compute starting point + } + size_t start = width - last - 1; // compute starting point p[start] = '*'; // put a star memmove(p + start + 1, p + first, last + 1); // move digits and NUL return p;
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: christos Date: Sat Apr 27 14:10:01 UTC 2019 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: simplify and explain To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.22 src/external/bsd/top/dist/machine/m_netbsd.c:1.23 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.22 Fri Apr 26 15:39:19 2019 +++ src/external/bsd/top/dist/machine/m_netbsd.c Sat Apr 27 10:10:01 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.22 2019/04/26 19:39:19 christos Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.22 2019/04/26 19:39:19 christos Exp $ + * $Id: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.22 2019/04/26 19:39:19 christos Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.23 2019/04/27 14:10:01 christos Exp $"); #endif #include @@ -882,19 +882,18 @@ static char * countable(char *p, size_t l) { static const char digits[] = "0123456789"; - size_t first = strcspn(p, digits); - size_t last = strspn(p + first, digits); - size_t len = first + last; - if (p[len] || last == 0) + size_t first = strcspn(p, digits); // non digits + size_t last = strspn(p + first, digits); // trailing digits + size_t len = first + last; + if (p[len] || last == 0) // should be total and must have digits return p; - if (len < l) + if (len < l) // if shorter, done return p; - if (l < last + 1) + if (l < last + 1) // if not enough for digits, done return p; - size_t start = l - last - 1; - p[start] = '*'; - memmove(p + start + 1, p + first, len - first); - p[l] = '\0'; + size_t start = l - last - 1; // compute starting point + p[start] = '*'; // put a star + memmove(p + start + 1, p + first, last + 1); // move digits and NUL return p; }
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: christos Date: Fri Apr 26 19:39:19 UTC 2019 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: for "countable" lwp names, try to display name* instead of truncating. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.21 src/external/bsd/top/dist/machine/m_netbsd.c:1.22 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.21 Tue Oct 30 17:15:09 2018 +++ src/external/bsd/top/dist/machine/m_netbsd.c Fri Apr 26 15:39:19 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.21 2018/10/30 21:15:09 kre Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.22 2019/04/26 19:39:19 christos Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.21 2018/10/30 21:15:09 kre Exp $ + * $Id: m_netbsd.c,v 1.22 2019/04/26 19:39:19 christos Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.21 2018/10/30 21:15:09 kre Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.22 2019/04/26 19:39:19 christos Exp $"); #endif #include @@ -879,6 +879,26 @@ format_next_proc(caddr_t handle, char *( } static char * +countable(char *p, size_t l) +{ + static const char digits[] = "0123456789"; + size_t first = strcspn(p, digits); + size_t last = strspn(p + first, digits); + size_t len = first + last; + if (p[len] || last == 0) + return p; + if (len < l) + return p; + if (l < last + 1) + return p; + size_t start = l - last - 1; + p[start] = '*'; + memmove(p + start + 1, p + first, len - first); + p[l] = '\0'; + return p; +} + +static char * format_next_lwp(caddr_t handle, char *(*get_userid)(int)) { struct kinfo_proc2 *pp; @@ -946,7 +966,7 @@ format_next_lwp(caddr_t handle, char *(* format_time(cputime), 100.0 * weighted_cpu(l_, pct, pl), 100.0 * pct, - printable(pl->l_name), + countable(printable(pl->l_name), 9), get_command(hp->sel, pp)); /* return the result */
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: kamil Date: Thu May 31 10:14:21 UTC 2018 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Fix read of unitialized array elements in top(1) The cp_old array is allocated with malloc(3) and its pointer is passed to percentages64(). In this function there happens a calculation of total_change, which value depends on the value inside the unitialized cp_old[] array. ==26662==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x268a2c in percentages64 /usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:1341:6 #1 0x26748b in get_system_info /usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:478:6 #2 0x25518e in do_display /usr/src/external/bsd/top/bin/../dist/top.c:507:5 #3 0x253038 in main /usr/src/external/bsd/top/bin/../dist/top.c:975:2 #4 0x21cad1 in ___start (/usr/bin/top+0x1cad1) SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/src/external/bsd/top/bin/../dist/machine/m_netbsd.c:1341:6 in percentages64 Exiting Fix this issue by changling malloc(3) with calloc(3). Detected with Memory Sanitizer during the integration of sanitizers with the NetBSD basesystem. Reported by To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.19 src/external/bsd/top/dist/machine/m_netbsd.c:1.20 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.19 Mon Dec 26 12:46:31 2016 +++ src/external/bsd/top/dist/machine/m_netbsd.c Thu May 31 10:14:21 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.20 2018/05/31 10:14:21 kamil Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $ + * $Id: m_netbsd.c,v 1.20 2018/05/31 10:14:21 kamil Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.20 2018/05/31 10:14:21 kamil Exp $"); #endif #include @@ -335,7 +335,7 @@ machine_init(statics) ncpu = 1; cpu_states = malloc(sizeof(cpu_states[0]) * CPUSTATES * ncpu); - cp_old = malloc(sizeof(cp_old[0]) * CPUSTATES * ncpu); + cp_old = calloc(CPUSTATES * ncpu, sizeof(cp_old[0])); cp_diff = malloc(sizeof(cp_diff[0]) * CPUSTATES * ncpu); if (cpu_states == NULL || cp_time == NULL || cp_old == NULL || cp_diff == NULL) {
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: leot Date: Mon Dec 26 12:46:32 UTC 2016 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Implement the `c' command in "interactive mode" that displays only commands that match a specified string. Reviewed by and thanks to To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.18 src/external/bsd/top/dist/machine/m_netbsd.c:1.19 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.18 Sun Oct 20 03:02:27 2013 +++ src/external/bsd/top/dist/machine/m_netbsd.c Mon Dec 26 12:46:31 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.18 2013/10/20 03:02:27 christos Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.18 2013/10/20 03:02:27 christos Exp $ + * $Id: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.18 2013/10/20 03:02:27 christos Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.19 2016/12/26 12:46:31 leot Exp $"); #endif #include @@ -587,6 +587,7 @@ get_proc_info(struct system_info *si, st int show_idle; int show_system; int show_uid; + char *show_command; static struct handle handle; @@ -626,6 +627,7 @@ get_proc_info(struct system_info *si, st show_idle = sel->idle; show_system = sel->system; show_uid = sel->uid != -1; + show_command = sel->command; /* count up process states and get pointers to interesting procs */ total_procs = 0; @@ -646,9 +648,12 @@ get_proc_info(struct system_info *si, st if (pp->p_stat != LSZOMB && (show_idle || (pp->p_pctcpu != 0) || (pp->p_stat == LSRUN || pp->p_stat == LSONPROC)) && - (!show_uid || pp->p_ruid == (uid_t)sel->uid)) { -*prefp++ = pp; -active_procs++; + (!show_uid || pp->p_ruid == (uid_t)sel->uid) && + (!show_command || + strstr(get_command(sel, pp), + show_command) != NULL)) { + *prefp++ = pp; + active_procs++; } } } @@ -685,6 +690,7 @@ get_lwp_info(struct system_info *si, str int show_idle; int show_system; int show_uid; + char *show_command; static struct handle handle; @@ -736,6 +742,7 @@ get_lwp_info(struct system_info *si, str show_idle = sel->idle; show_system = sel->system; show_uid = sel->uid != -1; + show_command = sel->command; /* count up thread states and get pointers to interesting threads */ total_lwps = 0; @@ -758,9 +765,12 @@ get_lwp_info(struct system_info *si, str if (lp->l_stat != LSZOMB && (show_idle || (lp->l_pctcpu != 0) || (lp->l_stat == LSRUN || lp->l_stat == LSONPROC)) && - (!show_uid || uid_from_thread(lp) == sel->uid)) { -*lrefp++ = lp; -active_lwps++; + (!show_uid || uid_from_thread(lp) == sel->uid) && + (!show_command || + strstr(get_command(sel, proc_from_thread(lp)), + show_command) != NULL)) { + *lrefp++ = lp; + active_lwps++; } } }
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: para Date: Thu Jan 3 10:12:36 UTC 2013 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: explicitly include sys/resource.h To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.16 src/external/bsd/top/dist/machine/m_netbsd.c:1.17 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.16 Sat Oct 8 08:45:37 2011 +++ src/external/bsd/top/dist/machine/m_netbsd.c Thu Jan 3 10:12:36 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.16 2011/10/08 08:45:37 njoly Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.17 2013/01/03 10:12:36 para Exp $ */ /* * top - a top users display for Unix @@ -37,15 +37,16 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.16 2011/10/08 08:45:37 njoly Exp $ + * $Id: m_netbsd.c,v 1.17 2013/01/03 10:12:36 para Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.16 2011/10/08 08:45:37 njoly Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.17 2013/01/03 10:12:36 para Exp $"); #endif #include +#include #include #include #include
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: njoly Date: Sat Oct 8 08:45:37 UTC 2011 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Adjust UID header position, to be aligned with the datas. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.15 src/external/bsd/top/dist/machine/m_netbsd.c:1.16 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.15 Fri Apr 15 02:05:53 2011 +++ src/external/bsd/top/dist/machine/m_netbsd.c Sat Oct 8 08:45:37 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.15 2011/04/15 02:05:53 christos Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.16 2011/10/08 08:45:37 njoly Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.15 2011/04/15 02:05:53 christos Exp $ + * $Id: m_netbsd.c,v 1.16 2011/10/08 08:45:37 njoly Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.15 2011/04/15 02:05:53 christos Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.16 2011/10/08 08:45:37 njoly Exp $"); #endif #include @@ -413,7 +413,7 @@ format_process_header(struct process_sel { char *header; char *ptr; - const char *uname_field = sel->usernames ? "USERNAME" : " UID "; + const char *uname_field = sel->usernames ? "USERNAME" : "UID "; if (sel->threads) { header = Thread_header;
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: christos Date: Fri Apr 15 02:05:53 UTC 2011 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Swap the command and the thread name in the thread view and let the command be as long as it wants. (Vladimir Kirillov) To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.14 src/external/bsd/top/dist/machine/m_netbsd.c:1.15 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.14 Mon May 31 14:14:59 2010 +++ src/external/bsd/top/dist/machine/m_netbsd.c Thu Apr 14 22:05:53 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.14 2010/05/31 18:14:59 rmind Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.15 2011/04/15 02:05:53 christos Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.14 2010/05/31 18:14:59 rmind Exp $ + * $Id: m_netbsd.c,v 1.15 2011/04/15 02:05:53 christos Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.14 2010/05/31 18:14:59 rmind Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.15 2011/04/15 02:05:53 christos Exp $"); #endif #include @@ -105,14 +105,14 @@ /* 0123456 -- field to fill in starts at header+6 */ #define PROC_UNAME_START 6 #define Proc_format \ - "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.*f%% %.12s" + "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.*f%% %s" static char Thread_header[] = - " PID LID XPRI STATE TIME WCPUCPU COMMAND NAME"; + " PID LID XPRI STATE TIME WCPUCPU NAME COMMAND"; /* 0123456 -- field to fill in starts at header+6 */ #define THREAD_UNAME_START 12 #define Thread_format \ -"%5d %5d %-8.8s %3d %-8.8s%7s %5.2f%% %5.2f%% %-12.12s %.12s" +"%5d %5d %-8.8s %3d %-8.8s%7s %5.2f%% %5.2f%% %-9.9s %s" /* * Process state names for the "STATE" column of the display. @@ -939,8 +939,8 @@ format_time(cputime), 100.0 * weighted_cpu(l_, pct, pl), 100.0 * pct, - get_command(hp->sel, pp), - printable(pl->l_name)); + printable(pl->l_name), + get_command(hp->sel, pp)); /* return the result */ return(fmt);
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: rmind Date: Mon May 31 18:14:59 UTC 2010 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Fix previous, so it builds on some ports. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.13 src/external/bsd/top/dist/machine/m_netbsd.c:1.14 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.13 Mon May 31 03:18:33 2010 +++ src/external/bsd/top/dist/machine/m_netbsd.c Mon May 31 18:14:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.13 2010/05/31 03:18:33 rmind Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.14 2010/05/31 18:14:59 rmind Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.13 2010/05/31 03:18:33 rmind Exp $ + * $Id: m_netbsd.c,v 1.14 2010/05/31 18:14:59 rmind Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.13 2010/05/31 03:18:33 rmind Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.14 2010/05/31 18:14:59 rmind Exp $"); #endif #include @@ -842,8 +842,8 @@ case LSRUN: case LSSLEEP: case LSIDL: - (void)snprintf(state, sizeof(state), "%.6s/%lu", - statep, pp->p_cpuid); + (void)snprintf(state, sizeof(state), "%.6s/%u", + statep, (unsigned int)pp->p_cpuid); statep = state; break; } @@ -915,8 +915,8 @@ case LSRUN: case LSSLEEP: case LSIDL: - (void)snprintf(state, sizeof(state), "%.6s/%lu", - statep, pl->l_cpuid); + (void)snprintf(state, sizeof(state), "%.6s/%u", + statep, (unsigned int)pl->l_cpuid); statep = state; break; }
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: christos Date: Wed May 12 22:09:36 UTC 2010 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: implement fullcmd mode. Now we need to modernize the machine specific code to handle displays > 80 columns to make this work effectively. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.11 src/external/bsd/top/dist/machine/m_netbsd.c:1.12 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.11 Wed Oct 21 17:11:57 2009 +++ src/external/bsd/top/dist/machine/m_netbsd.c Wed May 12 18:09:36 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.11 2009/10/21 21:11:57 rmind Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.12 2010/05/12 22:09:36 christos Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.11 2009/10/21 21:11:57 rmind Exp $ + * $Id: m_netbsd.c,v 1.12 2010/05/12 22:09:36 christos Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.11 2009/10/21 21:11:57 rmind Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.12 2010/05/12 22:09:36 christos Exp $"); #endif #include @@ -70,14 +70,15 @@ #include "loadavg.h" #include "username.h" -static void percentages64 __P((int, int *, u_int64_t *, u_int64_t *, -u_int64_t *)); -static int get_cpunum __P((u_int64_t)); +static void percentages64(int, int *, u_int64_t *, u_int64_t *, +u_int64_t *); +static int get_cpunum(u_int64_t); /* get_process_info passes back a handle. This is what it looks like: */ struct handle { + struct process_select *sel; struct kinfo_proc2 **next_proc; /* points to next valid proc pointer */ int remaining; /* number of pointers remaining */ }; @@ -188,17 +189,17 @@ }; /* forward definitions for comparison functions */ -static int compare_cpu __P((struct proc **, struct proc **)); -static int compare_prio __P((struct proc **, struct proc **)); -static int compare_res __P((struct proc **, struct proc **)); -static int compare_size __P((struct proc **, struct proc **)); -static int compare_state __P((struct proc **, struct proc **)); -static int compare_time __P((struct proc **, struct proc **)); -static int compare_pid __P((struct proc **, struct proc **)); -static int compare_command __P((struct proc **, struct proc **)); -static int compare_username __P((struct proc **, struct proc **)); +static int compare_cpu(struct proc **, struct proc **); +static int compare_prio(struct proc **, struct proc **); +static int compare_res(struct proc **, struct proc **); +static int compare_size(struct proc **, struct proc **); +static int compare_state(struct proc **, struct proc **); +static int compare_time(struct proc **, struct proc **); +static int compare_pid(struct proc **, struct proc **); +static int compare_command(struct proc **, struct proc **); +static int compare_username(struct proc **, struct proc **); -int (*proc_compares[]) __P((struct proc **, struct proc **)) = { +int (*proc_compares[])(struct proc **, struct proc **) = { compare_cpu, compare_prio, compare_res, @@ -248,6 +249,57 @@ #define pagetok(size) ((size) << pageshift) +/* + * Print swapped processes as and + * system processes as [pname] + */ +static const char * +get_pretty(const struct kinfo_proc2 *pp) +{ + if ((pp->p_flag & P_SYSTEM) != 0) + return "[]"; + if ((pp->p_flag & P_INMEM) == 0) + return "<>"; + return ""; +} + +static const char * +get_command(const struct process_select *sel, struct kinfo_proc2 *pp) +{ + static char cmdbuf[128]; + const char *pretty; + char **argv; + if (pp == NULL) + return ""; + pretty = get_pretty(pp); + + if (sel->fullcmd == 0 || kd == NULL || (argv = kvm_getargv2(kd, pp, + sizeof(cmdbuf))) == NULL) { + if (pretty[0] != '\0' && pp->p_comm[0] != pretty[0]) + snprintf(cmdbuf, sizeof(cmdbuf), "%c%s%c", pretty[0], + printable(pp->p_comm), pretty[1]); + else + strlcpy(cmdbuf, printable(pp->p_comm), sizeof(cmdbuf)); + } else { + char *d = cmdbuf; + if (pretty[0] != '\0' && argv[0][0] != pretty[0]) + *d++ = pretty[0]; + while (*argv) { + const char *s = printable(*argv++); + while (d < cmdbuf + sizeof(cmdbuf) - 2 && + (*d++ = *s++) != '\0') +continue; + if (d > cmdbuf && d < cmdbuf + sizeof(cmdbuf) - 2 && + d[-1] == '\0') +d[-1] = ' '; + } + if (pretty[0] != '\0' && pretty[0] == cmdbuf[0]) + *d++ = pretty[1]; + *d++ = '\0'; + } + return cmdbuf; +} + static int get_cpunum(id) u_int64_t id; @@ -364,6 +416,7 @@ statics->swap_names = swapnames; statics->order_names = ordernames; statics->flags.threads = 1; + statics->flags.fullcmds = 1; mib[0] = CTL_KERN; mib[1] = KERN_BOOTTIME; @@ -637,6 +690,7 @@ /*
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: njoly Date: Mon Jul 27 16:26:48 UTC 2009 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Make process CPU value drop the decimal part when reaching 100%, like WCPU. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.9 src/external/bsd/top/dist/machine/m_netbsd.c:1.10 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.9 Tue May 5 18:51:22 2009 +++ src/external/bsd/top/dist/machine/m_netbsd.c Mon Jul 27 16:26:48 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.9 2009/05/05 18:51:22 christos Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.10 2009/07/27 16:26:48 njoly Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.9 2009/05/05 18:51:22 christos Exp $ + * $Id: m_netbsd.c,v 1.10 2009/07/27 16:26:48 njoly Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.9 2009/05/05 18:51:22 christos Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.10 2009/07/27 16:26:48 njoly Exp $"); #endif #include @@ -106,7 +106,7 @@ /* 0123456 -- field to fill in starts at header+6 */ #define PROC_UNAME_START 6 #define Proc_format \ - "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.2f%% %.12s" + "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.*f%% %.12s" static char Thread_header[] = " PID LID XPRI STATE TIME WCPUCPU COMMAND NAME"; @@ -770,7 +770,7 @@ { struct kinfo_proc2 *pp; long cputime; - double pct, wcpu; + double pct, wcpu, cpu; struct handle *hp; const char *statep; #ifdef KI_NOCPU @@ -839,6 +839,7 @@ } #endif wcpu = 100.0 * weighted_cpu(p_, pct, pp); + cpu = 100.0 * pct; /* format this entry */ sprintf(fmt, @@ -852,7 +853,7 @@ statep, format_time(cputime), (wcpu >= 100.0) ? 0 : 2, wcpu, - 100.0 * pct, + (cpu >= 100.0) ? 0 : 2, cpu, printable(pp->p_comm)); /* return the result */
CVS commit: src/external/bsd/top/dist/machine
Module Name:src Committed By: njoly Date: Fri Apr 24 19:07:46 UTC 2009 Modified Files: src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Drop the process WCPU decimal part when it reaches 100.0% (threaded application on SMP system), to make it stay in the 5 expected columns. ok by christos. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.7 src/external/bsd/top/dist/machine/m_netbsd.c:1.8 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.7 Sun Mar 29 01:02:49 2009 +++ src/external/bsd/top/dist/machine/m_netbsd.c Fri Apr 24 19:07:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.7 2009/03/29 01:02:49 mrg Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.8 2009/04/24 19:07:45 njoly Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran * * - * $Id: m_netbsd.c,v 1.7 2009/03/29 01:02:49 mrg Exp $ + * $Id: m_netbsd.c,v 1.8 2009/04/24 19:07:45 njoly Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.7 2009/03/29 01:02:49 mrg Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.8 2009/04/24 19:07:45 njoly Exp $"); #endif #include @@ -106,7 +106,7 @@ /* 0123456 -- field to fill in starts at header+6 */ #define PROC_UNAME_START 6 #define Proc_format \ - "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.2f%% %5.2f%% %.12s" + "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.*f%% %5.2f%% %.12s" static char Thread_header[] = " PID LID XPRI STATE TIME WCPUCPU COMMAND NAME"; @@ -771,7 +771,7 @@ { struct kinfo_proc2 *pp; long cputime; - double pct; + double pct, wcpu; struct handle *hp; const char *statep; #ifdef KI_NOCPU @@ -839,6 +839,8 @@ } } #endif + wcpu = 100.0 * weighted_cpu(p_, pct, pp); + /* format this entry */ sprintf(fmt, Proc_format, @@ -850,7 +852,7 @@ format_k(pagetok(pp->p_vm_rssize)), statep, format_time(cputime), - 100.0 * weighted_cpu(p_, pct, pp), + (wcpu >= 100.0) ? 0 : 2, wcpu, 100.0 * pct, printable(pp->p_comm));