From 6d1b4a754811e740d47cb62d1ed61a73b1d8c5bb Mon Sep 17 00:00:00 2001 From: Antonio Nikishaev Date: Thu, 27 Nov 2014 20:21:30 +0400 Subject: [PATCH] top(1): ability to display individual threads And put square brackets around system processes. --- usr.bin/top/m_dragonfly.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/usr.bin/top/m_dragonfly.c b/usr.bin/top/m_dragonfly.c index 0d24db8..6ad315e 100644 --- a/usr.bin/top/m_dragonfly.c +++ b/usr.bin/top/m_dragonfly.c @@ -286,6 +286,7 @@ machine_init(struct statics *statics) statics->order_names = ordernames; /* we need kvm descriptor in order to show full commands */ statics->flags.fullcmds = kd != NULL; + statics->flags.threads = 1; /* all done! */ return (0); @@ -535,8 +536,6 @@ format_next_process(caddr_t xhandle, char *(*get_userid) (int)) char status[16]; int state; int xnice; - int prefer_fullcmd; - char **comm_full; char *comm; char cputime_fmt[10], ccputime_fmt[10]; @@ -546,16 +545,29 @@ format_next_process(caddr_t xhandle, char *(*get_userid) (int)) hp->remaining--; /* get the process's command name */ - prefer_fullcmd = show_fullcmd; if (show_fullcmd) { - if ((comm_full = kvm_getargv(kd, pp, 0)) == NULL) { - prefer_fullcmd = 0; + char **comm_full = kvm_getargv(kd, pp, 0); + if (comm_full != 0) + comm = *comm_full; + else comm = PP(pp, comm); - } } else { comm = PP(pp, comm); } + + /* the actual field to display */ + char cmdfield[MAX_COLS]; + + if (PP(pp, flags) & P_SYSTEM) { + /* system process */ + snprintf(cmdfield, sizeof cmdfield, "[%s]", comm); + } else if (LP(pp, tid) > 0) { + /* display it as a thread */ + snprintf(cmdfield, sizeof cmdfield, "%s{%d}", comm, LP(pp, tid)); + } else { + snprintf(cmdfield, sizeof cmdfield, "%s", comm); + } /* * Convert the process's runtime from microseconds to seconds. This @@ -631,7 +643,7 @@ format_next_process(caddr_t xhandle, char *(*get_userid) (int)) ccputime_fmt, 100.0 * pct, cmdlength, - prefer_fullcmd ? *comm_full : comm); + cmdfield); /* return the result */ return (fmt); -- 1.9.3 (Apple Git-50)