top(1): ability to display individual threads
authorAntonio Nikishaev <me@lelf.lu>
Thu, 27 Nov 2014 16:21:30 +0000 (20:21 +0400)
committerJohn Marino <draco@marino.st>
Sun, 30 Nov 2014 17:55:41 +0000 (18:55 +0100)
And put square brackets around system processes.

usr.bin/top/m_dragonfly.c

index 0d24db8..6ad315e 100644 (file)
@@ -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);