"Fossies" - the Fresh Open Source Software Archive

Member "atop-2.8.1/showprocs.c" (7 Jan 2023, 60098 Bytes) of package /linux/misc/atop-2.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "showprocs.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.7.1_vs_2.8.0.

    1 /*
    2 ** ATOP - System & Process Monitor 
    3 **
    4 ** The program 'atop' offers the possibility to view the activity of
    5 ** the system on system-level as well as process-level.
    6 **
    7 ** This source-file contains the Linux-specific functions to calculate
    8 ** figures to be visualized.
    9 ** ==========================================================================
   10 ** Author:      JC van Winkel - AT Computing, Nijmegen, Holland
   11 ** E-mail:      jc@ATComputing.nl
   12 ** Date:        November 2009
   13 ** --------------------------------------------------------------------------
   14 ** Copyright (C) 2009 JC van Winkel
   15 **
   16 ** This program is free software; you can redistribute it and/or modify it
   17 ** under the terms of the GNU General Public License as published by the
   18 ** Free Software Foundation; either version 2, or (at your option) any
   19 ** later version.
   20 **
   21 ** This program is distributed in the hope that it will be useful, but
   22 ** WITHOUT ANY WARRANTY; without even the implied warranty of
   23 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   24 ** See the GNU General Public License for more details.
   25 **
   26 ** You should have received a copy of the GNU General Public License
   27 ** along with this program; if not, write to the Free Software
   28 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   29 ** --------------------------------------------------------------------------
   30 */
   31 
   32 #include <sys/types.h>
   33 #include <sys/param.h>
   34 #include <sys/stat.h>
   35 #include <signal.h>
   36 #include <time.h>
   37 #include <stdio.h>
   38 #include <stdlib.h>
   39 #include <string.h>
   40 #include <errno.h>
   41 #include <fcntl.h>
   42 #include <unistd.h>
   43 #include <stdarg.h>
   44 #include <curses.h>
   45 #include <pwd.h>
   46 #include <grp.h>
   47 #include <regex.h>
   48 
   49 #include "atop.h"
   50 #include "photoproc.h"
   51 #include "photosyst.h"
   52 #include "showgeneric.h"
   53 #include "showlinux.h"
   54 
   55 static void format_bandw(char *, count_t);
   56 
   57 static char     *columnhead[] = {
   58     [MSORTCPU]= "CPU", [MSORTMEM]= "MEM",
   59     [MSORTDSK]= "DSK", [MSORTNET]= "NET",
   60     [MSORTGPU]= "GPU",
   61 };
   62 
   63 
   64 /***************************************************************/
   65 static int *colspacings;     // ugly static var, 
   66                              // but saves a lot of recomputations
   67                              // points to table with intercolumn 
   68                              // spacings
   69 static proc_printpair newelems[MAXITEMS];
   70                              // ugly static var,
   71                              // but saves a lot of recomputations
   72                              // contains the actual list of items to
   73                              // be printed
   74                              //
   75                              //
   76 /***************************************************************/
   77 /*
   78  * gettotwidth: calculate the sum of widths and number of columns
   79  * Also copys the printpair elements to the static array newelems
   80  * for later removal of lower priority elements.
   81  * Params:
   82  * elemptr: the array of what to print
   83  * nitems: (ref) returns the number of printitems in the array
   84  * sumwidth: (ref) returns the total width of the printitems in the array
   85  * varwidth: (ref) returns the number of variable width items in the array
   86  */
   87 void
   88 gettotwidth(proc_printpair* elemptr, int *nitems, int *sumwidth, int* varwidth) 
   89 {
   90         int i;
   91         int col;
   92         int varw=0;
   93 
   94         for (i=0, col=0; elemptr[i].f!=0; ++i) 
   95         {
   96                 col += (elemptr[i].f->varwidth ? 0 : elemptr[i].f->width);
   97                 varw += elemptr[i].f->varwidth;
   98                 newelems[i]=elemptr[i];    // copy element
   99         }
  100         newelems[i].f=0;
  101         *nitems=i;
  102         *sumwidth=col;
  103         *varwidth=varw;
  104 }
  105 
  106 
  107 
  108 /***************************************************************/
  109 /*
  110  * getspacings: determine how much extra space there is for
  111  * inter-column space.
  112  * returns an int array this number of spaces to add after each column
  113  * also removes items from the newelems array if the available width
  114  * is lower than what is needed.  The lowest priority columns are
  115  * removed first.
  116  *
  117  * Note: this function is only to be called when screen is true.
  118  */
  119 int *
  120 getspacings(proc_printpair* elemptr) 
  121 {
  122         static int spacings[MAXITEMS];
  123 
  124         int col=0;
  125         int nitems;
  126         int varwidth=0;
  127         int j;
  128         int maxw=screen ? COLS : linelen;    // for non screen: 80 columns max
  129 
  130         // get width etc; copy elemptr array to static newelms
  131         gettotwidth(elemptr, &nitems, &col, &varwidth);
  132 
  133         /* cases:
  134          *   1) nitems==1: just one column, no spacing needed.  Done
  135          *
  136          *   2) total width is more than COLS: remove low prio columns
  137          *      2a)  a varwidth column: no spacing needed
  138          *      2b)  total width is less than COLS: compute inter spacing
  139          */
  140 
  141         if (nitems==1)          // no inter column spacing if 1 column
  142         {
  143                 spacings[0]=0;
  144                 return spacings;
  145         }
  146 
  147         // Check if available width is less than required.
  148         // If so, delete columns to make things fit
  149         // space required:
  150         // width + (nitems-1) * 1 space + 12 for a varwidth column.
  151         while (col + nitems-1+ 12*varwidth > maxw)  
  152         {    
  153                 int lowestprio=999999;
  154                 int lowestprio_index=-1;
  155                 int i;
  156                 for (i=0; i<nitems; ++i) 
  157                 {
  158                         if (newelems[i].prio < lowestprio) 
  159                         {
  160                                 lowestprio=newelems[i].prio;
  161                                 lowestprio_index=i;
  162                         }
  163                 }
  164                 
  165                 // lowest priority item found, remove from newelems;
  166                 col -= newelems[lowestprio_index].f->width;
  167                 varwidth -= newelems[lowestprio_index].f->varwidth;
  168                 memmove(newelems+lowestprio_index, 
  169                         newelems+lowestprio_index+1, 
  170                         (nitems-lowestprio_index)* sizeof(proc_printpair));   
  171                        // also copies final 0 entry
  172                 nitems--;
  173         }
  174 
  175 
  176         /* if there is a var width column, handle that separately */
  177         if (varwidth) 
  178         {
  179                 for (j=0; j<nitems; ++j) 
  180                 {
  181                         spacings[j]=1;
  182                         if (elemptr[j].f->varwidth)
  183                         {
  184                                 elemptr[j].f->width=maxw-col-(nitems-1);
  185                                 // only nitems-1 in-between spaces
  186                                 // needed
  187                         }
  188 
  189                 }
  190                 return spacings;
  191         }
  192 
  193         // avoid division by 0
  194         if (nitems==1)
  195         {
  196                 spacings[0]=0;
  197                 return spacings;
  198         }
  199 
  200         /* fixed columns, spread whitespace over columns */
  201         double over=(0.0+maxw-col)/(nitems-1);
  202         double todo=over;
  203 
  204         for (j=0; j<nitems-1; ++j)   // last column gets no space appended
  205         {
  206                 spacings[j]=(int)todo+0.5;
  207                 todo-=spacings[j];
  208                 todo+=over;
  209         }
  210         spacings[j]=0;
  211         return spacings;
  212 }
  213 
  214 
  215 /*
  216  * showhdrline: show header line for processes.
  217  * if in interactive mode, also add a page numer
  218  * if in interactive mode, columns are aligned to fill out rows
  219  */
  220 void
  221 showhdrline(proc_printpair* elemptr, int curlist, int totlist, 
  222                   char showorder, char autosort) 
  223 {
  224         proc_printpair curelem;
  225 
  226         char *chead="";
  227         char *autoindic="";
  228         int order=showorder;
  229         int col=0;
  230         int allign;
  231         char pagindic[10];
  232         int pagindiclen;
  233         int n=0;
  234         int bufsz;
  235         int maxw=screen ? COLS : linelen;    // for non screen: 80 columns max
  236 
  237         colspacings=getspacings(elemptr);
  238         bufsz=maxw+1;
  239 
  240         elemptr=newelems;     // point to adjusted array
  241         char buf[bufsz+2];    // long live dynamically sized auto arrays...
  242         
  243         if (!screen) 
  244         {
  245                 printg("\n");
  246         }
  247 
  248         while ((curelem=*elemptr).f!=0) 
  249         {
  250         int widen = 0;
  251 
  252                 if (curelem.f->head==0)     // empty header==special: SORTITEM
  253                 {
  254                         chead     = columnhead[order];
  255                         autoindic = autosort ? "A" : " ";
  256             widen     = procprt_SORTITEM.width-3;
  257                 } 
  258                 else 
  259                 {
  260                         chead=curelem.f->head;
  261                         autoindic="";
  262                 }
  263 
  264                 if (screen)
  265                 {
  266                         col += sprintf(buf+col, "%*s%s%*s",
  267                 widen, autoindic, chead, colspacings[n], "");
  268                 }
  269                 else
  270                 {
  271                         col += sprintf(buf+col, "%s%s ", autoindic, chead);
  272                 }
  273                               
  274                 elemptr++;
  275                 n++;
  276         }
  277 
  278         if (screen)   // add page number, eat from last header if needed...
  279         {
  280                 pagindiclen=sprintf(pagindic,"%d/%d", curlist, totlist);
  281                 allign=COLS-col-pagindiclen;    // extra spaces needed
  282             
  283                 if (allign >= 0)     // allign by adding spaces
  284                 {
  285                         sprintf(buf+col, "%*s", allign+pagindiclen, pagindic);
  286                 }
  287                 else if (col+allign >= 0)
  288                 {    // allign by removing from the right
  289                         sprintf(buf+col+allign, "%s", pagindic);
  290                 }
  291         }
  292 
  293         printg("%s", buf);
  294 
  295         if (!screen) 
  296         {
  297                 printg("\n");
  298         }
  299 }
  300 
  301 
  302 
  303 /***************************************************************/
  304 /*
  305  * showprocline: show line for processes.
  306  * if in interactive mode, columns are aligned to fill out rows
  307  * params:
  308  *     elemptr: pointer to array of print definition structs ptrs
  309  *     curstat: the process to print
  310  *     perc: the sort order used
  311  *     nsecs: number of seconds elapsed between previous and this sample
  312  *     avgval: is averaging out per second needed?
  313  */
  314 void
  315 showprocline(proc_printpair* elemptr, struct tstat *curstat, 
  316                             double perc, int nsecs, int avgval) 
  317 {
  318         proc_printpair curelem;
  319         
  320         elemptr=newelems;      // point to static array
  321         int n=0;
  322 
  323     if (screen && threadview)
  324     {
  325         if (usecolors && !curstat->gen.isproc)
  326         {
  327             attron(COLOR_PAIR(COLORTHR));
  328         }
  329         else
  330         {
  331             if (!usecolors && curstat->gen.isproc)
  332                 attron(A_BOLD);
  333         }
  334     }
  335 
  336         while ((curelem=*elemptr).f!=0) 
  337         {
  338                 // what to print?  SORTITEM, or active process or
  339                 // exited process?
  340 
  341                 if (curelem.f->head==0)                // empty string=sortitem
  342                 {
  343                         printg("%*.0lf%%", procprt_SORTITEM.width-1, perc);
  344                 }
  345                 else if (curstat->gen.state != 'E')  // active process
  346                 {
  347                         printg("%s", curelem.f->doactiveconvert(curstat, 
  348                                                         avgval, nsecs));
  349                 }
  350                 else                                 // exited process
  351                 {
  352                         printg("%s", curelem.f->doexitconvert(curstat, 
  353                                                         avgval, nsecs));
  354                 }
  355 
  356                 if (screen)
  357                 {
  358                         printg("%*s",colspacings[n], "");
  359                 }
  360                 else
  361                 {
  362                         printg(" ");
  363                 }
  364 
  365                 elemptr++;
  366                 n++;
  367         }
  368 
  369     if (screen && threadview)
  370     {
  371         if (usecolors && !curstat->gen.isproc)
  372         {
  373             attroff(COLOR_PAIR(COLORTHR));
  374         }
  375         else
  376         {
  377             if (!usecolors && curstat->gen.isproc)
  378                 attroff(A_BOLD);
  379         }
  380     }
  381 
  382         if (!screen) 
  383         {
  384                 printg("\n");
  385         }
  386 }
  387 
  388 
  389 /*******************************************************************/
  390 /* PROCESS PRINT FUNCTIONS */
  391 /***************************************************************/
  392 char *
  393 procprt_NOTAVAIL_4(struct tstat *curstat, int avgval, int nsecs)
  394 {
  395         return "   ?";
  396 }
  397 
  398 char *
  399 procprt_NOTAVAIL_5(struct tstat *curstat, int avgval, int nsecs)
  400 {
  401         return "    ?";
  402 }
  403 
  404 char *
  405 procprt_NOTAVAIL_6(struct tstat *curstat, int avgval, int nsecs)
  406 {
  407         return "     ?";
  408 }
  409 
  410 char *
  411 procprt_NOTAVAIL_7(struct tstat *curstat, int avgval, int nsecs)
  412 {
  413         return "      ?";
  414 }
  415 /***************************************************************/
  416 char *
  417 procprt_TID_ae(struct tstat *curstat, int avgval, int nsecs)
  418 {
  419         static char buf[64];
  420 
  421     if (curstat->gen.isproc)
  422             sprintf(buf, "%*s", procprt_TID.width, "-");
  423     else
  424             sprintf(buf, "%*d", procprt_TID.width, curstat->gen.pid);
  425         return buf;
  426 }
  427 
  428 proc_printdef procprt_TID = 
  429    { "TID", "TID", procprt_TID_ae, procprt_TID_ae, 5}; //DYNAMIC WIDTH!
  430 /***************************************************************/
  431 char *
  432 procprt_PID_a(struct tstat *curstat, int avgval, int nsecs)
  433 {
  434         static char buf[64];
  435 
  436         sprintf(buf, "%*d", procprt_PID.width, curstat->gen.tgid);
  437         return buf;
  438 }
  439 
  440 char *
  441 procprt_PID_e(struct tstat *curstat, int avgval, int nsecs)
  442 {
  443         static char buf[64];
  444 
  445         if (curstat->gen.pid == 0)
  446             sprintf(buf, "%*s", procprt_PID.width, "?");
  447     else
  448             sprintf(buf, "%*d", procprt_PID.width, curstat->gen.tgid);
  449         return buf;
  450 }
  451 
  452 proc_printdef procprt_PID = 
  453    { "PID", "PID", procprt_PID_a, procprt_PID_e, 5}; //DYNAMIC WIDTH!
  454 /***************************************************************/
  455 char *
  456 procprt_PPID_a(struct tstat *curstat, int avgval, int nsecs)
  457 {
  458         static char buf[64];
  459 
  460         sprintf(buf, "%*d", procprt_PPID.width, curstat->gen.ppid);
  461         return buf;
  462 }
  463 
  464 char *
  465 procprt_PPID_e(struct tstat *curstat, int avgval, int nsecs)
  466 {
  467         static char buf[64];
  468 
  469     if (curstat->gen.ppid)
  470             sprintf(buf, "%*d", procprt_PPID.width, curstat->gen.ppid);
  471     else
  472         sprintf(buf, "%*s", procprt_PPID.width, "-");
  473         return buf;
  474 }
  475 
  476 proc_printdef procprt_PPID = 
  477    { "PPID", "PPID", procprt_PPID_a, procprt_PPID_e, 5 }; //DYNAMIC WIDTH!
  478 /***************************************************************/
  479 char *
  480 procprt_VPID_a(struct tstat *curstat, int avgval, int nsecs)
  481 {
  482         static char buf[64];
  483 
  484         sprintf(buf, "%*d", procprt_VPID.width, curstat->gen.vpid);
  485         return buf;
  486 }
  487 
  488 char *
  489 procprt_VPID_e(struct tstat *curstat, int avgval, int nsecs)
  490 {
  491         static char buf[64];
  492 
  493     sprintf(buf, "%*s", procprt_VPID.width, "-");
  494         return buf;
  495 }
  496 
  497 proc_printdef procprt_VPID = 
  498    { "VPID", "VPID", procprt_VPID_a, procprt_VPID_e, 5 }; //DYNAMIC WIDTH!
  499 /***************************************************************/
  500 char *
  501 procprt_CTID_a(struct tstat *curstat, int avgval, int nsecs)
  502 {
  503         static char buf[32];
  504 
  505         sprintf(buf, "%5d", curstat->gen.ctid);
  506         return buf;
  507 }
  508 
  509 char *
  510 procprt_CTID_e(struct tstat *curstat, int avgval, int nsecs)
  511 {
  512         return "    -";
  513 }
  514 
  515 proc_printdef procprt_CTID = 
  516    { " CTID", "CTID", procprt_CTID_a, procprt_CTID_e, 5 };
  517 /***************************************************************/
  518 char *
  519 procprt_CID_a(struct tstat *curstat, int avgval, int nsecs)
  520 {
  521         static char buf[64];
  522 
  523     if (curstat->gen.container[0])
  524             sprintf(buf, "%-12s", curstat->gen.container);
  525     else
  526             sprintf(buf, "%-12s", "host--------");
  527 
  528         return buf;
  529 }
  530 
  531 char *
  532 procprt_CID_e(struct tstat *curstat, int avgval, int nsecs)
  533 {
  534         static char buf[64];
  535 
  536     if (curstat->gen.container[0])
  537             sprintf(buf, "%-12s", curstat->gen.container);
  538     else
  539             sprintf(buf, "%-12s", "?");
  540 
  541         return buf;
  542 }
  543 
  544 proc_printdef procprt_CID = 
  545    { "CID         ", "CID", procprt_CID_a, procprt_CID_e, 12};
  546 /***************************************************************/
  547 char *
  548 procprt_SYSCPU_ae(struct tstat *curstat, int avgval, int nsecs)
  549 {
  550         static char buf[10];
  551 
  552         val2cpustr(curstat->cpu.stime*1000/hertz, buf);
  553         return buf;
  554 }
  555 
  556 proc_printdef procprt_SYSCPU = 
  557    { "SYSCPU", "SYSCPU", procprt_SYSCPU_ae, procprt_SYSCPU_ae, 6 };
  558 /***************************************************************/
  559 char *
  560 procprt_USRCPU_ae(struct tstat *curstat, int avgval, int nsecs)
  561 {
  562         static char buf[10];
  563 
  564         val2cpustr(curstat->cpu.utime*1000/hertz, buf);
  565         return buf;
  566 }
  567 
  568 proc_printdef procprt_USRCPU = 
  569    { "USRCPU", "USRCPU", procprt_USRCPU_ae, procprt_USRCPU_ae, 6 };
  570 /***************************************************************/
  571 char *
  572 procprt_VGROW_a(struct tstat *curstat, int avgval, int nsecs)
  573 {
  574         static char buf[10];
  575 
  576         val2memstr(curstat->mem.vgrow*1024, buf, BFORMAT, 0, 0);
  577         return buf;
  578 }
  579 
  580 char *
  581 procprt_VGROW_e(struct tstat *curstat, int avgval, int nsecs)
  582 {
  583         return "    0K";
  584 }
  585 
  586 proc_printdef procprt_VGROW = 
  587    { " VGROW", "VGROW", procprt_VGROW_a, procprt_VGROW_e, 6 };
  588 /***************************************************************/
  589 char *
  590 procprt_RGROW_a(struct tstat *curstat, int avgval, int nsecs)
  591 {
  592         static char buf[10];
  593 
  594         val2memstr(curstat->mem.rgrow*1024, buf, BFORMAT, 0, 0);
  595         return buf;
  596 }
  597 
  598 char *
  599 procprt_RGROW_e(struct tstat *curstat, int avgval, int nsecs)
  600 {
  601         return "    0K";
  602 }
  603 
  604 proc_printdef procprt_RGROW = 
  605    { " RGROW", "RGROW", procprt_RGROW_a, procprt_RGROW_e, 6 };
  606 /***************************************************************/
  607 char *
  608 procprt_MINFLT_ae(struct tstat *curstat, int avgval, int nsecs)
  609 {
  610         static char buf[10];
  611 
  612         val2valstr(curstat->mem.minflt, buf, 6, avgval, nsecs);
  613         return buf;
  614 }
  615 
  616 proc_printdef procprt_MINFLT = 
  617    { "MINFLT", "MINFLT", procprt_MINFLT_ae, procprt_MINFLT_ae, 6 };
  618 /***************************************************************/
  619 char *
  620 procprt_MAJFLT_ae(struct tstat *curstat, int avgval, int nsecs)
  621 {
  622         static char buf[10];
  623 
  624         val2valstr(curstat->mem.majflt, buf, 6, avgval, nsecs);
  625         return buf;
  626 }
  627 
  628 proc_printdef procprt_MAJFLT = 
  629    { "MAJFLT", "MAJFLT", procprt_MAJFLT_ae, procprt_MAJFLT_ae, 6 };
  630 /***************************************************************/
  631 char *
  632 procprt_VSTEXT_a(struct tstat *curstat, int avgval, int nsecs)
  633 {
  634         static char buf[10];
  635 
  636         val2memstr(curstat->mem.vexec*1024, buf, BFORMAT, 0, 0);
  637         return buf;
  638 }
  639 
  640 char *
  641 procprt_VSTEXT_e(struct tstat *curstat, int avgval, int nsecs)
  642 {
  643         return "    0K";
  644 }
  645 
  646 proc_printdef procprt_VSTEXT = 
  647    { "VSTEXT", "VSTEXT", procprt_VSTEXT_a, procprt_VSTEXT_e, 6 };
  648 /***************************************************************/
  649 char *
  650 procprt_VSIZE_a(struct tstat *curstat, int avgval, int nsecs)
  651 {
  652         static char buf[10];
  653 
  654         val2memstr(curstat->mem.vmem*1024, buf, BFORMAT, 0, 0);
  655         return buf;
  656 }
  657 
  658 char *
  659 procprt_VSIZE_e(struct tstat *curstat, int avgval, int nsecs)
  660 {
  661         return "    0K";
  662 }
  663 
  664 proc_printdef procprt_VSIZE = 
  665    { " VSIZE", "VSIZE", procprt_VSIZE_a, procprt_VSIZE_e, 6 };
  666 /***************************************************************/
  667 char *
  668 procprt_RSIZE_a(struct tstat *curstat, int avgval, int nsecs)
  669 {
  670         static char buf[10];
  671 
  672         val2memstr(curstat->mem.rmem*1024, buf, BFORMAT, 0, 0);
  673         return buf;
  674 }
  675 
  676 char *
  677 procprt_RSIZE_e(struct tstat *curstat, int avgval, int nsecs)
  678 {
  679         return "    0K";
  680 }
  681 
  682 proc_printdef procprt_RSIZE = 
  683    { " RSIZE", "RSIZE", procprt_RSIZE_a, procprt_RSIZE_e, 6 };
  684 /***************************************************************/
  685 char *
  686 procprt_PSIZE_a(struct tstat *curstat, int avgval, int nsecs)
  687 {
  688         static char buf[10];
  689 
  690     if (curstat->mem.pmem == (unsigned long long)-1LL)  
  691             return "    ?K";
  692 
  693         val2memstr(curstat->mem.pmem*1024, buf, BFORMAT, 0, 0);
  694         return buf;
  695 }
  696 
  697 char *
  698 procprt_PSIZE_e(struct tstat *curstat, int avgval, int nsecs)
  699 {
  700         return "    0K";
  701 }
  702 
  703 proc_printdef procprt_PSIZE = 
  704    { " PSIZE", "PSIZE", procprt_PSIZE_a, procprt_PSIZE_e, 6 };
  705 /***************************************************************/
  706 char *
  707 procprt_VSLIBS_a(struct tstat *curstat, int avgval, int nsecs)
  708 {
  709         static char buf[10];
  710 
  711         val2memstr(curstat->mem.vlibs*1024, buf, BFORMAT, 0, 0);
  712         return buf;
  713 }
  714 
  715 char *
  716 procprt_VSLIBS_e(struct tstat *curstat, int avgval, int nsecs)
  717 {
  718         return "    0K";
  719 }
  720 
  721 proc_printdef procprt_VSLIBS = 
  722    { "VSLIBS", "VSLIBS", procprt_VSLIBS_a, procprt_VSLIBS_e, 6 };
  723 /***************************************************************/
  724 char *
  725 procprt_VDATA_a(struct tstat *curstat, int avgval, int nsecs)
  726 {
  727         static char buf[10];
  728 
  729         val2memstr(curstat->mem.vdata*1024, buf, BFORMAT, 0, 0);
  730         return buf;
  731 }
  732 
  733 char *
  734 procprt_VDATA_e(struct tstat *curstat, int avgval, int nsecs)
  735 {
  736         return "    0K";
  737 }
  738 
  739 proc_printdef procprt_VDATA = 
  740    { " VDATA", "VDATA", procprt_VDATA_a, procprt_VDATA_e, 6 };
  741 /***************************************************************/
  742 char *
  743 procprt_VSTACK_a(struct tstat *curstat, int avgval, int nsecs)
  744 {
  745         static char buf[10];
  746 
  747         val2memstr(curstat->mem.vstack*1024, buf, BFORMAT, 0, 0);
  748         return buf;
  749 }
  750 
  751 char *
  752 procprt_VSTACK_e(struct tstat *curstat, int avgval, int nsecs)
  753 {
  754         return "    0K";
  755 }
  756 
  757 proc_printdef procprt_VSTACK = 
  758    { "VSTACK", "VSTACK", procprt_VSTACK_a, procprt_VSTACK_e, 6 };
  759 /***************************************************************/
  760 char *
  761 procprt_SWAPSZ_a(struct tstat *curstat, int avgval, int nsecs)
  762 {
  763         static char buf[10];
  764 
  765         val2memstr(curstat->mem.vswap*1024, buf, BFORMAT, 0, 0);
  766         return buf;
  767 }
  768 
  769 char *
  770 procprt_SWAPSZ_e(struct tstat *curstat, int avgval, int nsecs)
  771 {
  772         return "    0K";
  773 }
  774 
  775 proc_printdef procprt_SWAPSZ = 
  776    { "SWAPSZ", "SWAPSZ", procprt_SWAPSZ_a, procprt_SWAPSZ_e, 6 };
  777 /***************************************************************/
  778 char *
  779 procprt_LOCKSZ_a(struct tstat *curstat, int avgval, int nsecs)
  780 {
  781         static char buf[10];
  782 
  783         val2memstr(curstat->mem.vlock*1024, buf, KBFORMAT, 0, 0);
  784         return buf;
  785 }
  786 
  787 char *
  788 procprt_LOCKSZ_e(struct tstat *curstat, int avgval, int nsecs)
  789 {
  790         return "    0K";
  791 }
  792 
  793 proc_printdef procprt_LOCKSZ = 
  794    { "LOCKSZ", "LOCKSZ", procprt_LOCKSZ_a, procprt_LOCKSZ_e, 6 };
  795 /***************************************************************/
  796 char *
  797 procprt_CMD_a(struct tstat *curstat, int avgval, int nsecs)
  798 {
  799         static char buf[15];
  800 
  801         sprintf(buf, "%-14.14s", curstat->gen.name);
  802         return buf;
  803 }
  804 
  805 char *
  806 procprt_CMD_e(struct tstat *curstat, int avgval, int nsecs)
  807 {
  808         static char buf[15]="<";
  809         char        helpbuf[15];
  810 
  811         sprintf(helpbuf, "<%.12s>",  curstat->gen.name);
  812         sprintf(buf,     "%-14.14s", helpbuf);
  813         return buf;
  814 }
  815 
  816 proc_printdef procprt_CMD = 
  817    { "CMD           ", "CMD", procprt_CMD_a, procprt_CMD_e, 14 };
  818 /***************************************************************/
  819 char *
  820 procprt_RUID_ae(struct tstat *curstat, int avgval, int nsecs)
  821 {
  822         static char buf[9];
  823         struct passwd   *pwd;
  824 
  825         if ( (pwd = getpwuid(curstat->gen.ruid)) )
  826         {
  827                         sprintf(buf, "%-8.8s", pwd->pw_name);
  828         } 
  829         else 
  830         {
  831                         snprintf(buf, sizeof buf, "%-8d", curstat->gen.ruid);
  832         }
  833         return buf;
  834 }
  835 
  836 proc_printdef procprt_RUID = 
  837    { "RUID    ", "RUID", procprt_RUID_ae, procprt_RUID_ae, 8 };
  838 /***************************************************************/
  839 char *
  840 procprt_EUID_a(struct tstat *curstat, int avgval, int nsecs)
  841 {
  842         static char buf[9];
  843         struct passwd   *pwd;
  844 
  845         if ( (pwd = getpwuid(curstat->gen.euid)) )
  846         {
  847                         sprintf(buf, "%-8.8s", pwd->pw_name);
  848         } 
  849         else 
  850         {
  851                         snprintf(buf, sizeof buf, "%-8d", curstat->gen.euid);
  852         }
  853         return buf;
  854 }
  855 
  856 char *
  857 procprt_EUID_e(struct tstat *curstat, int avgval, int nsecs)
  858 {
  859     return "-       ";
  860 }
  861 
  862 proc_printdef procprt_EUID = 
  863    { "EUID    ", "EUID", procprt_EUID_a, procprt_EUID_e, 8 };
  864 /***************************************************************/
  865 char *
  866 procprt_SUID_a(struct tstat *curstat, int avgval, int nsecs)
  867 {
  868         static char buf[9];
  869         struct passwd   *pwd;
  870 
  871         if ( (pwd = getpwuid(curstat->gen.suid)) )
  872         {
  873                         sprintf(buf, "%-8.8s", pwd->pw_name);
  874         } 
  875         else 
  876         {
  877                         snprintf(buf, sizeof buf, "%-8d", curstat->gen.suid);
  878         }
  879         return buf;
  880 }
  881 
  882 char *
  883 procprt_SUID_e(struct tstat *curstat, int avgval, int nsecs)
  884 {
  885     return "-       ";
  886 }
  887 
  888 proc_printdef procprt_SUID = 
  889    { "SUID    ", "SUID", procprt_SUID_a, procprt_SUID_e, 8 };
  890 /***************************************************************/
  891 char *
  892 procprt_FSUID_a(struct tstat *curstat, int avgval, int nsecs)
  893 {
  894         static char buf[9];
  895         struct passwd   *pwd;
  896 
  897         if ( (pwd = getpwuid(curstat->gen.fsuid)) )
  898         {
  899                         sprintf(buf, "%-8.8s", pwd->pw_name);
  900         } 
  901         else 
  902         {
  903                         snprintf(buf, sizeof buf, "%-8d", curstat->gen.fsuid);
  904         }
  905         return buf;
  906 }
  907 
  908 char *
  909 procprt_FSUID_e(struct tstat *curstat, int avgval, int nsecs)
  910 {
  911     return "-       ";
  912 }
  913 
  914 proc_printdef procprt_FSUID = 
  915    { "FSUID   ", "FSUID", procprt_FSUID_a, procprt_FSUID_e, 8 };
  916 /***************************************************************/
  917 char *
  918 procprt_RGID_ae(struct tstat *curstat, int avgval, int nsecs)
  919 {
  920         static char buf[10];
  921         struct group    *grp;
  922         char *groupname;
  923         char grname[16];
  924 
  925         if ( (grp = getgrgid(curstat->gen.rgid)) )
  926         {
  927                         groupname = grp->gr_name;
  928         }
  929         else
  930         {
  931                         snprintf(grname, sizeof grname, "%d",curstat->gen.rgid);
  932                         groupname = grname;
  933         }
  934 
  935         sprintf(buf, "%-8.8s", groupname);
  936         return buf;
  937 }
  938 
  939 proc_printdef procprt_RGID = 
  940    { "RGID    ", "RGID", procprt_RGID_ae, procprt_RGID_ae, 8 };
  941 /***************************************************************/
  942 char *
  943 procprt_EGID_a(struct tstat *curstat, int avgval, int nsecs)
  944 {
  945         static char buf[10];
  946         struct group    *grp;
  947         char *groupname;
  948         char grname[16];
  949 
  950         if ( (grp = getgrgid(curstat->gen.egid)) )
  951         {
  952                         groupname = grp->gr_name;
  953         }
  954         else
  955         {
  956                         snprintf(grname, sizeof grname, "%d",curstat->gen.egid);
  957                         groupname = grname;
  958         }
  959 
  960         sprintf(buf, "%-8.8s", groupname);
  961         return buf;
  962 }
  963 
  964 char *
  965 procprt_EGID_e(struct tstat *curstat, int avgval, int nsecs)
  966 {
  967     return "-       ";
  968 }
  969 
  970 proc_printdef procprt_EGID = 
  971    { "EGID    ", "EGID", procprt_EGID_a, procprt_EGID_e, 8 };
  972 /***************************************************************/
  973 char *
  974 procprt_SGID_a(struct tstat *curstat, int avgval, int nsecs)
  975 {
  976         static char buf[10];
  977         struct group    *grp;
  978         char *groupname;
  979         char grname[16];
  980 
  981         if ( (grp = getgrgid(curstat->gen.sgid)) )
  982         {
  983                         groupname = grp->gr_name;
  984         }
  985         else
  986         {
  987                         snprintf(grname, sizeof grname, "%d",curstat->gen.sgid);
  988                         groupname = grname;
  989         }
  990 
  991         sprintf(buf, "%-8.8s", groupname);
  992         return buf;
  993 }
  994 
  995 char *
  996 procprt_SGID_e(struct tstat *curstat, int avgval, int nsecs)
  997 {
  998     return "-       ";
  999 }
 1000 
 1001 proc_printdef procprt_SGID = 
 1002    { "SGID    ", "SGID", procprt_SGID_a, procprt_SGID_e, 8 };
 1003 /***************************************************************/
 1004 char *
 1005 procprt_FSGID_a(struct tstat *curstat, int avgval, int nsecs)
 1006 {
 1007         static char buf[10];
 1008         struct group    *grp;
 1009         char *groupname;
 1010         char grname[16];
 1011 
 1012         if ( (grp = getgrgid(curstat->gen.fsgid)) )
 1013         {
 1014                         groupname = grp->gr_name;
 1015         }
 1016         else
 1017         {
 1018                         snprintf(grname, sizeof grname,"%d",curstat->gen.fsgid);
 1019                         groupname = grname;
 1020         }
 1021 
 1022         sprintf(buf, "%-8.8s", groupname);
 1023         return buf;
 1024 }
 1025 
 1026 char *
 1027 procprt_FSGID_e(struct tstat *curstat, int avgval, int nsecs)
 1028 {
 1029     return "-       ";
 1030 }
 1031 
 1032 proc_printdef procprt_FSGID = 
 1033    { "FSGID   ", "FSGID", procprt_FSGID_a, procprt_FSGID_e, 8 };
 1034 /***************************************************************/
 1035 char *
 1036 procprt_STDATE_ae(struct tstat *curstat, int avgval, int nsecs)
 1037 {
 1038         static char buf[11];
 1039 
 1040         convdate(curstat->gen.btime, buf);
 1041         return buf;
 1042 }
 1043 
 1044 proc_printdef procprt_STDATE = 
 1045    { "  STDATE  ", "STDATE", procprt_STDATE_ae, procprt_STDATE_ae, 10 };
 1046 /***************************************************************/
 1047 char *
 1048 procprt_STTIME_ae(struct tstat *curstat, int avgval, int nsecs)
 1049 {
 1050         static char buf[9];
 1051 
 1052         convtime(curstat->gen.btime, buf);
 1053         return buf;
 1054 }
 1055 
 1056 proc_printdef procprt_STTIME = 
 1057    { " STTIME ", "STTIME", procprt_STTIME_ae, procprt_STTIME_ae, 8 };
 1058 /***************************************************************/
 1059 char *
 1060 procprt_ENDATE_a(struct tstat *curstat, int avgval, int nsecs)
 1061 {
 1062         static char buf[11];
 1063 
 1064     strcpy(buf, "  active  ");
 1065 
 1066         return buf;
 1067 }
 1068 
 1069 char *
 1070 procprt_ENDATE_e(struct tstat *curstat, int avgval, int nsecs)
 1071 {
 1072         static char buf[11];
 1073 
 1074         convdate(curstat->gen.btime + curstat->gen.elaps/hertz, buf);
 1075 
 1076         return buf;
 1077 }
 1078 
 1079 proc_printdef procprt_ENDATE = 
 1080    { "  ENDATE  ", "ENDATE", procprt_ENDATE_a, procprt_ENDATE_e, 10 };
 1081 /***************************************************************/
 1082 char *
 1083 procprt_ENTIME_a(struct tstat *curstat, int avgval, int nsecs)
 1084 {
 1085         static char buf[9];
 1086 
 1087     strcpy(buf, " active ");
 1088 
 1089         return buf;
 1090 }
 1091 
 1092 char *
 1093 procprt_ENTIME_e(struct tstat *curstat, int avgval, int nsecs)
 1094 {
 1095         static char buf[9];
 1096 
 1097         convtime(curstat->gen.btime + curstat->gen.elaps/hertz, buf);
 1098 
 1099         return buf;
 1100 }
 1101 
 1102 proc_printdef procprt_ENTIME = 
 1103    { " ENTIME ", "ENTIME", procprt_ENTIME_a, procprt_ENTIME_e, 8 };
 1104 /***************************************************************/
 1105 char *
 1106 procprt_THR_a(struct tstat *curstat, int avgval, int nsecs)
 1107 {
 1108         static char buf[15];
 1109 
 1110         sprintf(buf, "%4d", curstat->gen.nthr);
 1111         return buf;
 1112 }
 1113 
 1114 char *
 1115 procprt_THR_e(struct tstat *curstat, int avgval, int nsecs)
 1116 {
 1117         return "   0";
 1118 }
 1119 
 1120 proc_printdef procprt_THR = 
 1121    { " THR", "THR", procprt_THR_a, procprt_THR_e, 4 };
 1122 /***************************************************************/
 1123 char *
 1124 procprt_TRUN_a(struct tstat *curstat, int avgval, int nsecs)
 1125 {
 1126         static char buf[15];
 1127 
 1128         sprintf(buf, "%4d", curstat->gen.nthrrun);
 1129         return buf;
 1130 }
 1131 
 1132 char *
 1133 procprt_TRUN_e(struct tstat *curstat, int avgval, int nsecs)
 1134 {
 1135         return "   0";
 1136 }
 1137 
 1138 proc_printdef procprt_TRUN = 
 1139    { "TRUN", "TRUN", procprt_TRUN_a, procprt_TRUN_e, 4 };
 1140 /***************************************************************/
 1141 char *
 1142 procprt_TSLPI_a(struct tstat *curstat, int avgval, int nsecs)
 1143 {
 1144         static char buf[15];
 1145 
 1146         sprintf(buf, "%5d", curstat->gen.nthrslpi);
 1147         return buf;
 1148 }
 1149 
 1150 char *
 1151 procprt_TSLPI_e(struct tstat *curstat, int avgval, int nsecs)
 1152 {
 1153         return "    0";
 1154 }
 1155 
 1156 proc_printdef procprt_TSLPI = 
 1157    { "TSLPI", "TSLPI", procprt_TSLPI_a, procprt_TSLPI_e, 5 };
 1158 /***************************************************************/
 1159 char *
 1160 procprt_TSLPU_a(struct tstat *curstat, int avgval, int nsecs)
 1161 {
 1162         static char buf[15];
 1163 
 1164         sprintf(buf, "%5d", curstat->gen.nthrslpu);
 1165         return buf;
 1166 }
 1167 
 1168 char *
 1169 procprt_TSLPU_e(struct tstat *curstat, int avgval, int nsecs)
 1170 {
 1171         return "    0";
 1172 }
 1173 
 1174 proc_printdef procprt_TSLPU = 
 1175    { "TSLPU", "TSLPU", procprt_TSLPU_a, procprt_TSLPU_e, 5 };
 1176 /***************************************************************/
 1177 #define SCHED_NORMAL    0
 1178 #define SCHED_FIFO  1
 1179 #define SCHED_RR    2
 1180 #define SCHED_BATCH 3
 1181 #define SCHED_ISO   4
 1182 #define SCHED_IDLE  5
 1183 #define SCHED_DEADLINE  6
 1184 
 1185 char *
 1186 procprt_POLI_a(struct tstat *curstat, int avgval, int nsecs)
 1187 {
 1188         switch (curstat->cpu.policy)
 1189         {
 1190                 case SCHED_NORMAL:
 1191                         return "norm";
 1192                         break;
 1193                 case SCHED_FIFO:
 1194                         return "fifo";
 1195                         break;
 1196                 case SCHED_RR:
 1197                         return "rr  ";
 1198                         break;
 1199                 case SCHED_BATCH:
 1200                         return "btch";
 1201                         break;
 1202                 case SCHED_ISO:
 1203                         return "iso ";
 1204                         break;
 1205                 case SCHED_IDLE:
 1206                         return "idle";
 1207                         break;
 1208                 case SCHED_DEADLINE:
 1209                         return "dead";
 1210                         break;
 1211         }
 1212         return "?   ";
 1213 }
 1214 
 1215 char *
 1216 procprt_POLI_e(struct tstat *curstat, int avgval, int nsecs)
 1217 {
 1218         return "-   ";
 1219 }
 1220 
 1221 proc_printdef procprt_POLI = 
 1222    { "POLI", "POLI", procprt_POLI_a, procprt_POLI_e, 4 };
 1223 /***************************************************************/
 1224 char *
 1225 procprt_NICE_a(struct tstat *curstat, int avgval, int nsecs)
 1226 {
 1227         static char buf[15];
 1228 
 1229         sprintf(buf, "%4d", curstat->cpu.nice);
 1230         return buf;
 1231 }
 1232 
 1233 char *
 1234 procprt_NICE_e(struct tstat *curstat, int avgval, int nsecs)
 1235 {
 1236         return "   -";
 1237 }
 1238 
 1239 proc_printdef procprt_NICE = 
 1240    { "NICE", "NICE", procprt_NICE_a, procprt_NICE_e, 4 };
 1241 /***************************************************************/
 1242 char *
 1243 procprt_PRI_a(struct tstat *curstat, int avgval, int nsecs)
 1244 {
 1245         static char buf[15];
 1246 
 1247         sprintf(buf, "%3d", curstat->cpu.prio);
 1248         return buf;
 1249 }
 1250 
 1251 char *
 1252 procprt_PRI_e(struct tstat *curstat, int avgval, int nsecs)
 1253 {
 1254         return "  -";
 1255 }
 1256 
 1257 proc_printdef procprt_PRI = 
 1258    { "PRI", "PRI", procprt_PRI_a, procprt_PRI_e, 3 };
 1259 /***************************************************************/
 1260 char *
 1261 procprt_RTPR_a(struct tstat *curstat, int avgval, int nsecs)
 1262 {
 1263         static char buf[15];
 1264 
 1265         sprintf(buf, "%4d", curstat->cpu.rtprio);
 1266         return buf;
 1267 }
 1268 
 1269 char *
 1270 procprt_RTPR_e(struct tstat *curstat, int avgval, int nsecs)
 1271 {
 1272         return "   -";
 1273 }
 1274 
 1275 proc_printdef procprt_RTPR = 
 1276    { "RTPR", "RTPR", procprt_RTPR_a, procprt_RTPR_e, 4 };
 1277 /***************************************************************/
 1278 char *
 1279 procprt_CURCPU_a(struct tstat *curstat, int avgval, int nsecs)
 1280 {
 1281         static char buf[15];
 1282 
 1283         sprintf(buf, "%5d", curstat->cpu.curcpu);
 1284         return buf;
 1285 }
 1286 
 1287 char *
 1288 procprt_CURCPU_e(struct tstat *curstat, int avgval, int nsecs)
 1289 {
 1290         return "    -";
 1291 }
 1292 
 1293 proc_printdef procprt_CURCPU = 
 1294    { "CPUNR", "CPUNR", procprt_CURCPU_a, procprt_CURCPU_e, 5 };
 1295 /***************************************************************/
 1296 char *
 1297 procprt_ST_a(struct tstat *curstat, int avgval, int nsecs)
 1298 {
 1299         static char buf[3]="--";
 1300         if (curstat->gen.excode & ~(INT_MAX))
 1301         {
 1302                 buf[0]='N';
 1303         } 
 1304         else
 1305         { 
 1306                 buf[0]='-';
 1307         }
 1308         return buf;
 1309 }
 1310 
 1311 char *
 1312 procprt_ST_e(struct tstat *curstat, int avgval, int nsecs)
 1313 {
 1314         static char buf[3];
 1315         if (curstat->gen.excode & ~(INT_MAX))
 1316         {
 1317                 buf[0]='N';
 1318         } 
 1319         else 
 1320         { 
 1321                 buf[0]='-';
 1322         }
 1323         if (curstat->gen.excode & 0xff) 
 1324         {
 1325                 if (curstat->gen.excode & 0x80)
 1326                         buf[1] = 'C';
 1327                 else
 1328                         buf[1] = 'S';
 1329         } 
 1330         else 
 1331         {
 1332                 buf[1] = 'E';
 1333         }
 1334         return buf;
 1335 }
 1336 
 1337 proc_printdef procprt_ST = 
 1338    { "ST", "ST", procprt_ST_a, procprt_ST_e, 2 };
 1339 /***************************************************************/
 1340 char *
 1341 procprt_EXC_a(struct tstat *curstat, int avgval, int nsecs)
 1342 {
 1343         return "  -";
 1344 }
 1345 
 1346 char *
 1347 procprt_EXC_e(struct tstat *curstat, int avgval, int nsecs)
 1348 {
 1349         static char buf[4];
 1350 
 1351 
 1352         sprintf(buf, "%3d", 
 1353                  curstat->gen.excode & 0xff ?
 1354                           curstat->gen.excode & 0x7f : 
 1355                           (curstat->gen.excode>>8) & 0xff);
 1356         return buf;
 1357 }
 1358 
 1359 
 1360 proc_printdef procprt_EXC = 
 1361    { "EXC", "EXC", procprt_EXC_a, procprt_EXC_e, 3 };
 1362 /***************************************************************/
 1363 char *
 1364 procprt_S_a(struct tstat *curstat, int avgval, int nsecs)
 1365 {
 1366         static char buf[2]="E";
 1367 
 1368         buf[0]=curstat->gen.state;
 1369         return buf;
 1370 }
 1371 
 1372 char *
 1373 procprt_S_e(struct tstat *curstat, int avgval, int nsecs)
 1374 {
 1375         return "E";
 1376 
 1377 }
 1378 
 1379 proc_printdef procprt_S = 
 1380    { "S", "S", procprt_S_a, procprt_S_e, 1 };
 1381 
 1382 /***************************************************************/
 1383 char *
 1384 procprt_COMMAND_LINE_ae(struct tstat *curstat, int avgval, int nsecs)
 1385 {
 1386         extern proc_printdef procprt_COMMAND_LINE;
 1387         extern int  startoffset;    // influenced by -> and <- keys
 1388 
 1389         static char buf[CMDLEN+1];
 1390 
 1391     char    *pline     = curstat->gen.cmdline[0] ?
 1392                         curstat->gen.cmdline : curstat->gen.name;
 1393 
 1394         int     curwidth   = procprt_COMMAND_LINE.width <= CMDLEN ?
 1395                 procprt_COMMAND_LINE.width : CMDLEN;
 1396 
 1397         int     cmdlen     = strlen(pline);
 1398         int     curoffset  = startoffset <= cmdlen ? startoffset : cmdlen;
 1399 
 1400         if (screen) 
 1401                 sprintf(buf, "%-*.*s", curwidth, curwidth, pline+curoffset);
 1402         else
 1403                 sprintf(buf, "%.*s", CMDLEN, pline+curoffset);
 1404 
 1405         return buf;
 1406 }
 1407 
 1408 proc_printdef procprt_COMMAND_LINE = 
 1409        { "COMMAND-LINE (horizontal scroll with <- and -> keys)",
 1410     "COMMAND-LINE", 
 1411         procprt_COMMAND_LINE_ae, procprt_COMMAND_LINE_ae, 0, 1 };
 1412 /***************************************************************/
 1413 char *
 1414 procprt_NPROCS_ae(struct tstat *curstat, int avgval, int nsecs)
 1415 {
 1416         static char buf[10];
 1417 
 1418         val2valstr(curstat->gen.pid, buf, 6, 0, 0); // pid abused as proc counter
 1419         return buf;
 1420 }
 1421 
 1422 proc_printdef procprt_NPROCS = 
 1423    { "NPROCS", "NPROCS", procprt_NPROCS_ae, procprt_NPROCS_ae, 6 };
 1424 /***************************************************************/
 1425 char *
 1426 procprt_RDDSK_a(struct tstat *curstat, int avgval, int nsecs)
 1427 {
 1428         static char buf[10];
 1429         val2memstr(curstat->dsk.rsz*512, buf, BFORMAT, avgval, nsecs);
 1430 
 1431         return buf;
 1432 }
 1433 
 1434 char *
 1435 procprt_RDDSK_e(struct tstat *curstat, int avgval, int nsecs)
 1436 {
 1437         return "     -";
 1438 }
 1439 
 1440 proc_printdef procprt_RDDSK = 
 1441    { " RDDSK", "RDDSK", procprt_RDDSK_a, procprt_RDDSK_e, 6 };
 1442 /***************************************************************/
 1443 char *
 1444 procprt_WRDSK_a(struct tstat *curstat, int avgval, int nsecs) 
 1445 {
 1446         static char buf[10];
 1447 
 1448         val2memstr(curstat->dsk.wsz*512, buf, BFORMAT, avgval, nsecs);
 1449 
 1450         return buf;
 1451 }
 1452 
 1453 char *
 1454 procprt_WRDSK_e(struct tstat *curstat, int avgval, int nsecs)
 1455 {
 1456         return "     -";
 1457 }
 1458 
 1459 proc_printdef procprt_WRDSK = 
 1460    { " WRDSK", "WRDSK", procprt_WRDSK_a, procprt_WRDSK_e, 6 };
 1461 /***************************************************************/
 1462 char *
 1463 procprt_CWRDSK_a(struct tstat *curstat, int avgval, int nsecs) 
 1464 {
 1465     count_t nett_wsz;
 1466         static char buf[10];
 1467 
 1468     if (curstat->dsk.wsz > curstat->dsk.cwsz)
 1469         nett_wsz = curstat->dsk.wsz - curstat->dsk.cwsz;
 1470     else
 1471         nett_wsz = 0;
 1472 
 1473         val2memstr(nett_wsz*512, buf, BFORMAT, avgval, nsecs);
 1474 
 1475         return buf;
 1476 }
 1477 
 1478 proc_printdef procprt_CWRDSK = 
 1479    {" WRDSK", "CWRDSK", procprt_CWRDSK_a, procprt_WRDSK_e, 6 };
 1480 /***************************************************************/
 1481 char *
 1482 procprt_WCANCEL_a(struct tstat *curstat, int avgval, int nsecs)
 1483 {
 1484         static char buf[10];
 1485         val2memstr(curstat->dsk.cwsz*512, buf, BFORMAT, avgval, nsecs);
 1486 
 1487         return buf;
 1488 }
 1489 
 1490 char *
 1491 procprt_WCANCEL_e(struct tstat *curstat, int avgval, int nsecs)
 1492 {
 1493         return "     -";
 1494 }
 1495 
 1496 proc_printdef procprt_WCANCEL = 
 1497    {"WCANCL", "WCANCL", procprt_WCANCEL_a, procprt_WCANCEL_e, 6};
 1498 /***************************************************************/
 1499 char *
 1500 procprt_TCPRCV_a(struct tstat *curstat, int avgval, int nsecs)
 1501 {
 1502         static char buf[10];
 1503         
 1504         val2valstr(curstat->net.tcprcv, buf, 6, avgval, nsecs);
 1505 
 1506         return buf;
 1507 }
 1508 
 1509 char *
 1510 procprt_TCPRCV_e(struct tstat *curstat, int avgval, int nsecs) 
 1511 {      
 1512     if (supportflags & NETATOPD)
 1513     {
 1514             static char buf[10];
 1515         
 1516             val2valstr(curstat->net.tcprcv, buf, 6, avgval, nsecs);
 1517 
 1518             return buf;
 1519     }
 1520     else
 1521             return "     -";
 1522 }
 1523 
 1524 
 1525 proc_printdef procprt_TCPRCV = 
 1526    { "TCPRCV", "TCPRCV", procprt_TCPRCV_a, procprt_TCPRCV_e, 6 };
 1527 /***************************************************************/
 1528 char *
 1529 procprt_TCPRASZ_a(struct tstat *curstat, int avgval, int nsecs)
 1530 {
 1531         static char buf[10];
 1532         
 1533         int avgtcpr = curstat->net.tcprcv ?
 1534                                   curstat->net.tcprsz / curstat->net.tcprcv : 0;
 1535 
 1536         val2valstr(avgtcpr, buf, 7, 0, 0);
 1537         return buf;
 1538 }
 1539 
 1540 char *
 1541 procprt_TCPRASZ_e(struct tstat *curstat, int avgval, int nsecs)
 1542 {
 1543     if (supportflags & NETATOPD)
 1544     {
 1545             static char buf[10];
 1546         
 1547             int avgtcpr = curstat->net.tcprcv ?
 1548                                   curstat->net.tcprsz / curstat->net.tcprcv : 0;
 1549 
 1550             val2valstr(avgtcpr, buf, 7, 0, 0);
 1551             return buf;
 1552     }
 1553     else
 1554             return "      -";
 1555 }
 1556 
 1557 proc_printdef procprt_TCPRASZ = 
 1558    { "TCPRASZ", "TCPRASZ", procprt_TCPRASZ_a, procprt_TCPRASZ_e, 7 };
 1559 /***************************************************************/
 1560 char *
 1561 procprt_TCPSND_a(struct tstat *curstat, int avgval, int nsecs)
 1562 {
 1563         static char buf[10];
 1564         
 1565         val2valstr(curstat->net.tcpsnd, buf, 6, avgval, nsecs);
 1566 
 1567         return buf;
 1568 }
 1569 
 1570 char *
 1571 procprt_TCPSND_e(struct tstat *curstat, int avgval, int nsecs)
 1572 {
 1573     if (supportflags & NETATOPD)
 1574     {
 1575             static char buf[10];
 1576         
 1577             val2valstr(curstat->net.tcpsnd, buf, 6, avgval, nsecs);
 1578 
 1579             return buf;
 1580     }
 1581     else
 1582             return "     -";
 1583 }
 1584 
 1585 proc_printdef procprt_TCPSND = 
 1586    { "TCPSND", "TCPSND", procprt_TCPSND_a, procprt_TCPSND_e, 6 };
 1587 /***************************************************************/
 1588 char *
 1589 procprt_TCPSASZ_a(struct tstat *curstat, int avgval, int nsecs)
 1590 {
 1591         static char buf[10];
 1592         
 1593         int avgtcps = curstat->net.tcpsnd ?
 1594                                   curstat->net.tcpssz / curstat->net.tcpsnd : 0;
 1595 
 1596         val2valstr(avgtcps, buf, 7, 0, 0);
 1597         return buf;
 1598 }
 1599 
 1600 char *
 1601 procprt_TCPSASZ_e(struct tstat *curstat, int avgval, int nsecs)
 1602 {
 1603     if (supportflags & NETATOPD)
 1604     {
 1605             static char buf[10];
 1606         
 1607             int avgtcps = curstat->net.tcpsnd ?
 1608                                   curstat->net.tcpssz / curstat->net.tcpsnd : 0;
 1609 
 1610             val2valstr(avgtcps, buf, 7, 0, 0);
 1611             return buf;
 1612     }
 1613     else
 1614             return "      -";
 1615 }
 1616 
 1617 proc_printdef procprt_TCPSASZ = 
 1618    { "TCPSASZ", "TCPSASZ", procprt_TCPSASZ_a, procprt_TCPSASZ_e, 7 };
 1619 /***************************************************************/
 1620 char *
 1621 procprt_UDPRCV_a(struct tstat *curstat, int avgval, int nsecs)        
 1622 {
 1623         static char buf[10];
 1624         
 1625         val2valstr(curstat->net.udprcv, buf, 6, avgval, nsecs);
 1626 
 1627         return buf;
 1628 }
 1629 
 1630 char *
 1631 procprt_UDPRCV_e(struct tstat *curstat, int avgval, int nsecs) 
 1632 {
 1633     if (supportflags & NETATOPD)
 1634     {
 1635             static char buf[10];
 1636         
 1637             val2valstr(curstat->net.udprcv, buf, 6, avgval, nsecs);
 1638 
 1639             return buf;
 1640     }
 1641     else
 1642             return "     -";
 1643 }
 1644 
 1645 
 1646 proc_printdef procprt_UDPRCV = 
 1647    { "UDPRCV", "UDPRCV", procprt_UDPRCV_a, procprt_UDPRCV_e, 6 };
 1648 /***************************************************************/
 1649 char *
 1650 procprt_UDPRASZ_a(struct tstat *curstat, int avgval, int nsecs)
 1651 {
 1652         static char buf[10];
 1653         
 1654         int avgudpr = curstat->net.udprcv ?
 1655                           curstat->net.udprsz / curstat->net.udprcv : 0;
 1656 
 1657         val2valstr(avgudpr, buf, 7, 0, 0);
 1658         return buf;
 1659 }
 1660 
 1661 char *
 1662 procprt_UDPRASZ_e(struct tstat *curstat, int avgval, int nsecs)
 1663 {
 1664     if (supportflags & NETATOPD)
 1665     {
 1666             static char buf[10];
 1667         
 1668             int avgudpr = curstat->net.udprcv ?
 1669                           curstat->net.udprsz / curstat->net.udprcv : 0;
 1670 
 1671             val2valstr(avgudpr, buf, 7, 0, 0);
 1672             return buf;
 1673     }
 1674     else
 1675             return "      -";
 1676 }
 1677 
 1678 
 1679 proc_printdef procprt_UDPRASZ = 
 1680    { "UDPRASZ", "UDPRASZ", procprt_UDPRASZ_a, procprt_UDPRASZ_e, 7 };
 1681 /***************************************************************/
 1682 char *
 1683 procprt_UDPSND_a(struct tstat *curstat, int avgval, int nsecs)
 1684 {
 1685         static char buf[10];
 1686         
 1687         val2valstr(curstat->net.udpsnd, buf, 6, avgval, nsecs);
 1688 
 1689         return buf;
 1690 }
 1691 
 1692 char *
 1693 procprt_UDPSND_e(struct tstat *curstat, int avgval, int nsecs)
 1694 {
 1695     if (supportflags & NETATOPD)
 1696     {
 1697             static char buf[10];
 1698         
 1699             val2valstr(curstat->net.udpsnd, buf, 6, avgval, nsecs);
 1700 
 1701             return buf;
 1702     }
 1703     else
 1704             return "     -";
 1705 }
 1706 
 1707 proc_printdef procprt_UDPSND = 
 1708    { "UDPSND", "UDPSND", procprt_UDPSND_a, procprt_UDPSND_e, 6 };
 1709 /***************************************************************/
 1710 char *
 1711 procprt_UDPSASZ_a(struct tstat *curstat, int avgval, int nsecs)
 1712 {
 1713         static char buf[10];
 1714         
 1715         int avgudps = curstat->net.udpsnd ?
 1716                                   curstat->net.udpssz / curstat->net.udpsnd : 0;
 1717 
 1718         val2valstr(avgudps, buf, 7, 0, 0);
 1719         return buf;
 1720 }
 1721 
 1722 char *
 1723 procprt_UDPSASZ_e(struct tstat *curstat, int avgval, int nsecs)
 1724 {
 1725     if (supportflags & NETATOPD)
 1726     {
 1727             static char buf[10];
 1728         
 1729             int avgudps = curstat->net.udpsnd ?
 1730                                   curstat->net.udpssz / curstat->net.udpsnd : 0;
 1731 
 1732             val2valstr(avgudps, buf, 7, 0, 0);
 1733             return buf;
 1734     }
 1735     else
 1736             return "      -";
 1737 }
 1738 
 1739 
 1740 proc_printdef procprt_UDPSASZ = 
 1741    { "UDPSASZ", "UDPSASZ", procprt_UDPSASZ_a, procprt_UDPSASZ_e, 7 };
 1742 /***************************************************************/
 1743 char *
 1744 procprt_RNET_a(struct tstat *curstat, int avgval, int nsecs)
 1745 {
 1746         static char buf[10];
 1747         
 1748         val2valstr(curstat->net.tcprcv + curstat->net.udprcv ,
 1749                     buf, 5, avgval, nsecs);
 1750 
 1751         return buf;
 1752 }
 1753 
 1754 char *
 1755 procprt_RNET_e(struct tstat *curstat, int avgval, int nsecs)
 1756 {
 1757     if (supportflags & NETATOPD)
 1758     {
 1759             static char buf[10];
 1760  
 1761             val2valstr(curstat->net.tcprcv + curstat->net.udprcv ,
 1762                     buf, 5, avgval, nsecs);
 1763 
 1764             return buf;
 1765     }
 1766     else
 1767             return "    -";
 1768 }
 1769 
 1770 proc_printdef procprt_RNET = 
 1771    { " RNET", "RNET", procprt_RNET_a, procprt_RNET_e, 5 };
 1772 /***************************************************************/
 1773 char *
 1774 procprt_SNET_a(struct tstat *curstat, int avgval, int nsecs)
 1775 {
 1776         static char buf[10];
 1777         
 1778         val2valstr(curstat->net.tcpsnd + curstat->net.udpsnd,
 1779                                 buf, 5, avgval, nsecs);
 1780         return buf;
 1781 }
 1782 
 1783 char *
 1784 procprt_SNET_e(struct tstat *curstat, int avgval, int nsecs)
 1785 {
 1786     if (supportflags & NETATOPD)
 1787     {
 1788             static char buf[10];
 1789         
 1790             val2valstr(curstat->net.tcpsnd + curstat->net.udpsnd,
 1791                                 buf, 5, avgval, nsecs);
 1792             return buf;
 1793     }
 1794     else
 1795             return "    -";
 1796 }
 1797 
 1798 proc_printdef procprt_SNET = 
 1799    { " SNET", "SNET", procprt_SNET_a, procprt_SNET_e, 5 };
 1800 /***************************************************************/
 1801 char *
 1802 procprt_BANDWI_a(struct tstat *curstat, int avgval, int nsecs)
 1803 {
 1804         static char buf[16];
 1805     count_t     rkbps = (curstat->net.tcprsz+curstat->net.udprsz)/125/nsecs;
 1806 
 1807     format_bandw(buf, rkbps);
 1808         return buf;
 1809 }
 1810 
 1811 char *
 1812 procprt_BANDWI_e(struct tstat *curstat, int avgval, int nsecs)
 1813 {
 1814     if (supportflags & NETATOPD)
 1815     {
 1816             static char buf[16];
 1817         count_t     rkbps = (curstat->net.tcprsz + curstat->net.udprsz)
 1818                                 /125/nsecs;
 1819 
 1820         format_bandw(buf, rkbps);
 1821             return buf;
 1822     }
 1823     else
 1824             return "        -";
 1825 }
 1826 
 1827 proc_printdef procprt_BANDWI = 
 1828    { "   BANDWI", "BANDWI", procprt_BANDWI_a, procprt_BANDWI_e, 9};
 1829 /***************************************************************/
 1830 char *
 1831 procprt_BANDWO_a(struct tstat *curstat, int avgval, int nsecs)
 1832 {
 1833         static char buf[16];
 1834     count_t     skbps = (curstat->net.tcpssz+curstat->net.udpssz)/125/nsecs;
 1835 
 1836     format_bandw(buf, skbps);
 1837         return buf;
 1838 }
 1839 
 1840 char *
 1841 procprt_BANDWO_e(struct tstat *curstat, int avgval, int nsecs)
 1842 {
 1843     if (supportflags & NETATOPD)
 1844     {
 1845             static char buf[16];
 1846         count_t     skbps = (curstat->net.tcpssz + curstat->net.udpssz)
 1847                                 /125/nsecs;
 1848 
 1849         format_bandw(buf, skbps);
 1850             return buf;
 1851     }
 1852     else
 1853             return "        -";
 1854 }
 1855 
 1856 proc_printdef procprt_BANDWO = 
 1857    { "   BANDWO", "BANDWO", procprt_BANDWO_a, procprt_BANDWO_e, 9};
 1858 /***************************************************************/
 1859 static void
 1860 format_bandw(char *buf, count_t kbps)
 1861 {
 1862     char        c;
 1863 
 1864     if (kbps < 10000)
 1865     {
 1866                 c='K';
 1867         }
 1868         else if (kbps < (count_t)10000 * 1000)
 1869         {
 1870                 kbps/=1000;
 1871                 c = 'M';
 1872         }
 1873         else if (kbps < (count_t)10000 * 1000 * 1000)
 1874         {
 1875                 kbps/=1000 * 1000;
 1876                 c = 'G';
 1877         }
 1878         else
 1879         {
 1880                 kbps = kbps / 1000 / 1000 / 1000;
 1881                 c = 'T';
 1882         }
 1883 
 1884         sprintf(buf, "%4lld %cbps", kbps%100000, c);
 1885 }
 1886 /***************************************************************/
 1887 char *
 1888 procprt_GPULIST_ae(struct tstat *curstat, int avgval, int nsecs)
 1889 {
 1890         static char buf[64];
 1891         char        tmp[64], *p=tmp;
 1892     int     i;
 1893 
 1894     if (!curstat->gpu.state)
 1895         return "       -";
 1896 
 1897     if (!curstat->gpu.gpulist)
 1898         return "       -";
 1899 
 1900     for (i=0; i < nrgpus; i++)
 1901     {
 1902         if (curstat->gpu.gpulist & 1<<i)
 1903         {
 1904             if (tmp == p)   // first?
 1905                 p += snprintf(p, sizeof tmp, "%d", i);
 1906             else
 1907                 p += snprintf(p, sizeof tmp - (p-tmp), ",%d", i);
 1908 
 1909             if (p - tmp > 8)
 1910             {
 1911                 snprintf(tmp, sizeof tmp, "0x%06x",
 1912                         curstat->gpu.gpulist);
 1913                 break;
 1914             }
 1915         }
 1916     }
 1917 
 1918     snprintf(buf, sizeof buf, "%8.8s", tmp);
 1919         return buf;
 1920 }
 1921 
 1922 proc_printdef procprt_GPULIST = 
 1923    { " GPUNUMS", "GPULIST", procprt_GPULIST_ae, procprt_GPULIST_ae, 8};
 1924 /***************************************************************/
 1925 char *
 1926 procprt_GPUMEMNOW_ae(struct tstat *curstat, int avgval, int nsecs)
 1927 {
 1928         static char buf[10];
 1929 
 1930     if (!curstat->gpu.state)
 1931         return "     -";
 1932 
 1933         val2memstr(curstat->gpu.memnow*1024, buf, BFORMAT, 0, 0);
 1934         return buf;
 1935 }
 1936 
 1937 proc_printdef procprt_GPUMEMNOW = 
 1938    { "MEMNOW", "GPUMEM", procprt_GPUMEMNOW_ae, procprt_GPUMEMNOW_ae, 6};
 1939 /***************************************************************/
 1940 char *
 1941 procprt_GPUMEMAVG_ae(struct tstat *curstat, int avgval, int nsecs)
 1942 {
 1943         static char buf[10];
 1944 
 1945     if (!curstat->gpu.state)
 1946         return "     -";
 1947 
 1948     if (curstat->gpu.sample == 0)
 1949         return("    0K");
 1950 
 1951         val2memstr(curstat->gpu.nrgpus * curstat->gpu.memcum /
 1952                curstat->gpu.sample*1024, buf, BFORMAT, 0, 0);
 1953         return buf;
 1954 }
 1955 
 1956 proc_printdef procprt_GPUMEMAVG = 
 1957    { "MEMAVG", "GPUMEMAVG", procprt_GPUMEMAVG_ae, procprt_GPUMEMAVG_ae, 6};
 1958 /***************************************************************/
 1959 char *
 1960 procprt_GPUGPUBUSY_ae(struct tstat *curstat, int avgval, int nsecs)
 1961 {
 1962         static char     buf[16];
 1963 
 1964     if (!curstat->gpu.state)
 1965         return "      -";
 1966 
 1967     if (curstat->gpu.gpubusy == -1)
 1968         return "    N/A";
 1969 
 1970         snprintf(buf, sizeof buf, "%6d%%", curstat->gpu.gpubusy);
 1971         return buf;
 1972 }
 1973 
 1974 proc_printdef procprt_GPUGPUBUSY = 
 1975    { "GPUBUSY", "GPUGPUBUSY", procprt_GPUGPUBUSY_ae, procprt_GPUGPUBUSY_ae, 7};
 1976 /***************************************************************/
 1977 char *
 1978 procprt_GPUMEMBUSY_ae(struct tstat *curstat, int avgval, int nsecs)
 1979 {
 1980         static char     buf[16];
 1981 
 1982     if (!curstat->gpu.state)
 1983         return "      -";
 1984 
 1985     if (curstat->gpu.membusy == -1)
 1986         return "    N/A";
 1987 
 1988         snprintf(buf, sizeof buf, "%6d%%", curstat->gpu.membusy);
 1989         return buf;
 1990 }
 1991 
 1992 proc_printdef procprt_GPUMEMBUSY = 
 1993    { "MEMBUSY", "GPUMEMBUSY", procprt_GPUMEMBUSY_ae, procprt_GPUMEMBUSY_ae, 7};
 1994 /***************************************************************/
 1995 char *
 1996 procprt_WCHAN_a(struct tstat *curstat, int avgval, int nsecs)
 1997 {
 1998         static char buf[32];
 1999 
 2000         if (curstat->gen.state != 'R')
 2001         snprintf(buf, sizeof buf, "%-15.15s", curstat->cpu.wchan);
 2002     else
 2003         snprintf(buf, sizeof buf, "%-15.15s", " ");
 2004 
 2005         return buf;
 2006 }
 2007 
 2008 char *
 2009 procprt_WCHAN_e(struct tstat *curstat, int avgval, int nsecs)
 2010 {
 2011         static char buf[32];
 2012 
 2013     snprintf(buf, sizeof buf, "%-15.15s", " ");
 2014         return buf;
 2015 }
 2016 
 2017 proc_printdef procprt_WCHAN =
 2018    { "WCHAN          ", "WCHAN", procprt_WCHAN_a, procprt_WCHAN_e, 15};
 2019 /***************************************************************/
 2020 char *
 2021 procprt_RUNDELAY_a(struct tstat *curstat, int avgval, int nsecs)
 2022 {
 2023         static char buf[10];
 2024 
 2025         val2cpustr(curstat->cpu.rundelay/1000000, buf);
 2026         return buf;
 2027 }
 2028 
 2029 char *
 2030 procprt_RUNDELAY_e(struct tstat *curstat, int avgval, int nsecs)
 2031 {
 2032         static char buf[10];
 2033 
 2034         snprintf(buf, sizeof buf, "     -");
 2035         return buf;
 2036 }
 2037 
 2038 proc_printdef procprt_RUNDELAY =
 2039    { "RDELAY", "RDELAY", procprt_RUNDELAY_a, procprt_RUNDELAY_e, 6};
 2040 /***************************************************************/
 2041 char *
 2042 procprt_BLKDELAY_a(struct tstat *curstat, int avgval, int nsecs)
 2043 {
 2044         static char buf[10];
 2045 
 2046         val2cpustr(curstat->cpu.blkdelay*1000/hertz, buf);
 2047         return buf;
 2048 }
 2049 
 2050 char *
 2051 procprt_BLKDELAY_e(struct tstat *curstat, int avgval, int nsecs)
 2052 {
 2053         static char buf[10];
 2054 
 2055         snprintf(buf, sizeof buf, "     -");
 2056         return buf;
 2057 }
 2058 
 2059 proc_printdef procprt_BLKDELAY =
 2060    { "BDELAY", "BDELAY", procprt_BLKDELAY_a, procprt_BLKDELAY_e, 6};
 2061 /***************************************************************/
 2062 char *
 2063 procprt_CGROUP_PATH_a(struct tstat *curstat, int avgval, int nsecs)
 2064 {
 2065         extern proc_printdef procprt_CGROUP_PATH;
 2066         extern int  startoffset;    // influenced by -> and <- keys
 2067         static char buf[CMDLEN+1];
 2068 
 2069     char    *pline     = curstat->gen.cgpath[0] ? curstat->gen.cgpath:"?";
 2070 
 2071         int     curwidth   = procprt_CGROUP_PATH.width <= CGRLEN ?
 2072                 procprt_CGROUP_PATH.width : CGRLEN;
 2073 
 2074         int     pathlen    = strlen(pline);
 2075         int     curoffset  = startoffset <= pathlen ? startoffset : pathlen;
 2076 
 2077     if (! curstat->gen.isproc)
 2078         return "";
 2079 
 2080         if (screen) 
 2081                 sprintf(buf, "%-*.*s", curwidth, curwidth, pline+curoffset);
 2082         else
 2083                 sprintf(buf, "%.*s", CGRLEN, pline+curoffset);
 2084 
 2085         return buf;
 2086 }
 2087 
 2088 char *
 2089 procprt_CGROUP_PATH_e(struct tstat *curstat, int avgval, int nsecs)
 2090 {
 2091     return "-";
 2092 }
 2093 
 2094 proc_printdef procprt_CGROUP_PATH = 
 2095        {"CGROUP (horizontal scroll: <- and ->)",
 2096     "CGROUP-PATH", 
 2097         procprt_CGROUP_PATH_a, procprt_CGROUP_PATH_e, 42, 0 };
 2098 /***************************************************************/
 2099 char *
 2100 procprt_CGRCPUWGT_a(struct tstat *curstat, int avgval, int nsecs)
 2101 {
 2102         static char buf[16];
 2103 
 2104     if (! curstat->gen.isproc)
 2105         return "      ";
 2106 
 2107     if (curstat->gen.cgpath[0])
 2108     {
 2109         switch (curstat->cpu.cgcpuweight)
 2110         {
 2111            case -2:
 2112                 return "     -";
 2113            default:
 2114             snprintf(buf, sizeof buf, "%6d", curstat->cpu.cgcpuweight);
 2115                 return buf;
 2116         }
 2117     }
 2118     else
 2119             return "     -";
 2120 }
 2121 
 2122 char *
 2123 procprt_CGRCPUWGT_e(struct tstat *curstat, int avgval, int nsecs)
 2124 {
 2125         return "     -";
 2126 }
 2127 
 2128 proc_printdef procprt_CGRCPUWGT =
 2129    { "CPUWGT", "CPUWGT", procprt_CGRCPUWGT_a, procprt_CGRCPUWGT_e, 6};
 2130 /***************************************************************/
 2131 char *
 2132 procprt_CGRCPUMAX_a(struct tstat *curstat, int avgval, int nsecs)
 2133 {
 2134         static char buf[16];
 2135 
 2136     if (! curstat->gen.isproc)
 2137         return "      ";
 2138 
 2139     if (curstat->gen.cgpath[0])
 2140     {
 2141         switch (curstat->cpu.cgcpumax)
 2142         {
 2143            case -1:
 2144                 return "   max";
 2145            case -2:
 2146                 return "     -";
 2147            default:
 2148             snprintf(buf, sizeof buf, "%5d%%", curstat->cpu.cgcpumax);
 2149                 return buf;
 2150         }
 2151     }
 2152     else
 2153             return "     -";
 2154 }
 2155 
 2156 char *
 2157 procprt_CGRCPUMAX_e(struct tstat *curstat, int avgval, int nsecs)
 2158 {
 2159         return "     -";
 2160 }
 2161 
 2162 proc_printdef procprt_CGRCPUMAX =
 2163    { "CPUMAX", "CPUMAX", procprt_CGRCPUMAX_a, procprt_CGRCPUMAX_e, 6};
 2164 /***************************************************************/
 2165 char *
 2166 procprt_CGRCPUMAXR_a(struct tstat *curstat, int avgval, int nsecs)
 2167 {
 2168         static char buf[16];
 2169 
 2170     if (! curstat->gen.isproc)
 2171         return "       ";
 2172 
 2173     if (curstat->gen.cgpath[0])
 2174     {
 2175         switch (curstat->cpu.cgcpumaxr)
 2176         {
 2177            case -1:
 2178                 return "    max";
 2179            case -2:
 2180                 return "      -";
 2181            default:
 2182             snprintf(buf, sizeof buf, "%6d%%", curstat->cpu.cgcpumaxr);
 2183                 return buf;
 2184         }
 2185     }
 2186     else
 2187             return "      -";
 2188 }
 2189 
 2190 char *
 2191 procprt_CGRCPUMAXR_e(struct tstat *curstat, int avgval, int nsecs)
 2192 {
 2193         return "      -";
 2194 }
 2195 
 2196 proc_printdef procprt_CGRCPUMAXR =
 2197    { "CPUMAXR", "CPUMAXR", procprt_CGRCPUMAXR_a, procprt_CGRCPUMAXR_e, 7};
 2198 /***************************************************************/
 2199 char *
 2200 procprt_CGRMEMMAX_a(struct tstat *curstat, int avgval, int nsecs)
 2201 {
 2202         static char buf[16];
 2203 
 2204     if (! curstat->gen.isproc)
 2205         return "      ";
 2206 
 2207     if (curstat->gen.cgpath[0])
 2208     {
 2209         switch (curstat->mem.cgmemmax)
 2210         {
 2211            case -1:
 2212                 return "   max";
 2213            case -2:
 2214                 return "     -";
 2215            default:
 2216                 val2memstr(curstat->mem.cgmemmax*1024, buf, BFORMAT, 0, 0);
 2217                 return buf;
 2218         }
 2219     }
 2220     else
 2221             return "     -";
 2222 }
 2223 
 2224 char *
 2225 procprt_CGRMEMMAX_e(struct tstat *curstat, int avgval, int nsecs)
 2226 {
 2227         return "     -";
 2228 }
 2229 
 2230 proc_printdef procprt_CGRMEMMAX =
 2231    { "MEMMAX", "MEMMAX", procprt_CGRMEMMAX_a, procprt_CGRMEMMAX_e, 6};
 2232 /***************************************************************/
 2233 char *
 2234 procprt_CGRMEMMAXR_a(struct tstat *curstat, int avgval, int nsecs)
 2235 {
 2236         static char buf[16];
 2237 
 2238     if (! curstat->gen.isproc)
 2239         return "      ";
 2240 
 2241     if (curstat->gen.cgpath[0])
 2242     {
 2243         switch (curstat->mem.cgmemmaxr)
 2244         {
 2245            case -1:
 2246                 return "   max";
 2247            case -2:
 2248                 return "     -";
 2249            default:
 2250                 val2memstr(curstat->mem.cgmemmaxr*1024, buf, BFORMAT, 0, 0);
 2251                 return buf;
 2252         }
 2253     }
 2254     else
 2255             return "     -";
 2256 }
 2257 
 2258 char *
 2259 procprt_CGRMEMMAXR_e(struct tstat *curstat, int avgval, int nsecs)
 2260 {
 2261         return "     -";
 2262 }
 2263 
 2264 proc_printdef procprt_CGRMEMMAXR =
 2265    { "MMMAXR", "MMMAXR", procprt_CGRMEMMAXR_a, procprt_CGRMEMMAXR_e, 6};
 2266 /***************************************************************/
 2267 char *
 2268 procprt_CGRSWPMAX_a(struct tstat *curstat, int avgval, int nsecs)
 2269 {
 2270         static char buf[16];
 2271 
 2272     if (! curstat->gen.isproc)
 2273         return "      ";
 2274 
 2275     if (curstat->gen.cgpath[0])
 2276     {
 2277         switch (curstat->mem.cgswpmax)
 2278         {
 2279            case -1:
 2280                 return "   max";
 2281            case -2:
 2282                 return "     -";
 2283            default:
 2284                 val2memstr(curstat->mem.cgswpmax*1024, buf, BFORMAT, 0, 0);
 2285                 return buf;
 2286         }
 2287     }
 2288     else
 2289             return "     -";
 2290 }
 2291 
 2292 char *
 2293 procprt_CGRSWPMAX_e(struct tstat *curstat, int avgval, int nsecs)
 2294 {
 2295         return "     -";
 2296 }
 2297 
 2298 proc_printdef procprt_CGRSWPMAX =
 2299    { "SWPMAX", "SWPMAX", procprt_CGRSWPMAX_a, procprt_CGRSWPMAX_e, 6};
 2300 /***************************************************************/
 2301 char *
 2302 procprt_CGRSWPMAXR_a(struct tstat *curstat, int avgval, int nsecs)
 2303 {
 2304         static char buf[16];
 2305 
 2306     if (! curstat->gen.isproc)
 2307         return "      ";
 2308 
 2309     if (curstat->gen.cgpath[0])
 2310     {
 2311         switch (curstat->mem.cgswpmaxr)
 2312         {
 2313            case -1:
 2314                 return "   max";
 2315            case -2:
 2316                 return "     -";
 2317            default:
 2318                 val2memstr(curstat->mem.cgswpmaxr*1024, buf, BFORMAT, 0, 0);
 2319                 return buf;
 2320         }
 2321     }
 2322     else
 2323             return "     -";
 2324 }
 2325 
 2326 char *
 2327 procprt_CGRSWPMAXR_e(struct tstat *curstat, int avgval, int nsecs)
 2328 {
 2329         return "     -";
 2330 }
 2331 
 2332 proc_printdef procprt_CGRSWPMAXR =
 2333    { "SWMAXR", "SWMAXR", procprt_CGRSWPMAXR_a, procprt_CGRSWPMAXR_e, 6};
 2334 /***************************************************************/
 2335 char *
 2336 procprt_SORTITEM_ae(struct tstat *curstat, int avgval, int nsecs)
 2337 {
 2338         return "";   // dummy function
 2339 }
 2340 
 2341 proc_printdef procprt_SORTITEM =   // width is dynamically defined!
 2342    { 0, "SORTITEM", procprt_SORTITEM_ae, procprt_SORTITEM_ae, 4};