thread diff for top

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

thread diff for top

Ted Unangst-2
enable toggling of viewing threads with T, similar to system processes and
S.

Index: commands.c
===================================================================
RCS file: /cvs/src/usr.bin/top/commands.c,v
retrieving revision 1.18
diff -u -r1.18 commands.c
--- commands.c 2005/10/07 17:46:13 1.18
+++ commands.c 2005/12/04 21:22:28
@@ -100,6 +100,7 @@
     "s       - change number of seconds to delay between updates\n"
     "S       - toggle the display of system processes\n"
     "u       - display processes for only one user (+ selects all users)\n"
+    "T       - toggle the display of threads\n"
     "C       - toggle the display of the command line arguments\n"
     "\n\n", stdout);
  }
Index: machine.c
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.49
diff -u -r1.49 machine.c
--- machine.c 2005/06/17 09:40:48 1.49
+++ machine.c 2005/12/04 21:22:29
@@ -342,7 +342,7 @@
 get_process_info(struct system_info *si, struct process_select *sel,
     int (*compare) (const void *, const void *))
 {
- int show_idle, show_system, show_uid, show_pid;
+ int show_idle, show_system, show_threads, show_uid, show_pid;
  int total_procs, active_procs;
  struct kinfo_proc2 **prefp, *pp;
 
@@ -363,6 +363,7 @@
  /* set up flags which define what we are going to select */
  show_idle = sel->idle;
  show_system = sel->system;
+ show_threads = sel->threads;
  show_uid = sel->uid != (uid_t)-1;
  show_pid = sel->pid != (pid_t)-1;
 
@@ -379,7 +380,8 @@
  *  processes---these get ignored unless show_sysprocs is set.
  */
  if (pp->p_stat != 0 &&
-    (show_system || (pp->p_flag & P_SYSTEM) == 0)) {
+    (show_system || (pp->p_flag & P_SYSTEM) == 0) &&
+    (show_threads || (pp->p_flag & P_THREAD) == 0)) {
  total_procs++;
  process_states[(unsigned char) pp->p_stat]++;
  if (pp->p_stat != SZOMB &&
Index: machine.h
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.13
diff -u -r1.13 machine.h
--- machine.h 2005/06/08 22:36:43 1.13
+++ machine.h 2005/12/04 21:22:29
@@ -72,6 +72,7 @@
 struct process_select {
  int             idle; /* show idle processes */
  int             system; /* show system processes */
+ int             threads; /* show threads */
  uid_t           uid; /* only this uid (unless uid == -1) */
  pid_t           pid; /* only this pid (unless pid == -1) */
  char           *command;/* only this command (unless == NULL) */
Index: top.1
===================================================================
RCS file: /cvs/src/usr.bin/top/top.1,v
retrieving revision 1.31
diff -u -r1.31 top.1
--- top.1 2005/09/06 23:30:33 1.31
+++ top.1 2005/12/04 21:22:29
@@ -152,6 +152,10 @@
 seconds.
 The value may be fractional, to permit delays of less than 1 second.
 The default delay between updates is 5 seconds.
+.It Fl S
+Show process threads in the display.
+Normally, only the main process is shown.
+This option makes all threads visible.
 .It Fl U Ar username
 Show only those processes owned by
 .Ar username .
Index: top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.40
diff -u -r1.40 top.c
--- top.c 2005/06/17 09:40:48 1.40
+++ top.c 2005/12/04 21:22:29
@@ -97,6 +97,7 @@
 int topn = Default_TOPN;
 int no_command = Yes;
 int old_system = No;
+int old_threads = No;
 int show_args = No;
 
 #if Default_TOPN == Infinity
@@ -127,6 +128,7 @@
 #define CMD_order 16
 #define CMD_pid 17
 #define CMD_command 18
+#define CMD_threads 19
 
 static void
 usage(void)
@@ -176,6 +178,11 @@
  old_system = Yes;
  break;
 
+ case 'T': /* show threads */
+ ps.threads = Yes;
+ old_threads = Yes;
+ break;
+
  case 'I': /* show idle processes */
  ps.idle = !ps.idle;
  break;
@@ -514,7 +521,7 @@
  int change, i;
  struct pollfd pfd[1];
  uid_t uid;
- static char command_chars[] = "\f qh?en#sdkriIuSopC";
+ static char command_chars[] = "\f qh?en#sdkriIuSopCT";
 
  /*
  * assume valid command unless told
@@ -852,6 +859,14 @@
 
  case CMD_command:
  show_args = (show_args == No) ? Yes : No;
+ break;
+
+ case CMD_threads:
+ ps.threads = !ps.threads;
+ old_threads = ps.threads;
+ new_message(MT_standout | MT_delayed,
+    " %sisplaying threads.",
+    ps.threads ? "D" : "Not d");
  break;
 
  default:

--
die energie aus fleisch und blut        deine sprache und die ganze wut
deine gefuehle die du lebst             und dein herz fuehl wie es bebt
zeitbombe! sie tickt in dir    zeitbombe! sie explodiert in deinem kopf
                                                    - girls under glass

Reply | Threaded
Open this post in threaded view
|

Re: thread diff for top

Thorsten Glaser
Ted Unangst dixit:

>--- top.1 2005/09/06 23:30:33 1.31
>+++ top.1 2005/12/04 21:22:29
>@@ -152,6 +152,10 @@
> seconds.
> The value may be fractional, to permit delays of less than 1 second.
> The default delay between updates is 5 seconds.
>+.It Fl S

make this a T

>@@ -514,7 +521,7 @@
> int change, i;
> struct pollfd pfd[1];
> uid_t uid;
>- static char command_chars[] = "\f qh?en#sdkriIuSopC";
>+ static char command_chars[] = "\f qh?en#sdkriIuSopCT";

What about "sort options while here"? ;)

Btw, nice sig, and nice work.

bye,
//mirabile
--
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
        -- idea by Michael Holstein CISSP GCIA, Cleveland State University
03.12.05 19:19 welche krawatte...?
        -- bsiegert@ in IRC, much to my surprise (actually, heavy shock)