From owner-freebsd-current@FreeBSD.ORG Thu Jan 17 21:47:48 2013 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id ED22C1CA; Thu, 17 Jan 2013 21:47:48 +0000 (UTC) (envelope-from eric@vangyzen.net) Received: from aussmtpmrkps320.us.dell.com (aussmtpmrkps320.us.dell.com [143.166.224.254]) by mx1.freebsd.org (Postfix) with ESMTP id B88BA2B6; Thu, 17 Jan 2013 21:47:48 +0000 (UTC) X-Loopcount0: from 64.238.244.148 X-IronPort-AV: E=Sophos;i="4.84,488,1355119200"; d="scan'208";a="16017360" Message-ID: <50F8713F.1030200@vangyzen.net> Date: Thu, 17 Jan 2013 15:46:39 -0600 From: Eric van Gyzen User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:14.0) Gecko/20120822 Thunderbird/14.0 MIME-Version: 1.0 To: John Baldwin Subject: Re: [PATCH] Adjust 'ps H' to include kthread names by default References: <201301171622.09624.jhb@freebsd.org> In-Reply-To: <201301171622.09624.jhb@freebsd.org> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Cc: current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2013 21:47:49 -0000 On 01/17/2013 15:22, John Baldwin wrote: > Running 'ps axH' on a current system results in a lot of kthreads with not > very useful names (unless you add -c): > > PID TT STAT TIME COMMAND > 0 ?? DLs 1:09.52 [kernel] > 0 ?? DLs 0:00.00 [kernel] > 0 ?? DLs 0:00.00 [kernel] > 0 ?? DLs 0:00.00 [kernel] > 0 ?? DLs 0:00.00 [kernel] > 0 ?? DLs 0:00.00 [kernel] > 0 ?? DLs 0:00.00 [kernel] > 0 ?? DLs 0:03.82 [kernel] > 0 ?? DLs 1:15.14 [kernel] > 0 ?? DLs 0:00.00 [kernel] > 0 ?? DLs 39:24.55 [kernel] > 0 ?? DLs 0:00.04 [kernel] > > This patch changes this to: > > PID TT STAT TIME COMMAND > 0 ?? DLs 1:09.53 [kernel/swapper] > 0 ?? DLs 0:00.00 [kernel/firmware tas] > 0 ?? DLs 0:00.00 [kernel/ffs_trim tas] > 0 ?? DLs 0:00.00 [kernel/acpi_task_0] > 0 ?? DLs 0:00.00 [kernel/acpi_task_1] > 0 ?? DLs 0:00.00 [kernel/acpi_task_2] > 0 ?? DLs 0:00.00 [kernel/aiod_bio tas] > 0 ?? DLs 0:03.82 [kernel/thread taskq] > 0 ?? DLs 1:15.19 [kernel/nvidia taskq] > 0 ?? DLs 0:00.00 [kernel/kqueue taskq] > 0 ?? DLs 39:26.82 [kernel/em0 taskq] > 0 ?? DLs 0:00.04 [kernel/mca taskq] > > In theory this will affect any process for which an argv can't be fetched, but > in practice it mostly helps with kthreads. Yes, please, and thank you. The patch looks fine to me. > Index: ps.c > =================================================================== > --- ps.c (revision 245225) > +++ ps.c (working copy) > @@ -141,7 +141,7 @@ > static void *expand_list(struct listinfo *); > static const char * > fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int), > - KINFO *, char *, int); > + KINFO *, char *, char *, int); > static void free_list(struct listinfo *); > static void init_list(struct listinfo *, addelem_rtn, int, const char *); > static char *kludge_oldps_options(const char *, char *, const char *); > @@ -1163,11 +1163,12 @@ > > static const char * > fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki, > - char *comm, int maxlen) > + char *comm, char *thread, int maxlen) > { > const char *s; > > - s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen); > + s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, > + ki->ki_p->ki_numthreads > 1 ? thread : NULL, maxlen); > return (s); > } > > @@ -1195,7 +1196,7 @@ > ki->ki_args = strdup(""); > else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) > ki->ki_args = strdup(fmt(kvm_getargv, ki, > - ki->ki_p->ki_comm, MAXCOMLEN)); > + ki->ki_p->ki_comm, ki->ki_p->ki_tdname, MAXCOMLEN)); > else > asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm); > if (ki->ki_args == NULL) > @@ -1206,7 +1207,7 @@ > if (needenv) { > if (UREADOK(ki)) > ki->ki_env = strdup(fmt(kvm_getenvv, ki, > - (char *)NULL, 0)); > + (char *)NULL, (char *)NULL, 0)); > else > ki->ki_env = strdup("()"); > if (ki->ki_env == NULL) > Index: fmt.c > =================================================================== > --- fmt.c (revision 245225) > +++ fmt.c (working copy) > @@ -105,7 +105,7 @@ > } > > const char * > -fmt_argv(char **argv, char *cmd, size_t maxlen) > +fmt_argv(char **argv, char *cmd, char *thread, size_t maxlen) > { > size_t len; > char *ap, *cp; > @@ -122,9 +122,14 @@ > cp = malloc(len); > if (cp == NULL) > errx(1, "malloc failed"); > - if (ap == NULL) > - sprintf(cp, "[%.*s]", (int)maxlen, cmd); > - else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) > + if (ap == NULL) { > + if (showthreads && thread != NULL) { > + asprintf(&ap, "%s/%s", cmd, thread); > + sprintf(cp, "[%.*s]", (int)maxlen, ap); > + free(ap); > + } else > + sprintf(cp, "[%.*s]", (int)maxlen, cmd); > + } else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) > sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd); > else > strcpy(cp, ap); > Index: extern.h > =================================================================== > --- extern.h (revision 245225) > +++ extern.h (working copy) > @@ -51,7 +51,7 @@ > char *elapseds(KINFO *, VARENT *); > char *emulname(KINFO *, VARENT *); > VARENT *find_varentry(VAR *); > -const char *fmt_argv(char **, char *, size_t); > +const char *fmt_argv(char **, char *, char *, size_t); > double getpcpu(const KINFO *); > char *kvar(KINFO *, VARENT *); > char *label(KINFO *, VARENT *); > >