From owner-freebsd-current@FreeBSD.ORG Fri May 27 14:46:31 2011 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA14C1065672 for ; Fri, 27 May 2011 14:46:31 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id B1AFC8FC20 for ; Fri, 27 May 2011 14:46:31 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 6759A46B1A for ; Fri, 27 May 2011 10:46:31 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 050E78A050 for ; Fri, 27 May 2011 10:46:31 -0400 (EDT) From: John Baldwin To: current@freebsd.org Date: Fri, 27 May 2011 10:46:30 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110325; KDE/4.5.5; amd64; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201105271046.30379.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Fri, 27 May 2011 10:46:31 -0400 (EDT) Cc: Subject: [PATCH] Toggle display of the kernel idle process (per-CPU idle threads) in top X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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: Fri, 27 May 2011 14:46:31 -0000 Some times in top, I don't want to see all the per-CPU idle threads but instead focus on the non-idle threads that are running. Especially on a system with a lot of CPUs, the idle threads can push all the interesting threads off of the list. This patch adds a new 'z' flag (gratuitously chosen letter) and interactive command to toggle the display of the system idle process. Patch is tested against 8, but should work fine on HEAD too: Index: contrib/top/commands.c =================================================================== --- contrib/top/commands.c (revision 221924) +++ contrib/top/commands.c (working copy) @@ -94,6 +94,7 @@ a - toggle the displaying of process titles\n\ t - toggle the display of this process\n\ u - display processes for only one user (+ selects all users)\n\ +z - toggle the displaying of system idle process\n\ \n\ \n", stdout); } Index: contrib/top/top.c =================================================================== --- contrib/top/top.c (revision 221924) +++ contrib/top/top.c (working copy) @@ -196,9 +196,9 @@ fd_set readfds; #ifdef ORDER - static char command_chars[] = "\f qh?en#sdkriIutHmSCajo"; + static char command_chars[] = "\f qh?en#sdkriIutHmSCajzo"; #else - static char command_chars[] = "\f qh?en#sdkriIutHmSCaj"; + static char command_chars[] = "\f qh?en#sdkriIutHmSCajz"; #endif /* these defines enumerate the "strchr"s of the commands in command_chars */ #define CMD_redraw 0 @@ -224,8 +224,9 @@ #define CMD_wcputog 19 #define CMD_showargs 20 #define CMD_jidtog 21 +#define CMD_kidletog 22 #ifdef ORDER -#define CMD_order 22 +#define CMD_order 23 #endif /* set the buffer for stdout */ @@ -258,6 +259,7 @@ ps.thread = No; ps.wcpu = 1; ps.jail = No; + ps.kidle = Yes; ps.command = NULL; /* get preset options from the environment */ @@ -283,7 +285,7 @@ optind = 1; } - while ((i = getopt(ac, av, "CSIHPabijnquvs:d:U:m:o:t")) != EOF) + while ((i = getopt(ac, av, "CSIHPabijnquvzs:d:U:m:o:t")) != EOF) { switch(i) { @@ -412,10 +414,14 @@ pcpu_stats = Yes; break; + case 'z': + ps.kidle = !ps.kidle; + break; + default: fprintf(stderr, "Top version %s\n" -"Usage: %s [-abCHIijnPqStuv] [-d count] [-m io | cpu] [-o field] [-s time]\n" +"Usage: %s [-abCHIijnPqStuvz] [-d count] [-m io | cpu] [-o field] [-s time]\n" " [-U username] [number]\n", version_string(), myname); exit(1); @@ -1075,7 +1081,13 @@ reset_display(); putchar('\r'); break; - + case CMD_kidletog: + ps.kidle = !ps.kidle; + new_message(MT_standout | MT_delayed, + " %sisplaying kernel idle process.", + ps.idle ? "D" : "Not d"); + putchar('\r'); + break; default: new_message(MT_standout, " BAD CASE IN SWITCH!"); putchar('\r'); Index: contrib/top/machine.h =================================================================== --- contrib/top/machine.h (revision 221924) +++ contrib/top/machine.h (working copy) @@ -65,6 +65,7 @@ int uid; /* only this uid (unless uid == -1) */ int wcpu; /* show weighted cpu */ int jail; /* show jail ID */ + int kidle; /* show per-CPU idle threads */ char *command; /* only this command (unless == NULL) */ }; Index: contrib/top/top.X =================================================================== --- contrib/top/top.X (revision 221924) +++ contrib/top/top.X (working copy) @@ -10,7 +10,7 @@ .SH SYNOPSIS .B top [ -.B \-abCHIijnPqStuv +.B \-abCHIijnPqStuvz ] [ .BI \-d count ] [ @@ -142,6 +142,9 @@ No other processing takes place when this option is used. To see current revision information while top is running, use the help command \*(lq?\*(rq. .TP +.B \-z +Do not display the system idle process. +.TP .BI \-d count Show only .I count @@ -303,6 +306,9 @@ Toggle the display of the .I top process. +.TP +.B z +Toggle the display of the system idle process. .SH "THE DISPLAY" The actual display varies depending on the specific variant of Unix that the machine is running. This description may not exactly match Index: usr.bin/top/machine.c =================================================================== --- usr.bin/top/machine.c (revision 221924) +++ usr.bin/top/machine.c (working copy) @@ -623,6 +623,7 @@ int show_system; int show_uid; int show_command; + int show_kidle; /* * Save the previous process info. @@ -663,6 +664,7 @@ show_system = sel->system; show_uid = sel->uid != -1; show_command = sel->command != NULL; + show_kidle = sel->kidle; /* count up process states and get pointers to interesting procs */ total_procs = 0; @@ -704,6 +706,11 @@ /* skip idle or non-running processes */ continue; + if (displaymode == DISP_CPU && !show_kidle && + pp->ki_tdflags & TDF_IDLETD) + /* skip kernel idle process */ + continue; + if (displaymode == DISP_IO && !show_idle && p_io == 0) /* skip processes that aren't doing I/O */ continue; -- John Baldwin