From owner-freebsd-bugs@FreeBSD.ORG Wed Oct 7 10:00:15 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9D7AA10656A4 for ; Wed, 7 Oct 2009 10:00:15 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 5FE078FC1A for ; Wed, 7 Oct 2009 10:00:15 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n97A0FYJ095504 for ; Wed, 7 Oct 2009 10:00:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n97A0FZ9095499; Wed, 7 Oct 2009 10:00:15 GMT (envelope-from gnats) Resent-Date: Wed, 7 Oct 2009 10:00:15 GMT Resent-Message-Id: <200910071000.n97A0FZ9095499@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Andrew Brampton Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2F3DE106566B for ; Wed, 7 Oct 2009 09:59:22 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 042648FC0C for ; Wed, 7 Oct 2009 09:59:22 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n979xLXE002958 for ; Wed, 7 Oct 2009 09:59:21 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n979xLJc002957; Wed, 7 Oct 2009 09:59:21 GMT (envelope-from nobody) Message-Id: <200910070959.n979xLJc002957@www.freebsd.org> Date: Wed, 7 Oct 2009 09:59:21 GMT From: Andrew Brampton To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/139389: [patch] Change top(1) to display thread IDs X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Oct 2009 10:00:15 -0000 >Number: 139389 >Category: bin >Synopsis: [patch] Change top(1) to display thread IDs >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Oct 07 10:00:15 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Andrew Brampton >Release: FreeBSD 8.0-RC1 >Organization: >Environment: FreeBSD machine 8.0-RC1 FreeBSD 8.0-RC1 #25 r197611M: Tue Sep 29 12:21:18 BST 2009 root@machine:/usr/obj/usr/src/sys/CUSTOM amd64 >Description: The program top(1) does not display thread IDs when listing threads (in "-H" mode). Displaying the thread ID can be very useful when using the tool cpuset, as this takes a thread ID as an argument. The attached patch adds a new column after PID which displays the Thread ID. >How-To-Repeat: >Fix: Patch attached with submission follows: Index: usr.bin/top/machine.c =================================================================== --- usr.bin/top/machine.c (revision 197611) +++ usr.bin/top/machine.c (working copy) @@ -108,18 +108,18 @@ static char smp_header_thr[] = " PID%s %-*.*s THR PRI NICE SIZE RES STATE C TIME %6s COMMAND"; static char smp_header[] = - " PID%s %-*.*s " "PRI NICE SIZE RES STATE C TIME %6s COMMAND"; + " PID TID%s %-*.*s PRI NICE SIZE RES STATE C TIME %6s COMMAND"; #define smp_Proc_format \ - "%5d%s %-*.*s %s%3d %4s%7s %6s %-6.6s %2d%7s %5.2f%% %.*s" + "%5d%s%s %-*.*s %s%3d %4s%7s %6s %-6.6s %2d%7s %5.2f%% %.*s" static char up_header_thr[] = " PID%s %-*.*s THR PRI NICE SIZE RES STATE TIME %6s COMMAND"; static char up_header[] = - " PID%s %-*.*s " "PRI NICE SIZE RES STATE TIME %6s COMMAND"; + " PID TID%s %-*.*s PRI NICE SIZE RES STATE TIME %6s COMMAND"; #define up_Proc_format \ - "%5d%s %-*.*s %s%3d %4s%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s" + "%5d%s%s %-*.*s %s%3d %4s%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s" /* process state names for the "STATE" column of the display */ @@ -757,7 +757,7 @@ int state; struct rusage ru, *rup; long p_tot, s_tot; - char *proc_fmt, thr_buf[6], jid_buf[6]; + char *proc_fmt, tid_buf[8], thr_buf[6], jid_buf[6]; char *cmdbuf = NULL; char **args; @@ -942,14 +942,19 @@ /* format this entry */ proc_fmt = smpmode ? smp_Proc_format : up_Proc_format; - if (ps.thread != 0) + if (ps.thread) { thr_buf[0] = '\0'; - else + snprintf(tid_buf, sizeof(tid_buf), "%*d", + sizeof(tid_buf) - 1, pp->ki_tid); + } else { + tid_buf[0] = '\0'; snprintf(thr_buf, sizeof(thr_buf), "%*d ", sizeof(thr_buf) - 2, pp->ki_numthreads); + } sprintf(fmt, proc_fmt, pp->ki_pid, + tid_buf, jid_buf, namelength, namelength, (*get_userid)(pp->ki_ruid), thr_buf, >Release-Note: >Audit-Trail: >Unformatted: