Diff for /src/usr.bin/top/machine.c between versions 1.10 and 1.11

version 1.10, 2003/11/21 22:46:14 version 1.11, 2004/05/29 05:11:15
Line 18 Line 18
  * AUTHOR:  Christos Zoulas <christos@ee.cornell.edu>   * AUTHOR:  Christos Zoulas <christos@ee.cornell.edu>
  *          Steven Wallace  <swallace@freebsd.org>   *          Steven Wallace  <swallace@freebsd.org>
  *          Wolfram Schneider <wosch@FreeBSD.org>   *          Wolfram Schneider <wosch@FreeBSD.org>
    *          Hiten Pandya <hmp@backplane.com>
  *   *
  * $FreeBSD: src/usr.bin/top/machine.c,v 1.29.2.2 2001/07/31 20:27:05 tmm Exp $   * $FreeBSD: src/usr.bin/top/machine.c,v 1.29.2.2 2001/07/31 20:27:05 tmm Exp $
  * $DragonFly$   * $DragonFly$
Line 62  static int smpmode; Line 63  static int smpmode;
 static int namelength;  static int namelength;
 static int cmdlength;  static int cmdlength;
   
   /* 
    * needs to be a global symbol, so wrapper can be
    * modified accordingly.
    */
   static int show_threads = 0;
   
 /* get_process_info passes back a handle.  This is what it looks like: */  /* get_process_info passes back a handle.  This is what it looks like: */
   
Line 212  long percentages(); Line 218  long percentages();
 #ifdef ORDER  #ifdef ORDER
 /* sorting orders. first is default */  /* sorting orders. first is default */
 char *ordernames[] = {  char *ordernames[] = {
    "cpu", "size", "res", "time", "pri", NULL    "cpu", "size", "res", "time", "pri", "thr", NULL
 };  };
 #endif  #endif
   
Line 308  char *format_header(register char *uname Line 314  char *format_header(register char *uname
     snprintf(Header, sizeof(Header), smpmode ? smp_header : up_header,      snprintf(Header, sizeof(Header), smpmode ? smp_header : up_header,
              namelength, namelength, uname_field);               namelength, namelength, uname_field);
   
    cmdlength = 80 - strlen(Header) + 6;    if (screen_width <= 79)
         cmdlength = 80;
     else
         cmdlength = 89;
 
     cmdlength = cmdlength - strlen(Header) + 6;
   
     return Header;      return Header;
 }  }
Line 479  caddr_t get_process_info(struct system_i Line 490  caddr_t get_process_info(struct system_i
     show_idle = sel->idle;      show_idle = sel->idle;
     show_self = sel->self;      show_self = sel->self;
     show_system = sel->system;      show_system = sel->system;
       show_threads = sel->threads;
     show_uid = sel->uid != -1;      show_uid = sel->uid != -1;
     show_command = sel->command != NULL;      show_command = sel->command != NULL;
   
Line 495  caddr_t get_process_info(struct system_i Line 507  caddr_t get_process_info(struct system_i
          *  status field.  Processes with P_SYSTEM set are system           *  status field.  Processes with P_SYSTEM set are system
          *  processes---these get ignored unless show_sysprocs is set.           *  processes---these get ignored unless show_sysprocs is set.
          */           */
        if (PP(pp, p_stat) != 0 &&        if ((show_threads && (TP(pp, td_proc) == NULL)) ||
             PP(pp, p_stat) != 0 &&
             (show_self != PP(pp, p_pid)) &&              (show_self != PP(pp, p_pid)) &&
             (show_system || ((PP(pp, p_flag) & P_SYSTEM) == 0)))              (show_system || ((PP(pp, p_flag) & P_SYSTEM) == 0)))
         {          {
             total_procs++;              total_procs++;
             process_states[(unsigned char) PP(pp, p_stat)]++;              process_states[(unsigned char) PP(pp, p_stat)]++;
            if ((PP(pp, p_stat) != SZOMB) &&            if ((show_threads && (TP(pp, td_proc) == NULL)) ||
                (show_idle || (PP(pp, p_pctcpu) != 0) ||                 (PP(pp, p_stat) != SZOMB) &&
                 (show_idle || (PP(pp, p_pctcpu) != 0) ||
                  (PP(pp, p_stat) == SRUN)) &&                   (PP(pp, p_stat) == SRUN)) &&
                 (!show_uid || EP(pp, e_ucred.cr_ruid) == (uid_t)sel->uid))                  (!show_uid || EP(pp, e_ucred.cr_ruid) == (uid_t)sel->uid))
             {              {
Line 537  char *format_next_process(caddr_t handle Line 551  char *format_next_process(caddr_t handle
     double pct;      double pct;
     struct handle *hp;      struct handle *hp;
     char status[16];      char status[16];
       char const *wrapper;
     int state;      int state;
     int nice;      int nice;
   
Line 545  char *format_next_process(caddr_t handle Line 560  char *format_next_process(caddr_t handle
     pp = *(hp->next_proc++);      pp = *(hp->next_proc++);
     hp->remaining--;      hp->remaining--;
           
       /* set the wrapper for the process/thread name */
       if ((PP(pp, p_flag) & P_INMEM) == 0)
            wrapper = "[]"; /* swapped process [pname] */
       else if (((PP(pp, p_flag) & P_SYSTEM) != 0) && (TP(pp, td_proc) != NULL))
            wrapper = "()"; /* system process (pname) */
       else if (show_threads && (TP(pp, td_proc) == NULL))
            wrapper = "<>"; /* pure kernel threads <thread> */
       else
            wrapper = NULL;
     
     /* get the process's command name */      /* get the process's command name */
    if ((PP(pp, p_flag) & P_INMEM) == 0) {    if (wrapper != NULL) {
        /* 
         * Print swapped processes as <pname> 
         */ 
         char *comm = TP(pp, td_comm);          char *comm = TP(pp, td_comm);
 #define COMSIZ sizeof(TP(pp, td_comm))  #define COMSIZ sizeof(TP(pp, td_comm))
         char buf[COMSIZ];          char buf[COMSIZ];
         (void) strncpy(buf, comm, COMSIZ);          (void) strncpy(buf, comm, COMSIZ);
        comm[0] = '<';        comm[0] = wrapper[0];
         (void) strncpy(&comm[1], buf, COMSIZ - 2);          (void) strncpy(&comm[1], buf, COMSIZ - 2);
         comm[COMSIZ - 2] = '\0';          comm[COMSIZ - 2] = '\0';
        (void) strncat(comm, ">", COMSIZ - 1);        (void) strncat(comm, &wrapper[1], COMSIZ - 1);
         comm[COMSIZ - 1] = '\0';          comm[COMSIZ - 1] = '\0';
     }      }
   
Line 618  char *format_next_process(caddr_t handle Line 640  char *format_next_process(caddr_t handle
   
   
     /* format this entry */      /* format this entry */
    sprintf(fmt,    snprintf(fmt, sizeof(fmt),
             smpmode ? smp_Proc_format : up_Proc_format,              smpmode ? smp_Proc_format : up_Proc_format,
             PP(pp, p_pid),              PP(pp, p_pid),
             namelength, namelength,              namelength, namelength,
             (*get_userid)(EP(pp, e_ucred.cr_ruid)),              (*get_userid)(EP(pp, e_ucred.cr_ruid)),
            PP(pp, p_priority),            (show_threads && (TP(pp, td_proc) == NULL)) ? TP(pp, td_pri) :
                 PP(pp, p_priority),
             nice,              nice,
             format_k2(PROCSIZE(pp)),              format_k2(PROCSIZE(pp)),
             format_k2(pagetok(VP(pp, vm_rssize))),              format_k2(pagetok(VP(pp, vm_rssize))),
Line 743  static unsigned char sorted_state[] = Line 766  static unsigned char sorted_state[] =
 #define ORDERKEY_PRIO \  #define ORDERKEY_PRIO \
   if ((result = PP(p2, p_priority) - PP(p1, p_priority)) == 0)    if ((result = PP(p2, p_priority) - PP(p1, p_priority)) == 0)
   
   #define ORDERKEY_KTHREADS \
     if ((result = (TP(p1, td_proc) == NULL) - (TP(p2, td_proc) == NULL)) == 0)
   
   #define ORDERKEY_KTHREADS_PRIO \
     if ((result = TP(p2, td_pri) - TP(p1, td_pri)) == 0)
   
 #define ORDERKEY_RSSIZE \  #define ORDERKEY_RSSIZE \
   if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0)     if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0) 
   
Line 780  proc_compare(struct proc **pp1, struct p Line 809  proc_compare(struct proc **pp1, struct p
   
 #ifdef ORDER  #ifdef ORDER
 /* compare routines */  /* compare routines */
int compare_size(), compare_res(), compare_time(), compare_prio();int compare_size(), compare_res(), compare_time(), compare_prio(), compare_thr();
   
 int (*proc_compares[])() = {  int (*proc_compares[])() = {
     compare_cpu,      compare_cpu,
Line 788  int (*proc_compares[])() = { Line 817  int (*proc_compares[])() = {
     compare_res,      compare_res,
     compare_time,      compare_time,
     compare_prio,      compare_prio,
       compare_thr,
     NULL      NULL
 };  };
   
Line 857  compare_time(struct proc **pp1, struct p Line 887  compare_time(struct proc **pp1, struct p
   
     ORDERKEY_CPTICKS      ORDERKEY_CPTICKS
     ORDERKEY_PCTCPU      ORDERKEY_PCTCPU
       ORDERKEY_KTHREADS
       ORDERKEY_KTHREADS_PRIO
     ORDERKEY_STATE      ORDERKEY_STATE
     ORDERKEY_PRIO      ORDERKEY_PRIO
     ORDERKEY_RSSIZE      ORDERKEY_RSSIZE
Line 880  compare_prio(struct proc **pp1, struct p Line 912  compare_prio(struct proc **pp1, struct p
     p1 = *(struct kinfo_proc **) pp1;      p1 = *(struct kinfo_proc **) pp1;
     p2 = *(struct kinfo_proc **) pp2;      p2 = *(struct kinfo_proc **) pp2;
   
       ORDERKEY_KTHREADS
       ORDERKEY_KTHREADS_PRIO
     ORDERKEY_PRIO      ORDERKEY_PRIO
     ORDERKEY_CPTICKS      ORDERKEY_CPTICKS
     ORDERKEY_PCTCPU      ORDERKEY_PCTCPU
Line 890  compare_prio(struct proc **pp1, struct p Line 924  compare_prio(struct proc **pp1, struct p
   
     return(result);      return(result);
 }  }
   
   int
   compare_thr(struct proc **pp1, struct proc **pp2)
   {
       register struct kinfo_proc *p1;
       register struct kinfo_proc *p2;
       register int result;
       register pctcpu lresult;
   
       /* remove one level of indirection */
       p1 = *(struct kinfo_proc **) pp1;
       p2 = *(struct kinfo_proc **) pp2;
   
       ORDERKEY_KTHREADS
       ORDERKEY_KTHREADS_PRIO
       ORDERKEY_CPTICKS
       ORDERKEY_PCTCPU
       ORDERKEY_STATE
       ORDERKEY_RSSIZE
       ORDERKEY_MEM
       ;
   
       return(result);
   }
   
   
 #endif  #endif
   
 /*  /*

Removed from v.1.10  
changed lines
  Added in v.1.11