"Fossies" - the Fresh Open Source Software Archive

Member "atop-2.8.1/showsys.c" (7 Jan 2023, 103820 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 "showsys.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 /*******************************************************************/
   56 /*
   57 ** print the label of a system-statistics line and switch on
   58 ** colors if needed 
   59 */
   60 static int
   61 syscolorlabel(char *labeltext, unsigned int badness)
   62 {
   63         if (screen)
   64         {
   65                 if (badness >= 100)
   66                 {
   67                         attron (A_BLINK);
   68 
   69                 if (usecolors)
   70             {
   71                             attron(COLOR_PAIR(COLORCRIT));
   72                             printg(labeltext);
   73                             attroff(COLOR_PAIR(COLORCRIT));
   74             }
   75             else
   76             {
   77                             attron(A_BOLD);
   78                             printg(labeltext);
   79                             attroff(A_BOLD);
   80             }
   81 
   82                         attroff(A_BLINK);
   83 
   84                         return COLORCRIT;
   85                 }
   86 
   87                 if (almostcrit && badness >= almostcrit)
   88                 {
   89                 if (usecolors)
   90             {
   91                             attron(COLOR_PAIR(COLORALMOST));
   92                             printg(labeltext);
   93                             attroff(COLOR_PAIR(COLORALMOST));
   94             }
   95             else
   96             {
   97                             attron(A_BOLD);
   98                             printg(labeltext);
   99                             attroff(A_BOLD);
  100             }
  101 
  102                         return COLORALMOST;
  103                 }
  104         }
  105 
  106         /*
  107         ** no colors required or no reason to show colors
  108         */
  109         printg(labeltext);
  110         return 0;
  111 }
  112 
  113 static char *sysprt_BLANKBOX(struct sstat *sstat, extraparam *notused, int, int *);
  114 
  115 void
  116 addblanks(double *charslackused, double *charslackover)
  117 {
  118         *charslackused+=*charslackover;
  119         while (*charslackused>0.5)
  120         {
  121                 printg(" ");
  122                 *charslackused-=1;
  123         }
  124 }
  125 
  126 /*
  127  * showsysline
  128  * print an array of sys_printpair things.  If the screen contains too
  129  * few character columns, lower priority items are removed
  130  *
  131  */
  132 #define MAXELEMS 40
  133 
  134 void
  135 showsysline(sys_printpair* elemptr, 
  136                  struct sstat* sstat, extraparam *extra,
  137                  char *labeltext, unsigned int badness)
  138 {
  139         sys_printdef    *curelem;
  140         int maxw = screen ? COLS : linelen;
  141 
  142         // every 15-char item is printed as:
  143         // >>>> | datadatadata<<<<<
  144         //     012345678901234
  145         
  146         /* how many items will fit on one line? */
  147         int avail = (maxw-5)/15;
  148 
  149         syscolorlabel(labeltext, badness);
  150 
  151         /* count number of items */
  152     sys_printpair newelems[MAXELEMS];
  153     int nitems;
  154 
  155     for (nitems=0; nitems < MAXELEMS-1 && elemptr[nitems].f != 0; ++nitems)
  156         newelems[nitems]=elemptr[nitems];
  157 
  158     newelems[nitems].f=0;
  159 
  160         /* remove lowest priority box to make room as needed */
  161         while (nitems > avail)
  162         {
  163                 int lowestprio=999999;
  164                 int lowestprio_index=-1;
  165                 int i;
  166 
  167                 for (i=0; i<nitems; ++i) 
  168                 {
  169                         if (newelems[i].prio < lowestprio) 
  170                         {
  171                                 lowestprio=newelems[i].prio;
  172                                 lowestprio_index=i;
  173                         }
  174                 }
  175 
  176                 // lowest priority item found, remove from newelems;
  177                 memmove(newelems+lowestprio_index, 
  178                         newelems+lowestprio_index+1, 
  179                         (nitems-lowestprio_index)* sizeof(sys_printpair));   
  180                        // also copies final 0 entry
  181                 nitems--;
  182         }
  183 
  184         /* 
  185          * ``item shortage'' is used to make entire blank boxes
  186          * these boxes are spread out as much as possible
  187          * remaining slack is used to add spaces around the vertical
  188          * bars
  189          */
  190         double slackitemsover;
  191 
  192         if (nitems >1)
  193         {
  194                 slackitemsover=(double)(avail-nitems)/(nitems);
  195         }
  196         else 
  197         {
  198                 slackitemsover=(avail-nitems)/2;
  199         }
  200 
  201         // charslack: the slack in characters after using as many
  202         // items as possible
  203         double charslackover = screen ? ((COLS - 5) % 15) : ((linelen - 5) %15);
  204 
  205         // two places per items where blanks can be added
  206         charslackover /= (avail * 2);    
  207 
  208         double charslackused=0.0;
  209         double itemslackused=0.0;
  210         elemptr=newelems;
  211 
  212         while ((curelem=elemptr->f)!=0) 
  213         {
  214         char    *itemp;
  215         int color;
  216 
  217         /*
  218         ** by default no color is shown for this field (color = 0)
  219         **
  220         ** the format-function can set a color-number (color > 0)
  221         ** when a specific color is wanted or the format-function
  222         ** can leave the decision to display with a color to the piece
  223         ** of code below (color == -1)
  224         */
  225         color = 0;
  226                 itemp = curelem->doformat(sstat, extra, badness, &color);
  227 
  228         if (!itemp)
  229         {
  230             itemp = "           ?";
  231         }
  232 
  233                 printg(" | ");
  234                 addblanks(&charslackused, &charslackover);
  235 
  236         if (screen)
  237         {
  238             if (color == -1) // default color wanted
  239             {
  240                 color = 0;
  241 
  242                 if (badness >= 100)
  243                                     color = COLORCRIT;
  244                 else if (almostcrit && badness >= almostcrit)
  245                     color = COLORALMOST;
  246             }
  247 
  248             if (color)  // after all: has a color been set?
  249             {
  250                 if (usecolors)
  251                                     attron(COLOR_PAIR(color));
  252                             else
  253                                     attron(A_BOLD);
  254             }
  255         }
  256 
  257                 printg("%s", itemp);
  258 
  259         if (color && screen)    // color set for this value?
  260         {
  261             if (usecolors)
  262                                 attroff(COLOR_PAIR(color));
  263                         else
  264                                 attroff(A_BOLD);
  265         }
  266 
  267                 itemslackused+=slackitemsover;
  268                 while (itemslackused>0.5)
  269                 {
  270                         addblanks(&charslackused, &charslackover);
  271                         printg(" | ");
  272                         printg("%s", sysprt_BLANKBOX(0, 0, 0, 0));
  273                         addblanks(&charslackused, &charslackover);
  274                         itemslackused-=1;
  275                 }
  276 
  277                 elemptr++;
  278 
  279                 addblanks(&charslackused, &charslackover);
  280         }
  281 
  282         printg(" |");
  283 
  284         if (!screen) 
  285         {
  286                 printg("\n");
  287         }
  288 }
  289 
  290 
  291 /*******************************************************************/
  292 /* SYSTEM PRINT FUNCTIONS                                          */
  293 /*******************************************************************/
  294 static char *
  295 sysprt_PRCSYS(struct sstat *notused, extraparam *as, int badness, int *color)
  296 {
  297         static char buf[15]="sys   ";
  298         val2cpustr(as->totst * 1000/hertz, buf+6);
  299         return buf;
  300 }
  301 
  302 sys_printdef syspdef_PRCSYS = {"PRCSYS", sysprt_PRCSYS, NULL};
  303 /*******************************************************************/
  304 static char *
  305 sysprt_PRCUSER(struct sstat *notused, extraparam *as, int badness, int *color) 
  306 {
  307         static char buf[15]="user  ";
  308         val2cpustr(as->totut * 1000/hertz, buf+6);
  309         return buf;
  310 }
  311 
  312 sys_printdef syspdef_PRCUSER = {"PRCUSER", sysprt_PRCUSER, NULL};
  313 /*******************************************************************/
  314 static char *
  315 sysprt_PRCNPROC(struct sstat *notused, extraparam *as, int badness, int *color) 
  316 {
  317         static char buf[15]="#proc     ";
  318         val2valstr(as->nproc - as->nexit, buf+6, 6, 0, 0);
  319         return buf;
  320 }
  321 
  322 sys_printdef syspdef_PRCNPROC = {"PRCNPROC", sysprt_PRCNPROC, NULL};
  323 /*******************************************************************/
  324 static char *
  325 sysprt_PRCNRUNNING(struct sstat *notused, extraparam *as, int badness, int *color) 
  326 {
  327         static char buf[15]="#trun     ";
  328         val2valstr(as->ntrun, buf+6, 6, 0, 0);
  329         return buf;
  330 }
  331 
  332 sys_printdef syspdef_PRCNRUNNING = {"PRCNRUNNING", sysprt_PRCNRUNNING, NULL};
  333 /*******************************************************************/
  334 static char *
  335 sysprt_PRCNSLEEPING(struct sstat *notused, extraparam *as, int badness, int *color) 
  336 {
  337         static char buf[15]="#tslpi    ";
  338         val2valstr(as->ntslpi, buf+8, 4, 0, 0);
  339         return buf;
  340 }
  341 
  342 sys_printdef syspdef_PRCNSLEEPING = {"PRCNSLEEPING", sysprt_PRCNSLEEPING, NULL};
  343 /*******************************************************************/
  344 static char *
  345 sysprt_PRCNDSLEEPING(struct sstat *notused, extraparam *as, int badness, int *color) 
  346 {
  347         static char buf[15]="#tslpu    ";
  348         val2valstr(as->ntslpu, buf+8, 4, 0, 0);
  349         return buf;
  350 }
  351 
  352 sys_printdef syspdef_PRCNDSLEEPING = {"PRCNDSLEEPING", sysprt_PRCNDSLEEPING, NULL};
  353 /*******************************************************************/
  354 static char *
  355 sysprt_PRCNZOMBIE(struct sstat *notused, extraparam *as, int badness, int *color) 
  356 {
  357         static char buf[15]="#zombie   ";
  358 
  359     if (as->nzomb > 30)
  360         *color = COLORALMOST;
  361 
  362     if (as->nzomb > 50)
  363         *color = COLORCRIT;
  364 
  365         val2valstr(as->nzomb, buf+8, 4, 0, 0);
  366         return buf;
  367 }
  368 
  369 sys_printdef syspdef_PRCNZOMBIE = {"PRCNZOMBIE", sysprt_PRCNZOMBIE, NULL};
  370 /*******************************************************************/
  371 static char *
  372 sysprt_PRCNNEXIT(struct sstat *notused, extraparam *as, int badness, int *color) 
  373 {
  374     static char firstcall = 1;
  375         static char buf[15]="#exit     ";
  376 
  377         if (supportflags & ACCTACTIVE)
  378         {
  379         if (as->noverflow)
  380         {
  381             *color = COLORCRIT;
  382             buf[6] = '>';
  383             val2valstr(as->nexit, buf+7, 5, as->avgval, as->nsecs);
  384         }
  385         else
  386         {
  387             val2valstr(as->nexit, buf+6, 6, as->avgval, as->nsecs);
  388         }
  389 
  390                 return buf;
  391         }
  392         else
  393         {
  394         if (firstcall)
  395         {
  396             *color = COLORCRIT;
  397             firstcall = 0;
  398         }
  399         else
  400         {
  401             *color = COLORINFO;
  402         }
  403 
  404         switch (acctreason)
  405         {
  406            case 1:
  407                     return "no  procacct";  // "no  acctread";
  408            case 2:
  409                     return "no  procacct";  // "no  acctwant";
  410            case 3:
  411                     return "no  procacct";  // "no  acctsema";
  412            case 4:
  413                     return "no  procacct";  // "no acctmkdir";
  414            case 5:
  415                     return "no  procacct";  // "no rootprivs";
  416            default:
  417                     return "no  procacct";
  418         }
  419         }
  420 }
  421 
  422 sys_printdef syspdef_PRCNNEXIT = {"PRCNNEXIT", sysprt_PRCNNEXIT, NULL};
  423 /*******************************************************************/
  424 static char *
  425 sysprt_CPUSYS(struct sstat *sstat, extraparam *as, int badness, int *color) 
  426 {
  427         static char buf[15];
  428     float perc  = (sstat->cpu.all.stime * 100.0) / as->percputot;
  429 
  430     if (perc > 1.0)
  431         *color = -1;
  432 
  433         sprintf(buf, "sys  %6.0f%%", perc);
  434         return buf;
  435 }
  436 
  437 sys_printdef syspdef_CPUSYS = {"CPUSYS", sysprt_CPUSYS, NULL};
  438 /*******************************************************************/
  439 static char *
  440 sysprt_CPUUSER(struct sstat *sstat, extraparam *as, int badness, int *color) 
  441 {
  442         static char buf[15];
  443     float perc  = (sstat->cpu.all.utime + sstat->cpu.all.ntime)
  444                                         * 100.0 / as->percputot;
  445 
  446     if (perc > 1.0)
  447         *color = -1;
  448 
  449         sprintf(buf, "user %6.0f%%", perc);
  450         return buf;
  451 }
  452 
  453 sys_printdef syspdef_CPUUSER = {"CPUUSER", sysprt_CPUUSER, NULL};
  454 /*******************************************************************/
  455 static char *
  456 sysprt_CPUIRQ(struct sstat *sstat, extraparam *as, int badness, int *color) 
  457 {
  458         static char buf[15];
  459         float perc = (sstat->cpu.all.Itime + sstat->cpu.all.Stime)
  460                                     * 100.0 / as->percputot;
  461 
  462     if (perc > 1.0)
  463         *color = -1;
  464 
  465         sprintf(buf, "irq  %6.0f%%", perc);
  466         return buf;
  467 }
  468 
  469 sys_printdef syspdef_CPUIRQ = {"CPUIRQ", sysprt_CPUIRQ, NULL};
  470 /*******************************************************************/
  471 static char *
  472 sysprt_CPUIDLE(struct sstat *sstat, extraparam *as, int badness, int *color) 
  473 {
  474         static char buf[15];
  475         sprintf(buf, "idle %6.0f%%", 
  476                 (sstat->cpu.all.itime * 100.0) / as->percputot);
  477         return buf;
  478 }
  479 
  480 sys_printdef syspdef_CPUIDLE = {"CPUIDLE", sysprt_CPUIDLE, NULL};
  481 /*******************************************************************/
  482 static char *
  483 sysprt_CPUWAIT(struct sstat *sstat, extraparam *as, int badness, int *color) 
  484 {
  485         static char buf[15];
  486         sprintf(buf, "wait %6.0f%%", 
  487                 (sstat->cpu.all.wtime * 100.0) / as->percputot);
  488         return buf;
  489 }
  490 
  491 sys_printdef syspdef_CPUWAIT = {"CPUWAIT", sysprt_CPUWAIT, NULL};
  492 /*******************************************************************/
  493 static char *
  494 sysprt_CPUISYS(struct sstat *sstat, extraparam *as, int badness, int *color) 
  495 {
  496         static char buf[15];
  497     float perc  = sstat->cpu.cpu[as->index].stime * 100.0
  498                             / as->percputot;
  499 
  500     if (perc > 1.0)
  501         *color = -1;
  502 
  503         sprintf(buf, "sys  %6.0f%%", perc);
  504         return buf;
  505 }
  506 
  507 sys_printdef syspdef_CPUISYS = {"CPUISYS", sysprt_CPUISYS, NULL};
  508 /*******************************************************************/
  509 static char *
  510 sysprt_CPUIUSER(struct sstat *sstat, extraparam *as, int badness, int *color) 
  511 {
  512         static char buf[15];
  513     float perc  = (sstat->cpu.cpu[as->index].utime +
  514                            sstat->cpu.cpu[as->index].ntime) 
  515                * 100.0 / as->percputot;
  516 
  517     if (perc > 1.0)
  518         *color = -1;
  519 
  520         sprintf(buf, "user %6.0f%%", perc);
  521         return buf;
  522 }
  523 
  524 sys_printdef syspdef_CPUIUSER = {"CPUIUSER", sysprt_CPUIUSER, NULL};
  525 /*******************************************************************/
  526 static char *
  527 sysprt_CPUIIRQ(struct sstat *sstat, extraparam *as, int badness, int *color) 
  528 {
  529         static char buf[15];
  530     float perc  = (sstat->cpu.cpu[as->index].Itime +
  531                sstat->cpu.cpu[as->index].Stime)
  532                * 100.0 / as->percputot;
  533 
  534     if (perc > 1.0)
  535         *color = -1;
  536 
  537         sprintf(buf, "irq  %6.0f%%", perc);
  538         return buf;
  539 }
  540 
  541 sys_printdef syspdef_CPUIIRQ = {"CPUIIRQ", sysprt_CPUIIRQ, NULL};
  542 /*******************************************************************/
  543 static char *
  544 sysprt_CPUIIDLE(struct sstat *sstat, extraparam *as, int badness, int *color) 
  545 {
  546         static char buf[15];
  547         sprintf(buf, "idle %6.0f%%", 
  548                 (sstat->cpu.cpu[as->index].itime * 100.0) / as->percputot);
  549         return buf;
  550 }
  551 
  552 sys_printdef syspdef_CPUIIDLE = {"CPUIIDLE", sysprt_CPUIIDLE, NULL};
  553 /*******************************************************************/
  554 static char *
  555 sysprt_CPUIWAIT(struct sstat *sstat, extraparam *as, int badness, int *color) 
  556 {
  557         static char buf[15];
  558         sprintf(buf, "cpu%03d w%3.0f%%", 
  559          sstat->cpu.cpu[as->index].cpunr,
  560                 (sstat->cpu.cpu[as->index].wtime * 100.0) / as->percputot);
  561         return buf;
  562 }
  563 
  564 sys_printdef syspdef_CPUIWAIT = {"CPUIWAIT", sysprt_CPUIWAIT, NULL};
  565 /*******************************************************************/
  566 static char *
  567 dofmt_cpufreq(char *buf, count_t maxfreq, count_t cnt, count_t ticks)
  568 {
  569         // if ticks != 0, do full output
  570         if (ticks) 
  571         {
  572             count_t curfreq = cnt/ticks;
  573             strcpy(buf, "avgf ");
  574             val2Hzstr(curfreq, buf+5);
  575         } 
  576         else if (cnt)       // no max, no %.  if freq is known: print it
  577         {
  578             strcpy(buf, "curf ");
  579             val2Hzstr(cnt, buf+5);
  580         }
  581         else                // nothing is known: suppress
  582         {
  583             buf = NULL;
  584         }
  585 
  586     return buf;
  587 }
  588 
  589 
  590 /*
  591  * sumscaling: sum scaling info for all processors
  592  *
  593  */
  594 void sumscaling(struct sstat *sstat, count_t *maxfreq,
  595                 count_t *cnt, count_t *ticks)
  596 {
  597         count_t mymaxfreq = 0;
  598         count_t mycnt     = 0;
  599         count_t myticks   = 0;
  600 
  601         int n=sstat->cpu.nrcpu;
  602         int i;
  603 
  604         for (i=0; i < n; ++i)
  605         {
  606                 mymaxfreq+= sstat->cpu.cpu[i].freqcnt.maxfreq;
  607                 mycnt    += sstat->cpu.cpu[i].freqcnt.cnt;
  608                 myticks  += sstat->cpu.cpu[i].freqcnt.ticks;
  609         }
  610 
  611         *maxfreq= mymaxfreq;
  612         *cnt    = mycnt;
  613         *ticks  = myticks;
  614 }
  615 
  616 
  617 static char *
  618 dofmt_cpuscale(char *buf, count_t maxfreq, count_t cnt, count_t ticks)
  619 {
  620     if (ticks) 
  621     {
  622         count_t curfreq = cnt/ticks;
  623         int     perc = maxfreq ? 100 * curfreq / maxfreq : 0;
  624 
  625         strcpy(buf, "avgscal ");
  626         sprintf(buf+7, "%4d%%", perc);
  627         } 
  628         else if (maxfreq)   // max frequency is known so % can be calculated
  629         {
  630         strcpy(buf, "curscal ");
  631         sprintf(buf+7, "%4lld%%", 100 * cnt / maxfreq);
  632         }
  633     else    // nothing is known: suppress
  634     {
  635         buf = NULL;
  636     }
  637 
  638     return buf;
  639 }
  640 
  641 /*******************************************************************/
  642 static char *
  643 sysprt_CPUFREQ(struct sstat *sstat, extraparam *as, int badness, int *color) 
  644 {
  645 
  646         static char buf[15];
  647 
  648         count_t maxfreq;
  649         count_t cnt;
  650         count_t ticks;
  651         int     n = sstat->cpu.nrcpu;
  652 
  653         sumscaling(sstat, &maxfreq, &cnt, &ticks);
  654 
  655         return dofmt_cpufreq(buf, maxfreq/n, cnt/n, ticks/n);
  656 }
  657 
  658 static int
  659 sysval_CPUFREQ(struct sstat *sstat)
  660 {
  661         char    buf[15];
  662         count_t maxfreq;
  663         count_t cnt;
  664         count_t ticks;
  665         int     n = sstat->cpu.nrcpu;
  666 
  667         sumscaling(sstat, &maxfreq, &cnt, &ticks);
  668 
  669         if (dofmt_cpufreq(buf, maxfreq/n, cnt/n, ticks/n))
  670                 return 1;
  671         else
  672                 return 0;
  673 }
  674 
  675 sys_printdef syspdef_CPUFREQ = {"CPUFREQ", sysprt_CPUFREQ, sysval_CPUFREQ};
  676 /*******************************************************************/
  677 static char *
  678 sysprt_CPUIFREQ(struct sstat *sstat, extraparam *as, int badness, int *color) 
  679 {
  680 
  681         static char buf[15];
  682 
  683         count_t maxfreq = sstat->cpu.cpu[as->index].freqcnt.maxfreq;
  684         count_t cnt = sstat->cpu.cpu[as->index].freqcnt.cnt;
  685         count_t ticks   = sstat->cpu.cpu[as->index].freqcnt.ticks;
  686 
  687         return dofmt_cpufreq(buf, maxfreq, cnt, ticks);
  688 }
  689 
  690 sys_printdef syspdef_CPUIFREQ = {"CPUIFREQ", sysprt_CPUIFREQ, sysval_CPUFREQ};
  691 /*******************************************************************/
  692 static char *
  693 sysprt_CPUSCALE(struct sstat *sstat, extraparam *as, int badness, int *color) 
  694 {
  695 
  696         static char buf[32] = "scaling    ?";
  697 
  698         count_t maxfreq;
  699         count_t cnt;
  700         count_t ticks;
  701         int     n = sstat->cpu.nrcpu;
  702 
  703         sumscaling(sstat, &maxfreq, &cnt, &ticks);
  704         dofmt_cpuscale(buf, maxfreq/n, cnt/n, ticks/n);
  705     return buf;
  706 }
  707 
  708 static int
  709 sysval_CPUSCALE(struct sstat *sstat)
  710 {
  711         char    buf[32];
  712         count_t maxfreq;
  713         count_t cnt;
  714         count_t ticks;
  715         int     n = sstat->cpu.nrcpu;
  716 
  717         sumscaling(sstat, &maxfreq, &cnt, &ticks);
  718 
  719         if (dofmt_cpuscale(buf, maxfreq/n, cnt/n, ticks/n))
  720         return 1;
  721     else
  722         return 0;
  723 }
  724 
  725 sys_printdef syspdef_CPUSCALE = {"CPUSCALE", sysprt_CPUSCALE, sysval_CPUSCALE};
  726 /*******************************************************************/
  727 static char *
  728 sysprt_CPUISCALE(struct sstat *sstat, extraparam *as, int badness, int *color) 
  729 {
  730 
  731         static char buf[32] = "scaling    ?";
  732 
  733         count_t maxfreq = sstat->cpu.cpu[as->index].freqcnt.maxfreq;
  734         count_t cnt     = sstat->cpu.cpu[as->index].freqcnt.cnt;
  735         count_t ticks   = sstat->cpu.cpu[as->index].freqcnt.ticks;
  736 
  737         dofmt_cpuscale(buf, maxfreq, cnt, ticks);
  738     return buf;
  739 }
  740 
  741 sys_printdef syspdef_CPUISCALE = {"CPUISCALE", sysprt_CPUISCALE, sysval_CPUSCALE};
  742 /*******************************************************************/
  743 static char *
  744 sysprt_CPUSTEAL(struct sstat *sstat, extraparam *as, int badness, int *color) 
  745 {
  746         static char buf[15];
  747     float perc  = sstat->cpu.all.steal * 100.0 / as->percputot;
  748 
  749     if (perc > 1.0)
  750         *color = -1;
  751 
  752         sprintf(buf, "steal %5.0f%%", perc);
  753         return buf;
  754 }
  755 
  756 sys_printdef syspdef_CPUSTEAL = {"CPUSTEAL", sysprt_CPUSTEAL, NULL};
  757 /*******************************************************************/
  758 static char *
  759 sysprt_CPUISTEAL(struct sstat *sstat, extraparam *as, int badness, int *color) 
  760 {
  761         static char buf[15];
  762     float perc  = sstat->cpu.cpu[as->index].steal * 100.0
  763                             / as->percputot;
  764 
  765     if (perc > 1.0)
  766         *color = -1;
  767 
  768         sprintf(buf, "steal %5.0f%%", perc);
  769         return buf;
  770 }
  771 
  772 sys_printdef syspdef_CPUISTEAL = {"CPUISTEAL", sysprt_CPUISTEAL, NULL};
  773 /*******************************************************************/
  774 static char *
  775 sysprt_CPUGUEST(struct sstat *sstat, extraparam *as, int badness, int *color) 
  776 {
  777         static char buf[15];
  778         float perc = sstat->cpu.all.guest * 100.0 / as->percputot;
  779 
  780     if (perc > 1.0)
  781         *color = -1;
  782 
  783         sprintf(buf, "guest %5.0f%%", perc);
  784         return buf;
  785 }
  786 
  787 sys_printdef syspdef_CPUGUEST = {"CPUGUEST", sysprt_CPUGUEST, NULL};
  788 /*******************************************************************/
  789 static char *
  790 sysprt_CPUIGUEST(struct sstat *sstat, extraparam *as, int badness, int *color) 
  791 {
  792         static char buf[15];
  793         float perc = sstat->cpu.cpu[as->index].guest * 100.0 / as->percputot;
  794 
  795     if (perc > 1.0)
  796         *color = -1;
  797 
  798         sprintf(buf, "guest %5.0f%%", perc);
  799         return buf;
  800 }
  801 
  802 sys_printdef syspdef_CPUIGUEST = {"CPUIGUEST", sysprt_CPUIGUEST, NULL};
  803 /*******************************************************************/
  804 static char *
  805 sysprt_CPUIPC(struct sstat *sstat, extraparam *as, int badness, int *color) 
  806 {
  807         static char buf[15];
  808         float ipc = 0.0;
  809 
  810     switch (sstat->cpu.all.cycle)
  811     {
  812        case 0:
  813             sprintf(buf, "ipc notavail");
  814         break;
  815 
  816        case 1:
  817         *color = COLORINFO;
  818             sprintf(buf, "ipc  initial");
  819         break;
  820 
  821        default:
  822         ipc = sstat->cpu.all.instr * 100 / sstat->cpu.all.cycle / 100.0;
  823             sprintf(buf, "ipc %8.2f", ipc);
  824     }
  825 
  826         return buf;
  827 }
  828 
  829 static int
  830 sysval_IPCVALIDATE(struct sstat *sstat)
  831 {
  832     return sstat->cpu.all.cycle;
  833 }
  834 
  835 sys_printdef syspdef_CPUIPC = {"CPUIPC", sysprt_CPUIPC, sysval_IPCVALIDATE};
  836 /*******************************************************************/
  837 static char *
  838 sysprt_CPUIIPC(struct sstat *sstat, extraparam *as, int badness, int *color) 
  839 {
  840         static char buf[15];
  841         float ipc = 0.0;
  842 
  843     switch (sstat->cpu.all.cycle)
  844     {
  845        case 0:
  846             sprintf(buf, "ipc notavail");
  847         break;
  848 
  849        case 1:
  850         *color = COLORINFO;
  851             sprintf(buf, "ipc  initial");
  852         break;
  853 
  854        default:
  855         if (sstat->cpu.cpu[as->index].cycle)
  856             ipc = sstat->cpu.cpu[as->index].instr * 100 /
  857                 sstat->cpu.cpu[as->index].cycle / 100.0;
  858 
  859             sprintf(buf, "ipc %8.2f", ipc);
  860     }
  861 
  862         return buf;
  863 }
  864 
  865 sys_printdef syspdef_CPUIIPC = {"CPUIIPC", sysprt_CPUIIPC, sysval_IPCVALIDATE};
  866 /*******************************************************************/
  867 static char *
  868 sysprt_CPUCYCLE(struct sstat *sstat, extraparam *as, int badness, int *color) 
  869 {
  870         static char buf[15] = "cycl ";
  871 
  872     switch (sstat->cpu.all.cycle)
  873     {
  874        case 0:
  875             sprintf(buf+5, "missing");
  876         break;
  877 
  878        case 1:
  879         *color = COLORINFO;
  880             sprintf(buf+5, "initial");
  881         break;
  882 
  883        default:
  884             val2Hzstr(sstat->cpu.all.cycle/1000000/as->nsecs/
  885                         sstat->cpu.nrcpu, buf+5);
  886     }
  887 
  888         return buf;
  889 }
  890 
  891 sys_printdef syspdef_CPUCYCLE = {"CPUCYCLE", sysprt_CPUCYCLE, sysval_IPCVALIDATE};
  892 /*******************************************************************/
  893 static char *
  894 sysprt_CPUICYCLE(struct sstat *sstat, extraparam *as, int badness, int *color) 
  895 {
  896         static char buf[15] = "cycl ";
  897 
  898     switch (sstat->cpu.all.cycle)
  899     {
  900        case 0:
  901             sprintf(buf+5, "missing");
  902         break;
  903 
  904        case 1:
  905         *color = COLORINFO;
  906             sprintf(buf+5, "initial");
  907         break;
  908 
  909        default:
  910             val2Hzstr(sstat->cpu.cpu[as->index].cycle/1000000/
  911                             as->nsecs, buf+5);
  912     }
  913 
  914         return buf;
  915 }
  916 
  917 sys_printdef syspdef_CPUICYCLE = {"CPUICYCLE", sysprt_CPUICYCLE, sysval_IPCVALIDATE};
  918 /*******************************************************************/
  919 static char *
  920 sysprt_CPLAVG1(struct sstat *sstat, extraparam *notused, int badness, int *color) 
  921 {
  922         static char buf[17]="avg1 ";
  923 
  924         if (sstat->cpu.lavg1 > 999999.0)
  925         {
  926                 sprintf(buf+5, ">999999");
  927         }
  928         else if (sstat->cpu.lavg1 > 999.0)
  929         {
  930                 sprintf(buf+5, "%7.0f", sstat->cpu.lavg1);
  931         }
  932         else
  933         {
  934                 sprintf(buf+5, "%7.2f", sstat->cpu.lavg1);
  935         }
  936         return buf;
  937 }
  938         
  939 sys_printdef syspdef_CPLAVG1 = {"CPLAVG1", sysprt_CPLAVG1, NULL};
  940 /*******************************************************************/
  941 static char *
  942 sysprt_CPLAVG5(struct sstat *sstat, extraparam *notused, int badness, int *color) 
  943 {
  944         static char buf[15]="avg5 ";
  945 
  946         if (sstat->cpu.lavg5 > 999999.0)
  947         {
  948                 sprintf(buf+5, ">999999");
  949         }
  950         else if (sstat->cpu.lavg5 > 999.0)
  951         {
  952                 sprintf(buf+5, "%7.0f", sstat->cpu.lavg5);
  953         }
  954         else
  955         {
  956                 sprintf(buf+5, "%7.2f", sstat->cpu.lavg5);
  957         }
  958         return buf;
  959 }
  960         
  961 sys_printdef syspdef_CPLAVG5 = {"CPLAVG5", sysprt_CPLAVG5, NULL};
  962 /*******************************************************************/
  963 static char *
  964 sysprt_CPLAVG15(struct sstat *sstat, extraparam *notused, int badness, int *color) 
  965 {
  966         static char buf[15]="avg15 ";
  967 
  968     if (sstat->cpu.lavg15 > (2 * sstat->cpu.nrcpu) )
  969         *color = COLORALMOST;
  970 
  971         if (sstat->cpu.lavg15 > 99999.0)
  972         {
  973                 sprintf(buf+6, ">99999");
  974         }
  975         else if (sstat->cpu.lavg15 > 999.0)
  976         {
  977                 sprintf(buf+6, "%6.0f", sstat->cpu.lavg15);
  978         }
  979         else
  980         {
  981                 sprintf(buf+6, "%6.2f", sstat->cpu.lavg15);
  982         }
  983         return buf;
  984 }
  985         
  986 sys_printdef syspdef_CPLAVG15 = {"CPLAVG15", sysprt_CPLAVG15, NULL};
  987 /*******************************************************************/
  988 static char *
  989 sysprt_CPLCSW(struct sstat *sstat, extraparam *as, int badness, int *color) 
  990 {
  991         static char buf[16]="csw    ";
  992 
  993         val2valstr(sstat->cpu.csw, buf+4   , 8,as->avgval,as->nsecs);
  994         return buf;
  995 }
  996 
  997 sys_printdef syspdef_CPLCSW = {"CPLCSW", sysprt_CPLCSW, NULL};
  998 /*******************************************************************/
  999 static char *
 1000 sysprt_PRCCLONES(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1001 {
 1002         static char buf[16]="clones ";
 1003 
 1004         val2valstr(sstat->cpu.nprocs, buf+7   , 5,as->avgval,as->nsecs);
 1005         return buf;
 1006 }
 1007 
 1008 sys_printdef syspdef_PRCCLONES = {"PRCCLONES", sysprt_PRCCLONES, NULL};
 1009 /*******************************************************************/
 1010 static char *
 1011 sysprt_CPLNUMCPU(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1012 {
 1013         static char buf[16]="numcpu ";
 1014 
 1015         val2valstr(sstat->cpu.nrcpu, buf+7   , 5,0,as->nsecs);
 1016         return buf;
 1017 }
 1018 
 1019 sys_printdef syspdef_CPLNUMCPU = {"CPLNUMCPU", sysprt_CPLNUMCPU, NULL};
 1020 /*******************************************************************/
 1021 static char *
 1022 sysprt_CPLINTR(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1023 {
 1024         static char buf[16]="intr   ";
 1025 
 1026         val2valstr(sstat->cpu.devint, buf+5   , 7,as->avgval,as->nsecs);
 1027         return buf;
 1028 }
 1029 
 1030 sys_printdef syspdef_CPLINTR = {"CPLINTR", sysprt_CPLINTR, NULL};
 1031 /*******************************************************************/
 1032 static char *
 1033 sysprt_GPUBUS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1034 {
 1035         static char     buf[16];
 1036     char        *pn;
 1037     int     len;
 1038 
 1039         if ( (len = strlen(sstat->gpu.gpu[as->index].busid)) > 9)
 1040         pn = sstat->gpu.gpu[as->index].busid + len - 9;
 1041     else
 1042         pn = sstat->gpu.gpu[as->index].busid;
 1043 
 1044         sprintf(buf, "%9.9s %2d", pn, sstat->gpu.gpu[as->index].gpunr);
 1045         return buf;
 1046 }
 1047 
 1048 sys_printdef syspdef_GPUBUS = {"GPUBUS", sysprt_GPUBUS, NULL};
 1049 /*******************************************************************/
 1050 static char *
 1051 sysprt_GPUTYPE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1052 {
 1053         static char     buf[16];
 1054     char        *pn;
 1055     int     len;
 1056 
 1057         if ( (len = strlen(sstat->gpu.gpu[as->index].type)) > 12)
 1058         pn = sstat->gpu.gpu[as->index].type + len - 12;
 1059     else
 1060         pn = sstat->gpu.gpu[as->index].type;
 1061 
 1062         sprintf(buf, "%12.12s", pn);
 1063         return buf;
 1064 }
 1065 
 1066 sys_printdef syspdef_GPUTYPE = {"GPUTYPE", sysprt_GPUTYPE, NULL};
 1067 /*******************************************************************/
 1068 static char *
 1069 sysprt_GPUNRPROC(struct sstat *sstat, extraparam *as, int badness, int *color)
 1070 {
 1071     static char buf[16] = "#proc    ";
 1072 
 1073     val2valstr(sstat->gpu.gpu[as->index].nrprocs, buf+6, 6, 0, 0);
 1074     return buf;
 1075 }
 1076 
 1077 sys_printdef syspdef_GPUNRPROC = {"GPUNRPROC", sysprt_GPUNRPROC, NULL};
 1078 /*******************************************************************/
 1079 static char *
 1080 sysprt_GPUMEMPERC(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1081 {
 1082         static char buf[16]="membusy   ";
 1083     int perc = sstat->gpu.gpu[as->index].mempercnow;
 1084 
 1085     if (perc == -1)
 1086     {
 1087             sprintf(buf+8, " N/A");
 1088     }
 1089     else
 1090     {
 1091         // preferably take the average percentage over sample
 1092         if (sstat->gpu.gpu[as->index].samples)
 1093             perc = sstat->gpu.gpu[as->index].memperccum /
 1094                    sstat->gpu.gpu[as->index].samples;
 1095 
 1096         if (perc >= 40)
 1097             *color = COLORALMOST;
 1098 
 1099             snprintf(buf+8, sizeof buf-8, "%3d%%", perc);
 1100     }
 1101 
 1102         return buf;
 1103 }
 1104 
 1105 sys_printdef syspdef_GPUMEMPERC = {"GPUMEMPERC", sysprt_GPUMEMPERC, NULL};
 1106 /*******************************************************************/
 1107 static char *
 1108 sysprt_GPUGPUPERC(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1109 {
 1110         static char buf[16]="gpubusy   ";
 1111     int perc = sstat->gpu.gpu[as->index].gpupercnow;
 1112 
 1113     if (perc == -1)     // metric not available?
 1114     {
 1115             sprintf(buf+8, " N/A");
 1116     }
 1117     else
 1118     {
 1119         // preferably take the average percentage over sample
 1120         if (sstat->gpu.gpu[as->index].samples)
 1121             perc = sstat->gpu.gpu[as->index].gpuperccum /
 1122                    sstat->gpu.gpu[as->index].samples;
 1123 
 1124         if (perc >= 90)
 1125             *color = COLORALMOST;
 1126 
 1127             snprintf(buf+8, sizeof buf-8, "%3d%%", perc);
 1128     }
 1129 
 1130         return buf;
 1131 }
 1132 
 1133 sys_printdef syspdef_GPUGPUPERC = {"GPUGPUPERC", sysprt_GPUGPUPERC, NULL};
 1134 /*******************************************************************/
 1135 static char *
 1136 sysprt_GPUMEMOCC(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1137 {
 1138         static char buf[16]="memocc   ";
 1139     int perc;
 1140 
 1141     perc = sstat->gpu.gpu[as->index].memusenow * 100 /
 1142           (sstat->gpu.gpu[as->index].memtotnow ?
 1143            sstat->gpu.gpu[as->index].memtotnow : 1);
 1144 
 1145         snprintf(buf+7, sizeof buf-7, "%4d%%", perc);
 1146 
 1147         return buf;
 1148 }
 1149 
 1150 sys_printdef syspdef_GPUMEMOCC = {"GPUMEMOCC", sysprt_GPUMEMOCC, NULL};
 1151 /*******************************************************************/
 1152 static char *
 1153 sysprt_GPUMEMTOT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1154 {
 1155         static char buf[16] = "total   ";
 1156 
 1157         val2memstr(sstat->gpu.gpu[as->index].memtotnow * 1024, buf+6,
 1158                             MBFORMAT, 0, 0);
 1159         return buf;
 1160 }
 1161 
 1162 sys_printdef syspdef_GPUMEMTOT = {"GPUMEMTOT", sysprt_GPUMEMTOT, NULL};
 1163 /*******************************************************************/
 1164 static char *
 1165 sysprt_GPUMEMUSE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1166 {
 1167         static char buf[16] = "used    ";
 1168 
 1169         val2memstr(sstat->gpu.gpu[as->index].memusenow * 1024,
 1170                 buf+6, MBFORMAT, 0, 0);
 1171         return buf;
 1172 }
 1173 
 1174 sys_printdef syspdef_GPUMEMUSE = {"GPUMEMUSE", sysprt_GPUMEMUSE, NULL};
 1175 /*******************************************************************/
 1176 static char *
 1177 sysprt_GPUMEMAVG(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1178 {
 1179         static char buf[16] = "usavg   ";
 1180 
 1181     if (sstat->gpu.gpu[as->index].samples)
 1182         val2memstr(sstat->gpu.gpu[as->index].memusecum * 1024 /
 1183                    sstat->gpu.gpu[as->index].samples,
 1184                 buf+6, MBFORMAT, 0, 0);
 1185     else
 1186         return "usavg ?";
 1187 
 1188         return buf;
 1189 }
 1190 
 1191 sys_printdef syspdef_GPUMEMAVG = {"GPUMEMAVG", sysprt_GPUMEMAVG, NULL};
 1192 /*******************************************************************/
 1193 static char *
 1194 sysprt_MEMTOT(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1195 {
 1196         static char buf[16]="tot   ";
 1197     *color = -1;
 1198         val2memstr(sstat->mem.physmem * pagesize, buf+6, MBFORMAT, 0, 0);
 1199         return buf;
 1200 }
 1201 
 1202 sys_printdef syspdef_MEMTOT = {"MEMTOT", sysprt_MEMTOT, NULL};
 1203 /*******************************************************************/
 1204 static char *
 1205 sysprt_MEMFREE(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1206 {
 1207         static char buf[16]="free  ";
 1208     *color = -1;
 1209         val2memstr(sstat->mem.freemem   * pagesize, buf+6, MBFORMAT, 0, 0);
 1210         return buf;
 1211 }
 1212 
 1213 sys_printdef syspdef_MEMFREE = {"MEMFREE", sysprt_MEMFREE, NULL};
 1214 /*******************************************************************/
 1215 static char *
 1216 sysprt_MEMCACHE(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1217 {
 1218         static char buf[16]="cache ";
 1219     *color = -1;
 1220         val2memstr(sstat->mem.cachemem   * pagesize, buf+6, MBFORMAT, 0, 0);
 1221         return buf;
 1222 }
 1223 
 1224 sys_printdef syspdef_MEMCACHE = {"MEMCACHE", sysprt_MEMCACHE, NULL};
 1225 /*******************************************************************/
 1226 static char *
 1227 sysprt_MEMDIRTY(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1228 {
 1229         static char buf[16] = "dirty ";
 1230         val2memstr(sstat->mem.cachedrt   * pagesize, buf+6, MBFORMAT, 0, 0);
 1231 
 1232         return buf;
 1233 }
 1234 
 1235 sys_printdef syspdef_MEMDIRTY = {"MEMDIRTY", sysprt_MEMDIRTY, NULL};
 1236 /*******************************************************************/
 1237 static char *
 1238 sysprt_MEMBUFFER(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1239 {
 1240         static char buf[16]="buff  ";
 1241     *color = -1;
 1242         val2memstr(sstat->mem.buffermem   * pagesize, buf+6, MBFORMAT, 0, 0);
 1243         return buf;
 1244 }
 1245 
 1246 sys_printdef syspdef_MEMBUFFER = {"MEMBUFFER", sysprt_MEMBUFFER, NULL};
 1247 /*******************************************************************/
 1248 static char *
 1249 sysprt_MEMSLAB(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1250 {
 1251         static char buf[16]="slab  ";
 1252     *color = -1;
 1253         val2memstr(sstat->mem.slabmem   * pagesize, buf+6, MBFORMAT, 0, 0);
 1254         return buf;
 1255 }
 1256 
 1257 sys_printdef syspdef_MEMSLAB = {"MEMSLAB", sysprt_MEMSLAB, NULL};
 1258 /*******************************************************************/
 1259 static char *
 1260 sysprt_RECSLAB(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1261 {
 1262         static char buf[16]="slrec ";
 1263     *color = -1;
 1264         val2memstr(sstat->mem.slabreclaim * pagesize, buf+6, MBFORMAT, 0, 0);
 1265         return buf;
 1266 }
 1267 
 1268 sys_printdef syspdef_RECSLAB = {"RECSLAB", sysprt_RECSLAB, NULL};
 1269 /*******************************************************************/
 1270 static char *
 1271 sysprt_PAGETABS(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1272 {
 1273         static char buf[16]="pgtab    ";
 1274     *color = -1;
 1275         val2memstr(sstat->mem.pagetables * pagesize, buf+6, MBFORMAT, 0, 0);
 1276         return buf;
 1277 }
 1278 
 1279 sys_printdef syspdef_PAGETABS = {"PAGETABS", sysprt_PAGETABS, NULL};
 1280 /*******************************************************************/
 1281 static char *
 1282 sysprt_SHMEM(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1283 {
 1284         static char buf[16]="shmem  ";
 1285     *color = -1;
 1286         val2memstr(sstat->mem.shmem * pagesize, buf+6, MBFORMAT, 0, 0);
 1287         return buf;
 1288 }
 1289 
 1290 sys_printdef syspdef_SHMEM = {"SHMEM", sysprt_SHMEM, NULL};
 1291 /*******************************************************************/
 1292 static char *
 1293 sysprt_SHMRSS(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1294 {
 1295         static char buf[16]="shrss  ";
 1296     *color = -1;
 1297         val2memstr(sstat->mem.shmrss * pagesize, buf+6, MBFORMAT, 0, 0);
 1298         return buf;
 1299 }
 1300 
 1301 sys_printdef syspdef_SHMRSS = {"SHMRSS", sysprt_SHMRSS, NULL};
 1302 /*******************************************************************/
 1303 static char *
 1304 sysprt_SHMSWP(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1305 {
 1306         static char buf[16]="shswp  ";
 1307     *color = -1;
 1308         val2memstr(sstat->mem.shmswp * pagesize, buf+6, MBFORMAT, 0, 0);
 1309         return buf;
 1310 }
 1311 
 1312 sys_printdef syspdef_SHMSWP = {"SHMSWP", sysprt_SHMSWP, NULL};
 1313 /*******************************************************************/
 1314 static char *
 1315 sysprt_HUPTOT(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1316 {
 1317         static char buf[16]="hptot  ";
 1318 
 1319     *color = -1;
 1320         val2memstr(sstat->mem.tothugepage * sstat->mem.hugepagesz,
 1321                         buf+6, MBFORMAT, 0, 0);
 1322         return buf;
 1323 }
 1324 
 1325 static int
 1326 sysval_HUPTOT(struct sstat *sstat)
 1327 {
 1328     return sstat->mem.tothugepage;
 1329 }
 1330 
 1331 sys_printdef syspdef_HUPTOT = {"HUPTOT", sysprt_HUPTOT, sysval_HUPTOT};
 1332 /*******************************************************************/
 1333 static char *
 1334 sysprt_HUPUSE(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1335 {
 1336         static char buf[16]="hpuse  ";
 1337 
 1338     *color = -1;
 1339         val2memstr( (sstat->mem.tothugepage - sstat->mem.freehugepage) *
 1340                 sstat->mem.hugepagesz, buf+6, MBFORMAT, 0, 0);
 1341         return buf;
 1342 }
 1343 
 1344 static int
 1345 sysval_HUPUSE(struct sstat *sstat)
 1346 {
 1347     return sstat->mem.tothugepage;
 1348 }
 1349 
 1350 sys_printdef syspdef_HUPUSE = {"HUPUSE", sysprt_HUPUSE, sysval_HUPUSE};
 1351 /*******************************************************************/
 1352 static char *
 1353 sysprt_VMWBAL(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1354 {
 1355         static char buf[16]="vmbal  ";
 1356 
 1357     *color = -1;
 1358         val2memstr(sstat->mem.vmwballoon * pagesize, buf+6, MBFORMAT, 0, 0);
 1359         return buf;
 1360 }
 1361 
 1362 static int
 1363 sysval_VMWBAL(struct sstat *sstat)
 1364 {
 1365     if (sstat->mem.vmwballoon == -1)
 1366         return 0;
 1367     else
 1368         return 1;
 1369 }
 1370 
 1371 sys_printdef syspdef_VMWBAL = {"VMWBAL", sysprt_VMWBAL, sysval_VMWBAL};
 1372 /*******************************************************************/
 1373 static char *
 1374 sysprt_ZFSARC(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1375 {
 1376         static char buf[16]="zfarc  ";
 1377 
 1378     if (sstat->mem.zfsarcsize == -1)
 1379     {
 1380             val2memstr(0, buf+6, MBFORMAT, 0, 0);
 1381     }
 1382     else
 1383     {
 1384         *color = -1;
 1385             val2memstr(sstat->mem.zfsarcsize * pagesize, buf+6,
 1386                             MBFORMAT, 0, 0);
 1387     }
 1388 
 1389         return buf;
 1390 }
 1391 
 1392 static int
 1393 sysval_ZFSARC(struct sstat *sstat)
 1394 {
 1395     if (sstat->mem.zfsarcsize == -1)
 1396         return 0;
 1397     else
 1398         return 1;
 1399 }
 1400 
 1401 sys_printdef syspdef_ZFSARC = {"ZFSARC", sysprt_ZFSARC, sysval_ZFSARC};
 1402 /*******************************************************************/
 1403 static char *
 1404 sysprt_SWPTOT(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1405 {
 1406         static char buf[16]="tot    ";
 1407     *color = -1;
 1408         val2memstr(sstat->mem.totswap   * pagesize, buf+6, MBFORMAT, 0, 0);
 1409         return buf;
 1410 }
 1411 
 1412 sys_printdef syspdef_SWPTOT = {"SWPTOT", sysprt_SWPTOT, NULL};
 1413 /*******************************************************************/
 1414 static char *
 1415 sysprt_SWPFREE(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1416 {
 1417         static char buf[16]="free  ";
 1418     *color = -1;
 1419         val2memstr(sstat->mem.freeswap   * pagesize, buf+6, MBFORMAT, 0, 0);
 1420         return buf;
 1421 }
 1422 
 1423 sys_printdef syspdef_SWPFREE = {"SWPFREE", sysprt_SWPFREE, NULL};
 1424 /*******************************************************************/
 1425 static char *
 1426 sysprt_SWPCACHE(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1427 {
 1428         static char buf[16]="swcac ";
 1429     *color = -1;
 1430         val2memstr(sstat->mem.swapcached * pagesize, buf+6, MBFORMAT, 0, 0);
 1431         return buf;
 1432 }
 1433 
 1434 sys_printdef syspdef_SWPCACHE = {"SWPCACHE", sysprt_SWPCACHE, NULL};
 1435 /*******************************************************************/
 1436 static char *
 1437 sysprt_ZSWTOTAL(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1438 {
 1439         static char buf[16]="zpool ";
 1440 
 1441     *color = -1;
 1442         val2memstr(sstat->mem.zswtotpool * pagesize, buf+6, MBFORMAT, 0, 0);
 1443         return buf;
 1444 }
 1445 
 1446 static int
 1447 sysval_ZSWTOTAL(struct sstat *sstat)
 1448 {
 1449     if (sstat->mem.zswtotpool == -1)
 1450         return 0;
 1451     else
 1452         return 1;
 1453 }
 1454 
 1455 sys_printdef syspdef_ZSWTOTAL = {"ZSWTOTAL", sysprt_ZSWTOTAL, sysval_ZSWTOTAL};
 1456 /*******************************************************************/
 1457 static char *
 1458 sysprt_ZSWSTORED(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1459 {
 1460         static char buf[16]="zstor ";
 1461 
 1462     if (sstat->mem.zswstored == -1)
 1463     {
 1464             val2memstr(0, buf+6, MBFORMAT, 0, 0);
 1465     }
 1466     else
 1467     {
 1468         *color = -1;
 1469             val2memstr(sstat->mem.zswstored * pagesize, buf+6, MBFORMAT, 0, 0);
 1470     }
 1471 
 1472         return buf;
 1473 }
 1474 
 1475 static int
 1476 sysval_ZSWSTORED(struct sstat *sstat)
 1477 {
 1478     if (sstat->mem.zswstored == -1)
 1479         return 0;
 1480     else
 1481         return 1;
 1482 }
 1483 
 1484 sys_printdef syspdef_ZSWSTORED = {"ZSWSTORED", sysprt_ZSWSTORED, sysval_ZSWSTORED};
 1485 /*******************************************************************/
 1486 static char *
 1487 sysprt_TCPSOCK(struct sstat *sstat, extraparam *as, int badness, int *color)
 1488 {
 1489         static char buf[16]="tcpsk ";
 1490         val2memstr(sstat->mem.tcpsock * pagesize, buf+6, MBFORMAT, 0, 0);
 1491         return buf;
 1492 }
 1493 
 1494 sys_printdef syspdef_TCPSOCK = {"TCPSOCK", sysprt_TCPSOCK, NULL};
 1495 /*******************************************************************/
 1496 static char *
 1497 sysprt_UDPSOCK(struct sstat *sstat, extraparam *as, int badness, int *color)
 1498 {
 1499         static char buf[16]="udpsk ";
 1500         val2memstr(sstat->mem.udpsock * pagesize, buf+6, MBFORMAT, 0, 0);
 1501         return buf;
 1502 }
 1503 
 1504 sys_printdef syspdef_UDPSOCK = {"UDPSOCK", sysprt_UDPSOCK, NULL};
 1505 /*******************************************************************/
 1506 static char *
 1507 sysprt_KSMSHARING(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1508 {
 1509         static char buf[16]="kssav ";
 1510 
 1511     if (sstat->mem.ksmsharing == -1)
 1512     {
 1513             val2memstr(0, buf+6, MBFORMAT, 0, 0);
 1514     }
 1515     else
 1516     {
 1517         *color = -1;
 1518             val2memstr(sstat->mem.ksmsharing * pagesize, buf+6, MBFORMAT, 0, 0);
 1519     }
 1520 
 1521         return buf;
 1522 }
 1523 
 1524 static int
 1525 sysval_KSMSHARING(struct sstat *sstat)
 1526 {
 1527     if (sstat->mem.ksmsharing == -1)
 1528         return 0;
 1529     else
 1530         return 1;
 1531 }
 1532 
 1533 sys_printdef syspdef_KSMSHARING = {"KSMSHARING", sysprt_KSMSHARING, sysval_KSMSHARING};
 1534 /*******************************************************************/
 1535 static char *
 1536 sysprt_KSMSHARED(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1537 {
 1538         static char buf[16]="ksuse ";
 1539 
 1540     if (sstat->mem.ksmshared == -1)
 1541     {
 1542             val2memstr(0, buf+6, MBFORMAT, 0, 0);
 1543     }
 1544     else
 1545     {
 1546         *color = -1;
 1547             val2memstr(sstat->mem.ksmshared * pagesize, buf+6, MBFORMAT, 0, 0);
 1548     }
 1549 
 1550         return buf;
 1551 }
 1552 
 1553 static int
 1554 sysval_KSMSHARED(struct sstat *sstat)
 1555 {
 1556     if (sstat->mem.ksmshared == -1)
 1557         return 0;
 1558     else
 1559         return 1;
 1560 }
 1561 
 1562 sys_printdef syspdef_KSMSHARED = {"KSMSHARED", sysprt_KSMSHARED, sysval_KSMSHARED};
 1563 /*******************************************************************/
 1564 static char *
 1565 sysprt_NUMNUMA(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1566 {
 1567         static char buf[16]="numnode  ";
 1568         val2valstr(sstat->memnuma.nrnuma, buf+8, 4, 0, 0);
 1569         return buf;
 1570 }
 1571 
 1572 sys_printdef syspdef_NUMNUMA = {"NUMNUMA", sysprt_NUMNUMA, NULL};
 1573 /*******************************************************************/
 1574 static char *
 1575 sysprt_SWPCOMMITTED(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1576 {
 1577         static char buf[16]="vmcom  ";
 1578         val2memstr(sstat->mem.committed   * pagesize, buf+6, MBFORMAT, 0, 0);
 1579 
 1580     if (sstat->mem.commitlim && sstat->mem.committed > sstat->mem.commitlim)
 1581         *color = COLORALMOST;
 1582 
 1583         return buf;
 1584 }
 1585 
 1586 sys_printdef syspdef_SWPCOMMITTED = {"SWPCOMMITTED", sysprt_SWPCOMMITTED, NULL};
 1587 /*******************************************************************/
 1588 static char *
 1589 sysprt_SWPCOMMITLIM(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 1590 {
 1591         static char buf[16]="vmlim  ";
 1592         val2memstr(sstat->mem.commitlim   * pagesize, buf+6, MBFORMAT, 0, 0);
 1593 
 1594     if (sstat->mem.commitlim && sstat->mem.committed > sstat->mem.commitlim)
 1595         *color = COLORINFO;
 1596 
 1597         return buf;
 1598 }
 1599 
 1600 sys_printdef syspdef_SWPCOMMITLIM = {"SWPCOMMITLIM", sysprt_SWPCOMMITLIM, NULL};
 1601 /*******************************************************************/
 1602 static char *
 1603 sysprt_PAGSCAN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1604 {
 1605         static char buf[16]="scan  ";
 1606         val2valstr(sstat->mem.pgscans, buf+5, 7, as->avgval, as->nsecs);
 1607         return buf;
 1608 }
 1609 
 1610 sys_printdef syspdef_PAGSCAN = {"PAGSCAN", sysprt_PAGSCAN, NULL};
 1611 /*******************************************************************/
 1612 static char *
 1613 sysprt_PAGSTEAL(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1614 {
 1615         static char buf[16]="steal  ";
 1616         val2valstr(sstat->mem.pgsteal, buf+ 6, 6, as->avgval, as->nsecs);
 1617         return buf;
 1618 }
 1619 
 1620 sys_printdef syspdef_PAGSTEAL = {"PAGSTEAL", sysprt_PAGSTEAL, NULL};
 1621 /*******************************************************************/
 1622 static char *
 1623 sysprt_PAGSTALL(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1624 {
 1625         static char buf[16]="stall  ";
 1626         val2valstr(sstat->mem.allocstall, buf+6, 6, as->avgval, as->nsecs);
 1627         return buf;
 1628 }
 1629 
 1630 sys_printdef syspdef_PAGSTALL = {"PAGSTALL", sysprt_PAGSTALL, NULL};
 1631 /*******************************************************************/
 1632 static char *
 1633 sysprt_PAGCOMPACT(struct sstat *sstat, extraparam *as, int badness, int *color)
 1634 {
 1635     static char buf[16]="compact ";
 1636     val2valstr(sstat->mem.compactstall, buf+8, 4, as->avgval, as->nsecs);
 1637     return buf;
 1638 }
 1639 
 1640 sys_printdef syspdef_PAGCOMPACT = {"PAGCOMPACT", sysprt_PAGCOMPACT, NULL};
 1641 /*******************************************************************/
 1642 static char *
 1643 sysprt_NUMAMIGRATE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1644 {
 1645         static char buf[16]="numamig  ";
 1646 
 1647         val2valstr(sstat->mem.numamigrate, buf+8, 4, as->avgval, as->nsecs);
 1648         return buf;
 1649 }
 1650 
 1651 sys_printdef syspdef_NUMAMIGRATE = {"NUMAMIGRATE", sysprt_NUMAMIGRATE, NULL};
 1652 
 1653 /*******************************************************************/
 1654 static char *
 1655 sysprt_PGMIGRATE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1656 {
 1657         static char buf[16]="migrate  ";
 1658 
 1659         val2valstr(sstat->mem.pgmigrate, buf+8, 4, as->avgval, as->nsecs);
 1660         return buf;
 1661 }
 1662 
 1663 sys_printdef syspdef_PGMIGRATE = {"PGMIGRATE", sysprt_PGMIGRATE, NULL};
 1664 
 1665 /*******************************************************************/
 1666 static char *
 1667 sysprt_PAGPGIN(struct sstat *sstat, extraparam *as, int badness, int *color)
 1668 {
 1669         static char buf[16]="pgin   ";
 1670         val2valstr(sstat->mem.pgins, buf+5, 7, as->avgval, as->nsecs);
 1671         return buf;
 1672 }
 1673 
 1674 sys_printdef syspdef_PAGPGIN = {"PAGPGIN", sysprt_PAGPGIN, NULL};
 1675 /*******************************************************************/
 1676 static char *
 1677 sysprt_PAGPGOUT(struct sstat *sstat, extraparam *as, int badness, int *color)
 1678 {
 1679         static char buf[16]="pgout  ";
 1680         val2valstr(sstat->mem.pgouts, buf+6, 6, as->avgval, as->nsecs);
 1681         return buf;
 1682 }
 1683 
 1684 sys_printdef syspdef_PAGPGOUT = {"PAGPGOUT", sysprt_PAGPGOUT, NULL};
 1685 /*******************************************************************/
 1686 static char *
 1687 sysprt_PAGSWIN(struct sstat *sstat, extraparam *as, int badness, int *color)
 1688 {
 1689         static char buf[16]="swin   ";
 1690         val2valstr(sstat->mem.swins, buf+5, 7, as->avgval, as->nsecs);
 1691         return buf;
 1692 }
 1693 
 1694 sys_printdef syspdef_PAGSWIN = {"PAGSWIN", sysprt_PAGSWIN, NULL};
 1695 /*******************************************************************/
 1696 static char *
 1697 sysprt_PAGSWOUT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1698 {
 1699         static char buf[16]="swout  ";
 1700     *color = -1;
 1701         val2valstr(sstat->mem.swouts, buf+6, 6, as->avgval, as->nsecs);
 1702         return buf;
 1703 }
 1704 
 1705 sys_printdef syspdef_PAGSWOUT = {"PAGSWOUT", sysprt_PAGSWOUT, NULL};
 1706 /*******************************************************************/
 1707 static char *
 1708 sysprt_OOMKILLS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1709 {
 1710         static char buf[16]="oomkill  ";
 1711 
 1712     if (sstat->mem.oomkills)
 1713         *color = COLORCRIT;
 1714 
 1715         val2valstr(sstat->mem.oomkills, buf+8, 4, as->avgval, as->nsecs);
 1716         return buf;
 1717 }
 1718 
 1719 static int
 1720 sysval_OOMKILLS(struct sstat *sstat)
 1721 {
 1722     if (sstat->mem.oomkills == -1)  // non-existing?
 1723         return 0;
 1724     else
 1725         return 1;
 1726 }
 1727 
 1728 sys_printdef syspdef_OOMKILLS = {"OOMKILLS", sysprt_OOMKILLS, sysval_OOMKILLS};
 1729 /*******************************************************************/
 1730 static char *
 1731 sysprt_NUMATOT(struct sstat *sstat, extraparam *as, int badness, int *color)
 1732 {
 1733     static char buf[16]="tot   ";
 1734     *color = -1;
 1735     val2memstr(sstat->memnuma.numa[as->index].totmem * pagesize, buf+6, MBFORMAT, 0, 0);
 1736     return buf;
 1737 }
 1738 
 1739 sys_printdef syspdef_NUMATOT = {"NUMATOT", sysprt_NUMATOT, NULL};
 1740 /*******************************************************************/
 1741 static char *
 1742 sysprt_NUMAFREE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1743 {
 1744     static char buf[16]="free  ";
 1745     *color = -1;
 1746     val2memstr(sstat->memnuma.numa[as->index].freemem * pagesize, buf+6, MBFORMAT, 0, 0);
 1747     return buf;
 1748 }
 1749 
 1750 sys_printdef syspdef_NUMAFREE = {"NUMAFREE", sysprt_NUMAFREE, NULL};
 1751 /*******************************************************************/
 1752 static char *
 1753 sysprt_NUMAFILE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1754 {
 1755     static char buf[16]="file  ";
 1756     *color = -1;
 1757     val2memstr(sstat->memnuma.numa[as->index].filepage * pagesize, buf+6, MBFORMAT, 0, 0);
 1758     return buf;
 1759 }
 1760 
 1761 sys_printdef syspdef_NUMAFILEPAGE = {"NUMAFILEPAGE", sysprt_NUMAFILE, NULL};
 1762 /*******************************************************************/
 1763 static char *
 1764 sysprt_NUMANR(struct sstat *sstat, extraparam *as, int badness, int *color)
 1765 {
 1766     static char buf[16];
 1767     *color = -1;
 1768     sprintf(buf, "numanode%04d", sstat->memnuma.numa[as->index].numanr);
 1769     return buf;
 1770 }
 1771 
 1772 sys_printdef syspdef_NUMANR = {"NUMANR", sysprt_NUMANR, NULL};
 1773 /*******************************************************************/
 1774 static char *
 1775 sysprt_NUMADIRTY(struct sstat *sstat, extraparam *as, int badness, int *color)
 1776 {
 1777     static char buf[16]="dirty  ";
 1778     *color = -1;
 1779     val2memstr(sstat->memnuma.numa[as->index].dirtymem * pagesize, buf+6, MBFORMAT, 0, 0);
 1780     return buf;
 1781 }
 1782 
 1783 sys_printdef syspdef_NUMADIRTY = {"NUMADIRTY", sysprt_NUMADIRTY, NULL};
 1784 /*******************************************************************/
 1785 static char *
 1786 sysprt_NUMAACTIVE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1787 {
 1788     static char buf[16]="activ  ";
 1789     *color = -1;
 1790     val2memstr(sstat->memnuma.numa[as->index].active * pagesize, buf+6, MBFORMAT, 0, 0);
 1791     return buf;
 1792 }
 1793 
 1794 sys_printdef syspdef_NUMAACTIVE = {"NUMAACTIVE", sysprt_NUMAACTIVE, NULL};
 1795 /*******************************************************************/
 1796 static char *
 1797 sysprt_NUMAINACTIVE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1798 {
 1799     static char buf[16]="inact   ";
 1800     *color = -1;
 1801     val2memstr(sstat->memnuma.numa[as->index].inactive * pagesize, buf+6, MBFORMAT, 0, 0);
 1802     return buf;
 1803 }
 1804 
 1805 sys_printdef syspdef_NUMAINACTIVE = {"NUMAINACTIVE", sysprt_NUMAINACTIVE, NULL};
 1806 /*******************************************************************/
 1807 static char *
 1808 sysprt_NUMASLAB(struct sstat *sstat, extraparam *as, int badness, int *color)
 1809 {
 1810     static char buf[16]="slab  ";
 1811     *color = -1;
 1812     val2memstr(sstat->memnuma.numa[as->index].slabmem * pagesize, buf+6, MBFORMAT, 0, 0);
 1813     return buf;
 1814 }
 1815 
 1816 sys_printdef syspdef_NUMASLAB = {"NUMASLAB", sysprt_NUMASLAB, NULL};
 1817 /*******************************************************************/
 1818 static char *
 1819 sysprt_NUMASLABRECLAIM(struct sstat *sstat, extraparam *as, int badness, int *color)
 1820 {
 1821     static char buf[16]="slrec ";
 1822     *color = -1;
 1823     val2memstr(sstat->memnuma.numa[as->index].slabreclaim * pagesize, buf+6, MBFORMAT, 0, 0);
 1824     return buf;
 1825 }
 1826 
 1827 sys_printdef syspdef_NUMASLABRECLAIM = {"NUMASLABRECLAIM", sysprt_NUMASLABRECLAIM, NULL};
 1828 /*******************************************************************/
 1829 static char *
 1830 sysprt_NUMASHMEM(struct sstat *sstat, extraparam *as, int badness, int *color)
 1831 {
 1832     static char buf[16]="shmem  ";
 1833     *color = -1;
 1834     val2memstr(sstat->memnuma.numa[as->index].shmem * pagesize, buf+6, MBFORMAT, 0, 0);
 1835     return buf;
 1836 }
 1837 
 1838 sys_printdef syspdef_NUMASHMEM = {"NUMASHMEM", sysprt_NUMASHMEM, NULL};
 1839 /*******************************************************************/
 1840 static char *
 1841 sysprt_NUMAFRAG(struct sstat *sstat, extraparam *as, int badness, int *color)
 1842 {
 1843     static char buf[15];
 1844     float perc = sstat->memnuma.numa[as->index].frag * 100.0;
 1845     if (perc > 1.0)
 1846         *color = -1;
 1847 
 1848     sprintf(buf, "frag %6.0f%%", perc);
 1849     return buf;
 1850 }
 1851 
 1852 sys_printdef syspdef_NUMAFRAG = {"NUMAFRAG", sysprt_NUMAFRAG, NULL};
 1853 /*******************************************************************/
 1854 static char *
 1855 sysprt_NUMAHUPTOT(struct sstat *sstat, extraparam *as, int badness, int *color)
 1856 {
 1857     static char buf[16]="hptot  ";
 1858     if (sstat->mem.tothugepage == 0)
 1859         return NULL;
 1860 
 1861     *color = -1;
 1862     val2memstr(sstat->memnuma.numa[as->index].tothp * sstat->mem.hugepagesz,
 1863                         buf+6, MBFORMAT, 0, 0);
 1864     return buf;
 1865 }
 1866 
 1867 sys_printdef syspdef_NUMAHUPTOT = {"NUMAHUPTOT", sysprt_NUMAHUPTOT, sysval_HUPTOT};
 1868 /*******************************************************************/
 1869 static char *
 1870 sysprt_NUMANUMCPU(struct sstat *sstat, extraparam *as, int badness, int *color) 
 1871 {
 1872         static char buf[16]="numcpu ";
 1873 
 1874         val2valstr(sstat->cpunuma.numa[as->index].nrcpu, buf+7, 5,0,as->nsecs);
 1875         return buf;
 1876 }
 1877 
 1878 sys_printdef syspdef_NUMANUMCPU = {"NUMANUMCPU", sysprt_NUMANUMCPU, NULL};
 1879 /*******************************************************************/
 1880 static char *
 1881 sysprt_NUMACPUSYS(struct sstat *sstat, extraparam *as, int badness, int *color)
 1882 {
 1883     static char buf[15];
 1884     float perc = sstat->cpunuma.numa[as->index].stime * 100.0 / as->percputot;
 1885 
 1886     if (perc > 1.0)
 1887         *color = -1;
 1888 
 1889     sprintf(buf, "sys  %6.0f%%", perc);
 1890     return buf;
 1891 }
 1892 
 1893 sys_printdef syspdef_NUMACPUSYS = {"NUMACPUSYS", sysprt_NUMACPUSYS, NULL};
 1894 /*******************************************************************/
 1895 static char *
 1896 sysprt_NUMACPUUSER(struct sstat *sstat, extraparam *as, int badness, int *color)
 1897 {
 1898     static char buf[15];
 1899     float perc = sstat->cpunuma.numa[as->index].utime * 100.0 / as->percputot;
 1900 
 1901     if (perc > 1.0)
 1902         *color = -1;
 1903 
 1904     sprintf(buf, "user %6.0f%%", perc);
 1905     return buf;
 1906 }
 1907 
 1908 sys_printdef syspdef_NUMACPUUSER = {"NUMACPUUSER", sysprt_NUMACPUUSER, NULL};
 1909 /*******************************************************************/
 1910 static char *
 1911 sysprt_NUMACPUNICE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1912 {
 1913     static char buf[15];
 1914     float perc = sstat->cpunuma.numa[as->index].ntime * 100.0 / as->percputot;
 1915 
 1916     if (perc > 1.0)
 1917         *color = -1;
 1918 
 1919     sprintf(buf, "nice %6.0f%%", perc);
 1920     return buf;
 1921 }
 1922 
 1923 sys_printdef syspdef_NUMACPUNICE = {"NUMACPUNICE", sysprt_NUMACPUNICE, NULL};
 1924 /*******************************************************************/
 1925 static char *
 1926 sysprt_NUMACPUIRQ(struct sstat *sstat, extraparam *as, int badness, int *color)
 1927 {
 1928     static char buf[15];
 1929     float perc = sstat->cpunuma.numa[as->index].Itime * 100.0 / as->percputot;
 1930 
 1931     if (perc > 1.0)
 1932         *color = -1;
 1933 
 1934     sprintf(buf, "irq  %6.0f%%", perc);
 1935     return buf;
 1936 }
 1937 
 1938 sys_printdef syspdef_NUMACPUIRQ = {"NUMACPUIRQ", sysprt_NUMACPUIRQ, NULL};
 1939 /*******************************************************************/
 1940 static char *
 1941 sysprt_NUMACPUSOFTIRQ(struct sstat *sstat, extraparam *as, int badness, int *color)
 1942 {
 1943     static char buf[15];
 1944     float perc = sstat->cpunuma.numa[as->index].Stime * 100.0 / as->percputot;
 1945 
 1946     if (perc > 1.0)
 1947         *color = -1;
 1948 
 1949     sprintf(buf, "sirq %6.0f%%", perc);
 1950     return buf;
 1951 }
 1952 
 1953 sys_printdef syspdef_NUMACPUSOFTIRQ = {"NUMACPUSOFTIRQ", sysprt_NUMACPUSOFTIRQ, NULL};
 1954 /*******************************************************************/
 1955 static char *
 1956 sysprt_NUMACPUIDLE(struct sstat *sstat, extraparam *as, int badness, int *color)
 1957 {
 1958     static char buf[15];
 1959 
 1960     sprintf(buf, "idle %6.0f%%",
 1961         (sstat->cpunuma.numa[as->index].itime * 100.0) / as->percputot);
 1962     return buf;
 1963 }
 1964 
 1965 sys_printdef syspdef_NUMACPUIDLE = {"NUMACPUIDLE", sysprt_NUMACPUIDLE, NULL};
 1966 /*******************************************************************/
 1967 static char *
 1968 sysprt_NUMACPUWAIT(struct sstat *sstat, extraparam *as, int badness, int *color)
 1969 {
 1970     static char buf[15];
 1971 
 1972     sprintf(buf, "nod%03d w%3.0f%%",
 1973         sstat->cpunuma.numa[as->index].numanr,
 1974         (sstat->cpunuma.numa[as->index].wtime * 100.0) / as->percputot);
 1975     return buf;
 1976 }
 1977 
 1978 sys_printdef syspdef_NUMACPUWAIT = {"NUMACPUWAIT", sysprt_NUMACPUWAIT, NULL};
 1979 /*******************************************************************/
 1980 static char *
 1981 sysprt_NUMACPUSTEAL(struct sstat *sstat, extraparam *as, int badness, int *color)
 1982 {
 1983     static char buf[15];
 1984     float perc = (sstat->cpunuma.numa[as->index].steal * 100.0)
 1985                             / as->percputot;
 1986 
 1987     if (perc > 1.0)
 1988         *color = -1;
 1989 
 1990     sprintf(buf, "steal %5.0f%%", perc);
 1991     return buf;
 1992 }
 1993 
 1994 sys_printdef syspdef_NUMACPUSTEAL = {"NUMACPUSTEAL", sysprt_NUMACPUSTEAL, NULL};
 1995 /*******************************************************************/
 1996 static char *
 1997 sysprt_NUMACPUGUEST(struct sstat *sstat, extraparam *as, int badness, int *color)
 1998 {
 1999     static char buf[15];
 2000     float perc = (sstat->cpunuma.numa[as->index].guest * 100.0)
 2001                             / as->percputot;
 2002 
 2003     if (perc > 1.0)
 2004         *color = -1;
 2005 
 2006     sprintf(buf, "guest %5.0f%%", perc);
 2007     return buf;
 2008 }
 2009 
 2010 sys_printdef syspdef_NUMACPUGUEST = {"NUMACPUGUEST", sysprt_NUMACPUGUEST, NULL};
 2011 /*******************************************************************/
 2012 static char *
 2013 sysprt_LLCMBMTOTAL(struct sstat *sstat, extraparam *as, int badness, int *color)
 2014 {
 2015     static char buf[16]="tot   ";
 2016     *color = -1;
 2017     val2memstr(sstat->llc.perllc[as->index].mbm_total, buf+6, MBFORMAT, as->avgval, as->nsecs);
 2018     return buf;
 2019 }
 2020 
 2021 sys_printdef syspdef_LLCMBMTOTAL = {"LLCMBMTOTAL", sysprt_LLCMBMTOTAL, NULL};
 2022 /*******************************************************************/
 2023 static char *
 2024 sysprt_LLCMBMLOCAL(struct sstat *sstat, extraparam *as, int badness, int *color)
 2025 {
 2026     static char buf[16]="loc   ";
 2027     *color = -1;
 2028     val2memstr(sstat->llc.perllc[as->index].mbm_local, buf+6, MBFORMAT, as->avgval, as->nsecs);
 2029     return buf;
 2030 }
 2031 
 2032 sys_printdef syspdef_LLCMBMLOCAL = {"LLCMBMLOCAL", sysprt_LLCMBMLOCAL, NULL};
 2033 /*******************************************************************/
 2034 static char *
 2035 sysprt_NUMLLC(struct sstat *sstat, extraparam *as, int badness, int *color)
 2036 {
 2037     static char buf[16];
 2038 
 2039     *color = -1;
 2040     sprintf(buf, "LLC%02d %5.0f%%", sstat->llc.perllc[as->index].id, sstat->llc.perllc[as->index].occupancy * 100);
 2041     return buf;
 2042 }
 2043 
 2044 sys_printdef syspdef_NUMLLC = {"NUMLLC", sysprt_NUMLLC, NULL};
 2045 /*******************************************************************/
 2046 // general formatting of PSI field in avg10/avg60/avg300
 2047 void
 2048 psiformatavg(struct psi *p, char *head, char *buf, int bufsize)
 2049 {
 2050     static char formats[] = "%.0f/%.0f/%.0f";
 2051     char        tmpbuf[32];
 2052 
 2053     snprintf(tmpbuf, sizeof tmpbuf, formats, p->avg10, p->avg60, p->avg300);
 2054 
 2055     if (strlen(tmpbuf) > 9) // reformat needed?
 2056     {
 2057         float avg10  = p->avg10;
 2058         float avg60  = p->avg60;
 2059         float avg300 = p->avg300;
 2060 
 2061         if (avg10 > 99.0)
 2062             avg10 = 99.0;
 2063         if (avg60 > 99.0)
 2064             avg60 = 99.0;
 2065         if (avg300 > 99.0)
 2066             avg300 = 99.0;
 2067 
 2068         snprintf(tmpbuf, sizeof tmpbuf, formats, avg10, avg60, avg300);
 2069     }
 2070 
 2071     snprintf(buf, bufsize, "%s %9s", head, tmpbuf);
 2072 }
 2073 
 2074 static char *
 2075 sysprt_PSICPUS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2076 {
 2077         static char buf[16];
 2078     psiformatavg(&(sstat->psi.cpusome), "cs", buf, sizeof buf);
 2079         return buf;
 2080 }
 2081 sys_printdef syspdef_PSICPUS = {"PSICPUS", sysprt_PSICPUS, NULL};
 2082 
 2083 static char *
 2084 sysprt_PSIMEMS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2085 {
 2086         static char buf[16];
 2087     psiformatavg(&(sstat->psi.memsome), "ms", buf, sizeof buf);
 2088         return buf;
 2089 }
 2090 sys_printdef syspdef_PSIMEMS = {"PSIMEMS", sysprt_PSIMEMS, NULL};
 2091 
 2092 static char *
 2093 sysprt_PSIMEMF(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2094 {
 2095         static char buf[16];
 2096     psiformatavg(&(sstat->psi.memfull), "mf", buf, sizeof buf);
 2097         return buf;
 2098 }
 2099 sys_printdef syspdef_PSIMEMF = {"PSIMEMF", sysprt_PSIMEMF, NULL};
 2100 
 2101 static char *
 2102 sysprt_PSIIOS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2103 {
 2104         static char buf[16];
 2105     psiformatavg(&(sstat->psi.iosome), "is", buf, sizeof buf);
 2106         return buf;
 2107 }
 2108 sys_printdef syspdef_PSIIOS = {"PSIIOS", sysprt_PSIIOS, NULL};
 2109 
 2110 static char *
 2111 sysprt_PSIIOF(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2112 {
 2113         static char buf[16];
 2114     psiformatavg(&(sstat->psi.iofull), "if", buf, sizeof buf);
 2115         return buf;
 2116 }
 2117 sys_printdef syspdef_PSIIOF = {"PSIIOF", sysprt_PSIIOF, NULL};
 2118 
 2119 /*******************************************************************/
 2120 // general formatting of PSI field in total percentage
 2121 void
 2122 psiformattot(struct psi *p, char *head, extraparam *as, int *color,
 2123                         char *buf, int bufsize)
 2124 {
 2125     static char formats[] = "%-7.7s %3lu%%";
 2126     unsigned long   perc = p->total/((count_t)as->nsecs*10000);
 2127 
 2128     if (perc > 100)
 2129         perc = 100;
 2130 
 2131     if (perc >= 1)
 2132         *color = COLORALMOST;
 2133 
 2134     snprintf(buf, bufsize, formats, head, perc);
 2135 }
 2136 
 2137 static char *
 2138 sysprt_PSICPUSTOT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2139 {
 2140         static char buf[32];
 2141 
 2142     psiformattot(&(sstat->psi.cpusome), "cpusome", as, color, buf, sizeof buf);
 2143         return buf;
 2144 }
 2145 sys_printdef syspdef_PSICPUSTOT = {"PSICPUSTOT", sysprt_PSICPUSTOT, NULL};
 2146 
 2147 static char *
 2148 sysprt_PSIMEMSTOT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2149 {
 2150         static char buf[32];
 2151 
 2152     psiformattot(&(sstat->psi.memsome), "memsome", as, color, buf, sizeof buf);
 2153         return buf;
 2154 }
 2155 sys_printdef syspdef_PSIMEMSTOT = {"PSIMEMSTOT", sysprt_PSIMEMSTOT, NULL};
 2156 
 2157 static char *
 2158 sysprt_PSIMEMFTOT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2159 {
 2160         static char buf[32];
 2161 
 2162     psiformattot(&(sstat->psi.memfull), "memfull", as, color, buf, sizeof buf);
 2163         return buf;
 2164 }
 2165 sys_printdef syspdef_PSIMEMFTOT = {"PSIMEMFTOT", sysprt_PSIMEMFTOT, NULL};
 2166 
 2167 static char *
 2168 sysprt_PSIIOSTOT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2169 {
 2170         static char buf[32];
 2171 
 2172     psiformattot(&(sstat->psi.iosome), "iosome", as, color, buf, sizeof buf);
 2173         return buf;
 2174 }
 2175 sys_printdef syspdef_PSIIOSTOT = {"PSIIOSTOT", sysprt_PSIIOSTOT, NULL};
 2176 
 2177 
 2178 static char *
 2179 sysprt_PSIIOFTOT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2180 {
 2181         static char buf[32];
 2182 
 2183     psiformattot(&(sstat->psi.iofull), "iofull", as, color, buf, sizeof buf);
 2184         return buf;
 2185 }
 2186 sys_printdef syspdef_PSIIOFTOT = {"PSIIOFTOT", sysprt_PSIIOFTOT, NULL};
 2187 
 2188 /*******************************************************************/
 2189 static char *
 2190 sysprt_CONTNAME(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2191 {
 2192         static char     buf[32] = "ctid ";
 2193 
 2194     *color = -1;
 2195 
 2196         sprintf(buf+5, "%7lu", sstat->cfs.cont[as->index].ctid);
 2197         return buf;
 2198 }
 2199 
 2200 sys_printdef syspdef_CONTNAME = {"CONTNAME", sysprt_CONTNAME, NULL};
 2201 /*******************************************************************/
 2202 static char *
 2203 sysprt_CONTNPROC(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2204 {
 2205         static char buf[16]="nproc  ";
 2206 
 2207     *color = -1;
 2208 
 2209         val2valstr(sstat->cfs.cont[as->index].numproc, 
 2210                       buf+6, 6, as->avgval, as->nsecs);
 2211         return buf;
 2212 }
 2213 
 2214 sys_printdef syspdef_CONTNPROC = {"CONTNPROC", sysprt_CONTNPROC, NULL};
 2215 /*******************************************************************/
 2216 static char *
 2217 sysprt_CONTCPU(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2218 {
 2219         static char buf[16];
 2220     float  perc;
 2221 
 2222     count_t used = sstat->cfs.cont[as->index].system + 
 2223                        sstat->cfs.cont[as->index].user + 
 2224                        sstat->cfs.cont[as->index].nice;
 2225 
 2226     *color = -1;
 2227 
 2228     if (sstat->cfs.cont[as->index].uptime)
 2229     {
 2230         perc = used * 100.0 / sstat->cfs.cont[as->index].uptime;
 2231             sprintf(buf, "cpubusy %3.0f%%", perc);
 2232     }
 2233     else
 2234             sprintf(buf, "cpubusy   ?%%");
 2235 
 2236         return buf;
 2237 }
 2238 
 2239 sys_printdef syspdef_CONTCPU = {"CONTCPU", sysprt_CONTCPU, NULL};
 2240 /*******************************************************************/
 2241 static char *
 2242 sysprt_CONTMEM(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2243 {
 2244         static char buf[16]="mem   ";
 2245 
 2246     *color = -1;
 2247 
 2248         val2memstr(sstat->cfs.cont[as->index].physpages * pagesize,
 2249                         buf+6, MBFORMAT, 0, 0);
 2250         return buf;
 2251 }
 2252 
 2253 sys_printdef syspdef_CONTMEM = {"CONTMEM", sysprt_CONTMEM, NULL};
 2254 /*******************************************************************/
 2255 static char *
 2256 sysprt_DSKNAME(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2257 {
 2258         static char     buf[16];
 2259     char        *pn;
 2260     int     len;
 2261 
 2262     *color = -1;
 2263 
 2264         if ( (len = strlen(as->perdsk[as->index].name)) > 12)
 2265         pn = as->perdsk[as->index].name + len - 12;
 2266     else
 2267         pn = as->perdsk[as->index].name;
 2268 
 2269         sprintf(buf, "%12.12s", pn);
 2270         return buf;
 2271 }
 2272 
 2273 sys_printdef syspdef_DSKNAME = {"DSKNAME", sysprt_DSKNAME, NULL};
 2274 /*******************************************************************/
 2275 static char *
 2276 sysprt_DSKBUSY(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2277 {
 2278     double      perc;
 2279         static char     buf[16]="busy  ";
 2280 
 2281     *color = -1;
 2282 
 2283     perc = as->perdsk[as->index].io_ms * 100.0 / as->mstot;
 2284 
 2285     if (perc >= 0.0 && perc < 1000000.0)
 2286             sprintf(buf+5, "%6.0lf%%", perc);
 2287     else
 2288             sprintf(buf+5, "%6.0lf%%", 999999.0);
 2289 
 2290         return buf;
 2291 }
 2292 
 2293 sys_printdef syspdef_DSKBUSY = {"DSKBUSY", sysprt_DSKBUSY, NULL};
 2294 /*******************************************************************/
 2295 static char *
 2296 sysprt_DSKNREAD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2297 {
 2298         static char buf[16]="read  ";
 2299 
 2300     *color = -1;
 2301 
 2302         val2valstr(as->perdsk[as->index].nread >= 0 ?
 2303             as->perdsk[as->index].nread : 0,  
 2304                     buf+5, 7, as->avgval, as->nsecs);
 2305         return buf;
 2306 }
 2307 
 2308 sys_printdef syspdef_DSKNREAD = {"DSKNREAD", sysprt_DSKNREAD, NULL};
 2309 /*******************************************************************/
 2310 static char *
 2311 sysprt_DSKNWRITE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2312 {
 2313         static char buf[16]="write ";
 2314 
 2315     *color = -1;
 2316 
 2317         val2valstr(as->perdsk[as->index].nwrite >= 0 ?
 2318             as->perdsk[as->index].nwrite : 0,  
 2319             buf+6, 6, as->avgval, as->nsecs);
 2320         return buf;
 2321 }
 2322 
 2323 sys_printdef syspdef_DSKNWRITE = {"DSKNWRITE", sysprt_DSKNWRITE, NULL};
 2324 /*******************************************************************/
 2325 static char *
 2326 sysprt_DSKNDISC(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2327 {
 2328         static char buf[16]="discrd ";
 2329 
 2330     *color = -1;
 2331 
 2332     // value might be -1 in case not supported --> "?"
 2333         val2valstr(as->perdsk[as->index].ndisc,
 2334                     buf+7, 5, as->avgval, as->nsecs);
 2335         return buf;
 2336 }
 2337 
 2338 static int
 2339 sysval_DSKNDISK(struct sstat *sstat)
 2340 {
 2341     if (sstat->dsk.ndsk > 0 && sstat->dsk.dsk[0].ndisc != -1)
 2342         return 1;
 2343     else
 2344         return 0;
 2345 }
 2346 
 2347 sys_printdef syspdef_DSKNDISC = {"DSKNDISC", sysprt_DSKNDISC, sysval_DSKNDISK};
 2348 /*******************************************************************/
 2349 static char *
 2350 sysprt_DSKKBPERRD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2351 {
 2352         static char buf[16]="KiB/r ";
 2353     struct perdsk   *dp = &(as->perdsk[as->index]);
 2354 
 2355         val2valstr(dp->nread > 0 ?  dp->nrsect / dp->nread / 2 : 0,
 2356                    buf+6, 6, 0, as->nsecs);
 2357         return buf;
 2358 }
 2359 
 2360 sys_printdef syspdef_DSKKBPERRD = {"DSKKBPERRD", sysprt_DSKKBPERRD, NULL};
 2361 /*******************************************************************/
 2362 static char *
 2363 sysprt_DSKKBPERWR(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2364 {
 2365         static char buf[16]="KiB/w ";
 2366     struct perdsk   *dp = &(as->perdsk[as->index]);
 2367 
 2368         val2valstr(dp->nwrite > 0 ?  dp->nwsect / dp->nwrite / 2 : 0,
 2369                    buf+6, 6, 0, as->nsecs);
 2370         return buf;
 2371 }
 2372 
 2373 sys_printdef syspdef_DSKKBPERWR = {"DSKKBPERWR", sysprt_DSKKBPERWR, NULL};
 2374 /*******************************************************************/
 2375 static char *
 2376 sysprt_DSKKBPERDS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2377 {
 2378         static char buf[16]="KiB/d      ?";
 2379     struct perdsk   *dp = &(as->perdsk[as->index]);
 2380 
 2381     if (dp->ndisc != -1)
 2382             val2valstr(dp->ndisc > 0 ? dp->ndsect/dp->ndisc/2 : 0,
 2383                    buf+6, 6, 0, as->nsecs);
 2384 
 2385         return buf;
 2386 }
 2387 
 2388 sys_printdef syspdef_DSKKBPERDS = {"DSKKBPERDS", sysprt_DSKKBPERDS, sysval_DSKNDISK};
 2389 /*******************************************************************/
 2390 static char *
 2391 sysprt_DSKMBPERSECWR(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2392 {
 2393         static char buf[16]="MBw/s ";
 2394     struct perdsk   *dp = &(as->perdsk[as->index]);
 2395 
 2396         snprintf(buf+6, sizeof buf-6, "%6.1lf",
 2397                     dp->nwsect / 2.0 / 1024 / as->nsecs);
 2398 
 2399         return buf;
 2400 }
 2401 
 2402 sys_printdef syspdef_DSKMBPERSECWR = {"DSKMBPERSECWR", sysprt_DSKMBPERSECWR, NULL};
 2403 /*******************************************************************/
 2404 static char *
 2405 sysprt_DSKMBPERSECRD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2406 {
 2407         static char buf[16]="MBr/s ";
 2408     struct perdsk   *dp = &(as->perdsk[as->index]);
 2409 
 2410         snprintf(buf+6, sizeof buf-6, "%6.1lf",
 2411                 dp->nrsect / 2.0 / 1024 / as->nsecs);
 2412         return buf;
 2413 }
 2414 
 2415 sys_printdef syspdef_DSKMBPERSECRD = {"DSKMBPERSECRD", sysprt_DSKMBPERSECRD, NULL};
 2416 /*******************************************************************/
 2417 static char *
 2418 sysprt_DSKINFLIGHT(struct sstat *sstat, extraparam *as, int badness, int *color)
 2419 {
 2420         static char    buf[16]="inflt  ";
 2421         struct perdsk  *dp = &(as->perdsk[as->index]);
 2422 
 2423         val2valstr(dp->inflight, buf+6, 6, 0, 0);
 2424         return buf;
 2425 }
 2426 
 2427 sys_printdef syspdef_DSKINFLIGHT = {"DSKINFLIGHT", sysprt_DSKINFLIGHT, NULL};
 2428 /*******************************************************************/
 2429 static char *
 2430 sysprt_DSKAVQUEUE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2431 {
 2432         static char buf[16]="avq  ";
 2433     struct perdsk   *dp = &(as->perdsk[as->index]);
 2434 
 2435     sprintf(buf+4, "%8.2f", dp->io_ms > 0 ?
 2436                                 (double)dp->avque / dp->io_ms : 0.0);
 2437         return buf;
 2438 }
 2439 
 2440 sys_printdef syspdef_DSKAVQUEUE = {"DSKAVQUEUE", sysprt_DSKAVQUEUE, NULL};
 2441 /*******************************************************************/
 2442 static char *
 2443 sysprt_DSKAVIO(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2444 {
 2445         static char buf[32]="avio  ";
 2446         double      avioms = as->iotot > 0 ? 
 2447                         (double)(as->perdsk[as->index].io_ms)/as->iotot:0.0;
 2448 
 2449     *color = -1;
 2450 
 2451     if (avioms >= 9995.0)
 2452     {
 2453         val2valstr((unsigned long long)avioms / 1000, buf+5, 5, 0, 0);
 2454         sprintf(buf+10, " s");
 2455     }
 2456     else if (avioms >= 99.95)
 2457     {
 2458         sprintf(buf+5, "%4.0lf ms", avioms);
 2459     }
 2460     else if (avioms >= 9.995)
 2461     {
 2462         sprintf(buf+5, "%4.1lf ms", avioms);
 2463     }
 2464     else if (avioms >= 0.09995)
 2465     {
 2466         sprintf(buf+5, "%4.2lf ms", avioms);
 2467     }
 2468     else if (avioms >= 0.01)
 2469     {
 2470         sprintf(buf+5, "%4.1lf µs", avioms * 1000.0);
 2471     }
 2472     else if (avioms >= 0.0001)
 2473     {
 2474         sprintf(buf+5, "%4.2lf µs", avioms * 1000.0);
 2475     }
 2476     else
 2477     {
 2478         sprintf(buf+5, "%4.1lf ns", avioms * 1000000.0);
 2479     }
 2480 
 2481         return buf;
 2482 }
 2483 
 2484 sys_printdef syspdef_DSKAVIO = {"DSKAVIO", sysprt_DSKAVIO, NULL};
 2485 /*******************************************************************/
 2486 static char *
 2487 sysprt_NETTRANSPORT(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 2488 {
 2489         return "transport   ";
 2490 }
 2491 
 2492 sys_printdef syspdef_NETTRANSPORT = {"NETTRANSPORT", sysprt_NETTRANSPORT, NULL};
 2493 /*******************************************************************/
 2494 static char *
 2495 sysprt_NETTCPI(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2496 {
 2497         static char buf[16]="tcpi   ";
 2498         val2valstr(sstat->net.tcp.InSegs,  buf+5, 7, as->avgval, as->nsecs);
 2499         return buf;
 2500 }
 2501 
 2502 sys_printdef syspdef_NETTCPI = {"NETTCPI", sysprt_NETTCPI, NULL};
 2503 /*******************************************************************/
 2504 static char *
 2505 sysprt_NETTCPO(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2506 {
 2507         static char buf[16]="tcpo   ";
 2508         val2valstr(sstat->net.tcp.OutSegs,  buf+5, 7, as->avgval, as->nsecs);
 2509         return buf;
 2510 }
 2511 
 2512 sys_printdef syspdef_NETTCPO = {"NETTCPO", sysprt_NETTCPO, NULL};
 2513 /*******************************************************************/
 2514 static char *
 2515 sysprt_NETTCPACTOPEN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2516 {
 2517         static char buf[16]="tcpao  ";
 2518         val2valstr(sstat->net.tcp.ActiveOpens,  buf+6, 6, as->avgval, as->nsecs);
 2519         return buf;
 2520 }
 2521 
 2522 sys_printdef syspdef_NETTCPACTOPEN = {"NETTCPACTOPEN", sysprt_NETTCPACTOPEN, NULL};
 2523 /*******************************************************************/
 2524 static char *
 2525 sysprt_NETTCPPASVOPEN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2526 {
 2527         static char buf[16]="tcppo  ";
 2528         val2valstr(sstat->net.tcp.PassiveOpens, buf+6, 6, as->avgval, as->nsecs);
 2529         return buf;
 2530 }
 2531 
 2532 sys_printdef syspdef_NETTCPPASVOPEN = {"NETTCPPASVOPEN", sysprt_NETTCPPASVOPEN, NULL};
 2533 /*******************************************************************/
 2534 static char *
 2535 sysprt_NETTCPRETRANS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2536 {
 2537         static char buf[16]="tcprs  ";
 2538         val2valstr(sstat->net.tcp.RetransSegs,  buf+6, 6, as->avgval, as->nsecs);
 2539         return buf;
 2540 }
 2541 
 2542 sys_printdef syspdef_NETTCPRETRANS = {"NETTCPRETRANS", sysprt_NETTCPRETRANS, NULL};
 2543 /*******************************************************************/
 2544 static char *
 2545 sysprt_NETTCPINERR(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2546 {
 2547         static char buf[16]="tcpie  ";
 2548         val2valstr(sstat->net.tcp.InErrs,  buf+6, 6, as->avgval, as->nsecs);
 2549         return buf;
 2550 }
 2551 
 2552 sys_printdef syspdef_NETTCPINERR = {"NETTCPINERR", sysprt_NETTCPINERR, NULL};
 2553 /*******************************************************************/
 2554 static char *
 2555 sysprt_NETTCPORESET(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2556 {
 2557         static char buf[16]="tcpor  ";
 2558         val2valstr(sstat->net.tcp.OutRsts,  buf+6, 6, as->avgval, as->nsecs);
 2559         return buf;
 2560 }
 2561 
 2562 sys_printdef syspdef_NETTCPORESET = {"NETTCPORESET", sysprt_NETTCPORESET, NULL};
 2563 /*******************************************************************/
 2564 static char *
 2565 sysprt_NETUDPNOPORT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2566 {
 2567         static char buf[16]="udpnp  ";
 2568         val2valstr(sstat->net.udpv4.NoPorts,  buf+6, 6, as->avgval, as->nsecs);
 2569         return buf;
 2570 }
 2571 
 2572 sys_printdef syspdef_NETUDPNOPORT = {"NETUDPNOPORT", sysprt_NETUDPNOPORT, NULL};
 2573 /*******************************************************************/
 2574 static char *
 2575 sysprt_NETUDPINERR(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2576 {
 2577         static char buf[16]="udpie  ";
 2578         val2valstr(sstat->net.udpv4.InErrors,  buf+6, 6, as->avgval, as->nsecs);
 2579         return buf;
 2580 }
 2581 
 2582 sys_printdef syspdef_NETUDPINERR = {"NETUDPINERR", sysprt_NETUDPINERR, NULL};
 2583 /*******************************************************************/
 2584 static char *
 2585 sysprt_NETUDPI(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2586 {
 2587         static char buf[16]="udpi   ";
 2588         count_t udpin  = sstat->net.udpv4.InDatagrams  +
 2589                         sstat->net.udpv6.Udp6InDatagrams;
 2590         val2valstr(udpin,   buf+5, 7, as->avgval, as->nsecs);
 2591         return buf;
 2592 }
 2593 
 2594 sys_printdef syspdef_NETUDPI = {"NETUDPI", sysprt_NETUDPI, NULL};
 2595 /*******************************************************************/
 2596 static char *
 2597 sysprt_NETUDPO(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2598 {
 2599         static char buf[16]="udpo   ";
 2600         count_t udpout = sstat->net.udpv4.OutDatagrams +
 2601                         sstat->net.udpv6.Udp6OutDatagrams;
 2602         val2valstr(udpout,   buf+5, 7, as->avgval, as->nsecs);
 2603         return buf;
 2604 }
 2605 
 2606 sys_printdef syspdef_NETUDPO = {"NETUDPO", sysprt_NETUDPO, NULL};
 2607 /*******************************************************************/
 2608 static char *
 2609 sysprt_NETNETWORK(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 2610 {
 2611         return "network     ";
 2612 }
 2613 
 2614 sys_printdef syspdef_NETNETWORK = {"NETNETWORK", sysprt_NETNETWORK, NULL};
 2615 /*******************************************************************/
 2616 static char *
 2617 sysprt_NETIPI(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2618 {
 2619         static char buf[16]="ipi    ";
 2620         count_t ipin    = sstat->net.ipv4.InReceives  +
 2621                         sstat->net.ipv6.Ip6InReceives;
 2622         val2valstr(ipin, buf+4, 8, as->avgval, as->nsecs);
 2623         return buf;
 2624 }
 2625 
 2626 sys_printdef syspdef_NETIPI = {"NETIPI", sysprt_NETIPI, NULL};
 2627 /*******************************************************************/
 2628 static char *
 2629 sysprt_NETIPO(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2630 {
 2631         static char buf[16]="ipo    ";
 2632         count_t ipout   = sstat->net.ipv4.OutRequests +
 2633                         sstat->net.ipv6.Ip6OutRequests;
 2634         val2valstr(ipout, buf+4, 8, as->avgval, as->nsecs);
 2635         return buf;
 2636 }
 2637 
 2638 sys_printdef syspdef_NETIPO = {"NETIPO", sysprt_NETIPO, NULL};
 2639 /*******************************************************************/
 2640 static char *
 2641 sysprt_NETIPFRW(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2642 {
 2643         static char buf[16]="ipfrw  ";
 2644         count_t ipfrw   = sstat->net.ipv4.ForwDatagrams +
 2645                         sstat->net.ipv6.Ip6OutForwDatagrams;
 2646         val2valstr(ipfrw, buf+6, 6, as->avgval, as->nsecs);
 2647         return buf;
 2648 }
 2649 
 2650 sys_printdef syspdef_NETIPFRW = {"NETIPFRW", sysprt_NETIPFRW, NULL};
 2651 /*******************************************************************/
 2652 static char *
 2653 sysprt_NETIPDELIV(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2654 {
 2655         static char buf[16]="deliv  ";
 2656         count_t ipindel = sstat->net.ipv4.InDelivers +
 2657                         sstat->net.ipv6.Ip6InDelivers;
 2658         val2valstr(ipindel, buf+6, 6, as->avgval, as->nsecs);
 2659         return buf;
 2660 }
 2661 
 2662 sys_printdef syspdef_NETIPDELIV = {"NETIPDELIV", sysprt_NETIPDELIV, NULL};
 2663 /*******************************************************************/
 2664 static char *
 2665 sysprt_NETICMPIN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2666 {
 2667         static char buf[16]="icmpi  ";
 2668         count_t icmpin = sstat->net.icmpv4.InMsgs+
 2669                         sstat->net.icmpv6.Icmp6InMsgs;
 2670         val2valstr(icmpin , buf+6, 6, as->avgval, as->nsecs);
 2671         return buf;
 2672 }
 2673 
 2674 sys_printdef syspdef_NETICMPIN = {"NETICMPIN", sysprt_NETICMPIN, NULL};
 2675 /*******************************************************************/
 2676 static char *
 2677 sysprt_NETICMPOUT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2678 {
 2679         static char buf[16]="icmpo  ";
 2680         count_t icmpin = sstat->net.icmpv4.OutMsgs+
 2681                         sstat->net.icmpv6.Icmp6OutMsgs;
 2682         val2valstr(icmpin , buf+6, 6, as->avgval, as->nsecs);
 2683         return buf;
 2684 }
 2685 
 2686 sys_printdef syspdef_NETICMPOUT = {"NETICMPOUT", sysprt_NETICMPOUT, NULL};
 2687 /*******************************************************************/
 2688 static char *
 2689 sysprt_NETNAME(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2690 {
 2691         count_t busy;
 2692         count_t ival = sstat->intf.intf[as->index].rbyte/125/as->nsecs;
 2693         count_t oval = sstat->intf.intf[as->index].sbyte/125/as->nsecs;
 2694 
 2695         static char buf[16] = "ethxxxx ----";
 2696                       //       012345678901
 2697 
 2698     *color = -1;
 2699 
 2700         if (sstat->intf.intf[as->index].speed)  /* speed known? */
 2701         {
 2702                 if (sstat->intf.intf[as->index].duplex)
 2703                         busy = (ival > oval ? ival : oval) /
 2704                                (sstat->intf.intf[as->index].speed *10);
 2705                 else
 2706                         busy = (ival + oval) /
 2707                                (sstat->intf.intf[as->index].speed *10);
 2708 
 2709         // especially with wireless, the speed might have dropped
 2710         // temporarily to a very low value (snapshot)
 2711         // then it might be better to take the speed of the previous
 2712         // sample
 2713         if (busy > 100 && sstat->intf.intf[as->index].speed <
 2714                     sstat->intf.intf[as->index].speedp)
 2715         {
 2716             sstat->intf.intf[as->index].speed =
 2717                 sstat->intf.intf[as->index].speedp;
 2718 
 2719                     if (sstat->intf.intf[as->index].duplex)
 2720                             busy = (ival > oval ? ival : oval) /
 2721                                     (sstat->intf.intf[as->index].speed *10);
 2722                     else
 2723                             busy = (ival + oval) /
 2724                                     (sstat->intf.intf[as->index].speed *10);
 2725         }
 2726 
 2727         if( busy < -99 )
 2728         {
 2729             // when we get wrong values, show wrong values
 2730             busy = -99;
 2731         }       
 2732         else if( busy > 999 )
 2733         {
 2734             busy = 999;
 2735         }
 2736             snprintf(buf, sizeof(buf)-1, "%-7.7s %3lld%%", 
 2737                       sstat->intf.intf[as->index].name, busy);
 2738 
 2739         } 
 2740         else 
 2741         {
 2742                 snprintf(buf, sizeof(buf)-1, "%-7.7s ----",
 2743                                sstat->intf.intf[as->index].name);
 2744                 strcpy(buf+8, "----");
 2745         } 
 2746         return buf;
 2747 }
 2748 
 2749 sys_printdef syspdef_NETNAME = {"NETNAME", sysprt_NETNAME, NULL};
 2750 /*******************************************************************/
 2751 static char *
 2752 sysprt_NETPCKI(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2753 {
 2754         static char buf[16]="pcki  ";
 2755 
 2756     *color = -1;
 2757 
 2758         val2valstr(sstat->intf.intf[as->index].rpack, 
 2759                    buf+5, 7, as->avgval, as->nsecs);
 2760         return buf;
 2761 }
 2762 
 2763 sys_printdef syspdef_NETPCKI = {"NETPCKI", sysprt_NETPCKI, NULL};
 2764 /*******************************************************************/
 2765 static char *
 2766 sysprt_NETPCKO(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2767 {
 2768         static char buf[16]="pcko  ";
 2769 
 2770     *color = -1;
 2771 
 2772         val2valstr(sstat->intf.intf[as->index].spack, 
 2773                    buf+5, 7, as->avgval, as->nsecs);
 2774         return buf;
 2775 }
 2776 
 2777 sys_printdef syspdef_NETPCKO = {"NETPCKO", sysprt_NETPCKO, NULL};
 2778 /*******************************************************************/
 2779 /*
 2780 ** convert byte-transfers to bit-transfers     (*    8)
 2781 ** convert bit-transfers  to kilobit-transfers (/ 1000)
 2782 ** per second
 2783 */
 2784 static char *makenetspeed(count_t val, int nsecs)
 2785 {
 2786         char        c;
 2787         static char buf[16]="si      ?bps";
 2788                               // 012345678901
 2789 
 2790         val=val/125/nsecs;  // convert to Kbps
 2791 
 2792         if (val < 10000)
 2793         {
 2794                 c='K';
 2795         } 
 2796         else if (val < (count_t)10000 * 1000)
 2797         {
 2798                 val/=1000;
 2799                 c = 'M';
 2800         } 
 2801         else if (val < (count_t)10000 * 1000 * 1000)
 2802         {
 2803                 val/=1000 * 1000;
 2804                 c = 'G';
 2805         } 
 2806         else 
 2807         {
 2808                 val = val / 1000 / 1000 / 1000;
 2809                 c = 'T';
 2810         }
 2811 
 2812         if(val < -999)
 2813         {
 2814         // when we get wrong values, show wrong values
 2815                 val = -999;
 2816         }
 2817         else if(val > 9999)
 2818         {
 2819                 val = 9999;
 2820         }
 2821 
 2822         snprintf(buf+3, sizeof(buf)-3, "%4lld %cbps", val, c);
 2823 
 2824         return buf;
 2825 }
 2826 /*******************************************************************/
 2827 static char *
 2828 sysprt_NETSPEEDMAX(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2829 {
 2830         static char buf[16];
 2831         count_t speed = sstat->intf.intf[as->index].speed;
 2832 
 2833     *color = -1;
 2834 
 2835     if (speed < 0 )
 2836         speed = 0;
 2837 
 2838     if (speed < 10000)
 2839     {
 2840             snprintf(buf, sizeof buf, "sp %4lld Mbps", speed);
 2841     }
 2842     else
 2843     {
 2844         speed /= 1000;
 2845 
 2846         if (speed > 9999)
 2847         {
 2848             speed = 9999;
 2849         }
 2850             snprintf(buf, sizeof buf, "sp %4lld Gbps", speed);
 2851     }
 2852 
 2853         return buf;
 2854 }
 2855 
 2856 sys_printdef syspdef_NETSPEEDMAX = {"NETSPEEDMAX", sysprt_NETSPEEDMAX, NULL};
 2857 /*******************************************************************/
 2858 static char *
 2859 sysprt_NETSPEEDIN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2860 {
 2861 
 2862     *color = -1;
 2863 
 2864         char *ps=makenetspeed(sstat->intf.intf[as->index].rbyte,as->nsecs);
 2865         ps[0]='s';
 2866         ps[1]='i';
 2867         return ps;
 2868 }
 2869 
 2870 sys_printdef syspdef_NETSPEEDIN = {"NETSPEEDIN", sysprt_NETSPEEDIN, NULL};
 2871 /*******************************************************************/
 2872 static char *
 2873 sysprt_NETSPEEDOUT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2874 {
 2875 
 2876     *color = -1;
 2877 
 2878         char *ps=makenetspeed(sstat->intf.intf[as->index].sbyte,as->nsecs);
 2879         ps[0]='s';
 2880         ps[1]='o';
 2881         return ps;
 2882 }
 2883 
 2884 sys_printdef syspdef_NETSPEEDOUT = {"NETSPEEDOUT", sysprt_NETSPEEDOUT, NULL};
 2885 /*******************************************************************/
 2886 static char *
 2887 sysprt_NETCOLLIS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2888 {
 2889         static char buf[16]="coll  ";
 2890         val2valstr(sstat->intf.intf[as->index].scollis, 
 2891                    buf+5, 7, as->avgval, as->nsecs);
 2892         return buf;
 2893 }
 2894 
 2895 sys_printdef syspdef_NETCOLLIS = {"NETCOLLIS", sysprt_NETCOLLIS, NULL};
 2896 /*******************************************************************/
 2897 static char *
 2898 sysprt_NETMULTICASTIN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2899 {
 2900         static char buf[16]="mlti ";
 2901         val2valstr(sstat->intf.intf[as->index].rmultic, 
 2902                    buf+5, 7, as->avgval, as->nsecs);
 2903         return buf;
 2904 }
 2905 
 2906 sys_printdef syspdef_NETMULTICASTIN = {"NETMULTICASTIN", sysprt_NETMULTICASTIN, NULL};
 2907 /*******************************************************************/
 2908 static char *
 2909 sysprt_NETRCVERR(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2910 {
 2911         static char buf[16]="erri   ";
 2912         val2valstr(sstat->intf.intf[as->index].rerrs, 
 2913                    buf+5, 7, as->avgval, as->nsecs);
 2914         return buf;
 2915 }
 2916 
 2917 sys_printdef syspdef_NETRCVERR = {"NETRCVERR", sysprt_NETRCVERR, NULL};
 2918 /*******************************************************************/
 2919 static char *
 2920 sysprt_NETSNDERR(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2921 {
 2922         static char buf[16]="erro   ";
 2923         val2valstr(sstat->intf.intf[as->index].serrs, 
 2924                    buf+5, 7, as->avgval, as->nsecs);
 2925         return buf;
 2926 }
 2927 
 2928 sys_printdef syspdef_NETSNDERR = {"NETSNDERR", sysprt_NETSNDERR, NULL};
 2929 /*******************************************************************/
 2930 static char *
 2931 sysprt_NETRCVDROP(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2932 {
 2933         static char buf[16]="drpi   ";
 2934         val2valstr(sstat->intf.intf[as->index].rdrop,
 2935                    buf+5, 7, as->avgval, as->nsecs);
 2936         return buf;
 2937 }
 2938 
 2939 sys_printdef syspdef_NETRCVDROP = {"NETRCVDROP", sysprt_NETRCVDROP, NULL};
 2940 /*******************************************************************/
 2941 static char *
 2942 sysprt_NETSNDDROP(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2943 {
 2944         static char buf[16]="drpo   ";
 2945         val2valstr(sstat->intf.intf[as->index].sdrop,
 2946                    buf+5, 7, as->avgval, as->nsecs);
 2947         return buf;
 2948 }
 2949 
 2950 sys_printdef syspdef_NETSNDDROP = {"NETSNDDROP", sysprt_NETSNDDROP, NULL};
 2951 /*******************************************************************/
 2952 static char *
 2953 sysprt_IFBNAME(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2954 {
 2955         count_t busy;
 2956         count_t ival = sstat->ifb.ifb[as->index].rcvb/125/as->nsecs;
 2957         count_t oval = sstat->ifb.ifb[as->index].sndb/125/as->nsecs;
 2958     int     len;
 2959         static char buf[16] = "ethxxxx ----", tmp[32], *ps=tmp;
 2960                       //       012345678901
 2961 
 2962     *color = -1;
 2963 
 2964     busy = (ival > oval ? ival : oval) * sstat->ifb.ifb[as->index].lanes /
 2965                                (sstat->ifb.ifb[as->index].rate * 10);
 2966 
 2967     snprintf(tmp, sizeof tmp, "%s/%d",
 2968                  sstat->ifb.ifb[as->index].ibname,
 2969              sstat->ifb.ifb[as->index].portnr);
 2970 
 2971     len = strlen(ps);
 2972         if (len > 7)
 2973         ps = ps + len - 7;
 2974 
 2975     snprintf(buf, sizeof buf, "%-7.7s %3lld%%", ps, busy);
 2976         return buf;
 2977 }
 2978 
 2979 sys_printdef syspdef_IFBNAME = {"IFBNAME", sysprt_IFBNAME, NULL};
 2980 /*******************************************************************/
 2981 static char *
 2982 sysprt_IFBPCKI(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2983 {
 2984         static char buf[16]="pcki  ";
 2985 
 2986     *color = -1;
 2987 
 2988         val2valstr(sstat->ifb.ifb[as->index].rcvp, 
 2989                    buf+5, 7, as->avgval, as->nsecs);
 2990         return buf;
 2991 }
 2992 
 2993 sys_printdef syspdef_IFBPCKI = {"IFBPCKI", sysprt_IFBPCKI, NULL};
 2994 /*******************************************************************/
 2995 static char *
 2996 sysprt_IFBPCKO(struct sstat *sstat, extraparam *as, int badness, int *color) 
 2997 {
 2998         static char buf[16]="pcko  ";
 2999 
 3000     *color = -1;
 3001 
 3002         val2valstr(sstat->ifb.ifb[as->index].sndp, 
 3003                    buf+5, 7, as->avgval, as->nsecs);
 3004         return buf;
 3005 }
 3006 
 3007 sys_printdef syspdef_IFBPCKO = {"IFBPCKO", sysprt_IFBPCKO, NULL};
 3008 /*******************************************************************/
 3009 static char *
 3010 sysprt_IFBSPEEDMAX(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3011 {
 3012         static char buf[64];
 3013         count_t rate = sstat->ifb.ifb[as->index].rate;
 3014 
 3015     *color = -1;
 3016 
 3017     if (rate < 10000)
 3018     {
 3019             snprintf(buf, sizeof buf, "sp %4lld Mbps", rate);
 3020     }
 3021     else
 3022     {
 3023         rate /= 1000;
 3024 
 3025         if (rate > 9999)
 3026         {
 3027             rate = 9999;
 3028         }
 3029             snprintf(buf, sizeof buf, "sp %4lld Gbps", rate);
 3030     }
 3031 
 3032         return buf;
 3033 }
 3034 
 3035 sys_printdef syspdef_IFBSPEEDMAX = {"IFBSPEEDMAX", sysprt_IFBSPEEDMAX, NULL};
 3036 /*******************************************************************/
 3037 static char *
 3038 sysprt_IFBLANES(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3039 {
 3040         static char buf[16]="lanes   ";
 3041         val2valstr(sstat->ifb.ifb[as->index].lanes, buf+6, 6, 0, 0);
 3042         return buf;
 3043 }
 3044 
 3045 sys_printdef syspdef_IFBLANES = {"IFBLANES", sysprt_IFBLANES, NULL};
 3046 /*******************************************************************/
 3047 static char *
 3048 sysprt_IFBSPEEDIN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3049 {
 3050 
 3051     *color = -1;
 3052 
 3053         char *ps=makenetspeed(sstat->ifb.ifb[as->index].rcvb *
 3054                           sstat->ifb.ifb[as->index].lanes, as->nsecs);
 3055         ps[0]='s';
 3056         ps[1]='i';
 3057         return ps;
 3058 }
 3059 
 3060 sys_printdef syspdef_IFBSPEEDIN = {"IFBSPEEDIN", sysprt_IFBSPEEDIN, NULL};
 3061 /*******************************************************************/
 3062 static char *
 3063 sysprt_IFBSPEEDOUT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3064 {
 3065 
 3066     *color = -1;
 3067 
 3068     char *ps=makenetspeed(sstat->ifb.ifb[as->index].sndb *
 3069                           sstat->ifb.ifb[as->index].lanes, as->nsecs);
 3070         ps[0]='s';
 3071         ps[1]='o';
 3072         return ps;
 3073 }
 3074 
 3075 sys_printdef syspdef_IFBSPEEDOUT = {"IFBSPEEDOUT", sysprt_IFBSPEEDOUT, NULL};
 3076 /*******************************************************************/
 3077 static char *
 3078 sysprt_NFMSERVER(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3079 {
 3080     static char buf[16] = "srv ";
 3081         char mntdev[128], *ps;
 3082 
 3083         memcpy(mntdev, sstat->nfs.nfsmounts.nfsmnt[as->index].mountdev,
 3084                                 sizeof mntdev);
 3085 
 3086     if ( (ps = strchr(mntdev, ':')) )       // colon found?
 3087         *ps = '\0';
 3088     else
 3089         strcpy(mntdev, "?");
 3090 
 3091     sprintf(buf+4, "%8.8s", mntdev);
 3092         return buf;
 3093 }
 3094 
 3095 sys_printdef syspdef_NFMSERVER = {"NFMSERVER", sysprt_NFMSERVER, NULL};
 3096 /*******************************************************************/
 3097 static char *
 3098 sysprt_NFMPATH(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3099 {
 3100     static char buf[16];
 3101         char mntdev[128], *ps;
 3102     int len;
 3103 
 3104         memcpy(mntdev, sstat->nfs.nfsmounts.nfsmnt[as->index].mountdev,
 3105                                 sizeof mntdev);
 3106 
 3107     if ( (ps = strchr(mntdev, ':')) )       // colon found?
 3108         ps++;
 3109     else
 3110         ps = mntdev;
 3111 
 3112     len = strlen(ps);
 3113         if (len > 12)
 3114         ps = ps + len - 12;
 3115 
 3116     sprintf(buf, "%12.12s", ps);
 3117         return buf;
 3118 }
 3119 
 3120 sys_printdef syspdef_NFMPATH = {"NFMPATH", sysprt_NFMPATH, NULL};
 3121 /*******************************************************************/
 3122 static char *
 3123 sysprt_NFMTOTREAD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3124 {
 3125         static char buf[16]="read   ";
 3126 
 3127         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].bytestotread,
 3128                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3129         return buf;
 3130 }
 3131 
 3132 sys_printdef syspdef_NFMTOTREAD = {"NFMTOTREAD", sysprt_NFMTOTREAD, NULL};
 3133 /*******************************************************************/
 3134 static char *
 3135 sysprt_NFMTOTWRITE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3136 {
 3137         static char buf[16]="write   ";
 3138 
 3139         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].bytestotwrite,
 3140                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3141         return buf;
 3142 }
 3143 
 3144 sys_printdef syspdef_NFMTOTWRITE = {"NFMTOTWRITE", sysprt_NFMTOTWRITE, NULL};
 3145 /*******************************************************************/
 3146 static char *
 3147 sysprt_NFMNREAD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3148 {
 3149         static char buf[16]="nread    ";
 3150 
 3151         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].bytesread,
 3152                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3153         return buf;
 3154 }
 3155 
 3156 sys_printdef syspdef_NFMNREAD = {"NFMNREAD", sysprt_NFMNREAD, NULL};
 3157 /*******************************************************************/
 3158 static char *
 3159 sysprt_NFMNWRITE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3160 {
 3161         static char buf[16]="nwrit    ";
 3162 
 3163         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].byteswrite,
 3164                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3165         return buf;
 3166 }
 3167 
 3168 sys_printdef syspdef_NFMNWRITE = {"NFMNWRITE", sysprt_NFMNWRITE, NULL};
 3169 /*******************************************************************/
 3170 static char *
 3171 sysprt_NFMDREAD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3172 {
 3173         static char buf[16]="dread    ";
 3174 
 3175         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].bytesdread,
 3176                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3177         return buf;
 3178 }
 3179 
 3180 sys_printdef syspdef_NFMDREAD = {"NFMDREAD", sysprt_NFMDREAD, NULL};
 3181 /*******************************************************************/
 3182 static char *
 3183 sysprt_NFMDWRITE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3184 {
 3185         static char buf[16]="dwrit    ";
 3186 
 3187         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].bytesdwrite,
 3188                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3189         return buf;
 3190 }
 3191 
 3192 sys_printdef syspdef_NFMDWRITE = {"NFMDWRITE", sysprt_NFMDWRITE, NULL};
 3193 /*******************************************************************/
 3194 static char *
 3195 sysprt_NFMMREAD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3196 {
 3197         static char buf[16]="mread    ";
 3198 
 3199         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].pagesmread *pagesize,
 3200                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3201         return buf;
 3202 }
 3203 
 3204 sys_printdef syspdef_NFMMREAD = {"NFMMREAD", sysprt_NFMMREAD, NULL};
 3205 /*******************************************************************/
 3206 static char *
 3207 sysprt_NFMMWRITE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3208 {
 3209         static char buf[16]="mwrit    ";
 3210 
 3211         val2memstr(sstat->nfs.nfsmounts.nfsmnt[as->index].pagesmwrite *pagesize,
 3212                 buf+6, KBFORMAT, as->avgval, as->nsecs);
 3213         return buf;
 3214 }
 3215 
 3216 sys_printdef syspdef_NFMMWRITE = {"NFMMWRITE", sysprt_NFMMWRITE, NULL};
 3217 /*******************************************************************/
 3218 static char *
 3219 sysprt_NFCRPCCNT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3220 {
 3221         static char buf[16]="rpc   ";
 3222         val2valstr(sstat->nfs.client.rpccnt,
 3223                    buf+4, 8, as->avgval, as->nsecs);
 3224         return buf;
 3225 }
 3226 
 3227 sys_printdef syspdef_NFCRPCCNT = {"NFCRPCCNT", sysprt_NFCRPCCNT, NULL};
 3228 /*******************************************************************/
 3229 static char *
 3230 sysprt_NFCRPCREAD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3231 {
 3232         static char buf[16]="read   ";
 3233         val2valstr(sstat->nfs.client.rpcread,
 3234                    buf+5, 7, as->avgval, as->nsecs);
 3235         return buf;
 3236 }
 3237 
 3238 sys_printdef syspdef_NFCRPCREAD = {"NFCRPCREAD", sysprt_NFCRPCREAD, NULL};
 3239 /*******************************************************************/
 3240 static char *
 3241 sysprt_NFCRPCWRITE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3242 {
 3243         static char buf[16]="write   ";
 3244         val2valstr(sstat->nfs.client.rpcwrite,
 3245                    buf+6, 6, as->avgval, as->nsecs);
 3246         return buf;
 3247 }
 3248 
 3249 sys_printdef syspdef_NFCRPCWRITE = {"NFCRPCWRITE", sysprt_NFCRPCWRITE, NULL};
 3250 /*******************************************************************/
 3251 static char *
 3252 sysprt_NFCRPCRET(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3253 {
 3254         static char buf[16]="retxmit ";
 3255         val2valstr(sstat->nfs.client.rpcretrans,
 3256                    buf+8, 4, as->avgval, as->nsecs);
 3257         return buf;
 3258 }
 3259 
 3260 sys_printdef syspdef_NFCRPCRET = {"NFCRPCRET", sysprt_NFCRPCRET, NULL};
 3261 /*******************************************************************/
 3262 static char *
 3263 sysprt_NFCRPCARF(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3264 {
 3265         static char buf[16]="autref  ";
 3266         val2valstr(sstat->nfs.client.rpcautrefresh,
 3267                    buf+7, 5, as->avgval, as->nsecs);
 3268         return buf;
 3269 }
 3270 
 3271 sys_printdef syspdef_NFCRPCARF = {"NFCRPCARF", sysprt_NFCRPCARF, NULL};
 3272 /*******************************************************************/
 3273 static char *
 3274 sysprt_NFSRPCCNT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3275 {
 3276         static char buf[16]="rpc   ";
 3277         val2valstr(sstat->nfs.server.rpccnt,
 3278                    buf+4, 8, as->avgval, as->nsecs);
 3279         return buf;
 3280 }
 3281 
 3282 sys_printdef syspdef_NFSRPCCNT = {"NFSRPCCNT", sysprt_NFSRPCCNT, NULL};
 3283 /*******************************************************************/
 3284 static char *
 3285 sysprt_NFSRPCREAD(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3286 {
 3287         static char buf[16]="cread   ";
 3288         val2valstr(sstat->nfs.server.rpcread,
 3289                    buf+6, 6, as->avgval, as->nsecs);
 3290         return buf;
 3291 }
 3292 
 3293 sys_printdef syspdef_NFSRPCREAD = {"NFSRPCREAD", sysprt_NFSRPCREAD, NULL};
 3294 /*******************************************************************/
 3295 static char *
 3296 sysprt_NFSRPCWRITE(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3297 {
 3298         static char buf[16]="cwrit   ";
 3299         val2valstr(sstat->nfs.server.rpcwrite,
 3300                    buf+6, 6, as->avgval, as->nsecs);
 3301         return buf;
 3302 }
 3303 
 3304 sys_printdef syspdef_NFSRPCWRITE = {"NFSRPCWRITE", sysprt_NFSRPCWRITE, NULL};
 3305 /*******************************************************************/
 3306 static char *
 3307 sysprt_NFSBADFMT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3308 {
 3309         static char buf[16]="badfmt   ";
 3310         val2valstr(sstat->nfs.server.rpcbadfmt,
 3311                    buf+7, 5, as->avgval, as->nsecs);
 3312         return buf;
 3313 }
 3314 
 3315 sys_printdef syspdef_NFSBADFMT = {"NFSBADFMT", sysprt_NFSBADFMT, NULL};
 3316 /*******************************************************************/
 3317 static char *
 3318 sysprt_NFSBADAUT(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3319 {
 3320         static char buf[16]="badaut   ";
 3321         val2valstr(sstat->nfs.server.rpcbadaut,
 3322                    buf+7, 5, as->avgval, as->nsecs);
 3323         return buf;
 3324 }
 3325 
 3326 sys_printdef syspdef_NFSBADAUT = {"NFSBADAUT", sysprt_NFSBADAUT, NULL};
 3327 /*******************************************************************/
 3328 static char *
 3329 sysprt_NFSBADCLN(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3330 {
 3331         static char buf[16]="badcln   ";
 3332         val2valstr(sstat->nfs.server.rpcbadcln,
 3333                    buf+7, 5, as->avgval, as->nsecs);
 3334         return buf;
 3335 }
 3336 
 3337 sys_printdef syspdef_NFSBADCLN = {"NFSBADCLN", sysprt_NFSBADCLN, NULL};
 3338 /*******************************************************************/
 3339 static char *
 3340 sysprt_NFSNETTCP(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3341 {
 3342         static char buf[16]="nettcp   ";
 3343         val2valstr(sstat->nfs.server.nettcpcnt,
 3344                    buf+7, 5, as->avgval, as->nsecs);
 3345         return buf;
 3346 }
 3347 
 3348 sys_printdef syspdef_NFSNETTCP = {"NFSNETTCP", sysprt_NFSNETTCP, NULL};
 3349 /*******************************************************************/
 3350 static char *
 3351 sysprt_NFSNETUDP(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3352 {
 3353         static char buf[16]="netudp   ";
 3354         val2valstr(sstat->nfs.server.netudpcnt,
 3355                    buf+7, 5, as->avgval, as->nsecs);
 3356         return buf;
 3357 }
 3358 
 3359 sys_printdef syspdef_NFSNETUDP = {"NFSNETUDP", sysprt_NFSNETUDP, NULL};
 3360 /*******************************************************************/
 3361 static char *
 3362 sysprt_NFSNRBYTES(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3363 {
 3364         static char buf[32]="MBcr/s ";
 3365 
 3366         sprintf(buf+7, "%5.1lf",
 3367         sstat->nfs.server.nrbytes / 1024.0 / 1024.0 / as->nsecs);
 3368 
 3369         return buf;
 3370 }
 3371 
 3372 sys_printdef syspdef_NFSNRBYTES = {"NFSNRBYTES", sysprt_NFSNRBYTES, NULL};
 3373 /*******************************************************************/
 3374 static char *
 3375 sysprt_NFSNWBYTES(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3376 {
 3377         static char buf[32]="MBcw/s ";
 3378 
 3379         sprintf(buf+7, "%5.1lf",
 3380         sstat->nfs.server.nwbytes / 1024.0 / 1024.0 / as->nsecs);
 3381 
 3382         return buf;
 3383 }
 3384 
 3385 sys_printdef syspdef_NFSNWBYTES = {"NFSNWBYTES", sysprt_NFSNWBYTES, NULL};
 3386 /*******************************************************************/
 3387 static char *
 3388 sysprt_NFSRCHITS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3389 {
 3390         static char buf[16]="rchits   ";
 3391         val2valstr(sstat->nfs.server.rchits,
 3392                    buf+8, 4, as->avgval, as->nsecs);
 3393         return buf;
 3394 }
 3395 
 3396 sys_printdef syspdef_NFSRCHITS = {"NFSRCHITS", sysprt_NFSRCHITS, NULL};
 3397 /*******************************************************************/
 3398 static char *
 3399 sysprt_NFSRCMISS(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3400 {
 3401         static char buf[16]="rcmiss   ";
 3402         val2valstr(sstat->nfs.server.rcmiss,
 3403                    buf+8, 4, as->avgval, as->nsecs);
 3404         return buf;
 3405 }
 3406 
 3407 sys_printdef syspdef_NFSRCMISS = {"NFSRCMISS", sysprt_NFSRCMISS, NULL};
 3408 /*******************************************************************/
 3409 static char *
 3410 sysprt_NFSRCNOCA(struct sstat *sstat, extraparam *as, int badness, int *color) 
 3411 {
 3412         static char buf[16]="rcnoca   ";
 3413         val2valstr(sstat->nfs.server.rcnoca,
 3414                    buf+8, 4, as->avgval, as->nsecs);
 3415         return buf;
 3416 }
 3417 
 3418 sys_printdef syspdef_NFSRCNOCA = {"NFSRCNOCA", sysprt_NFSRCNOCA, NULL};
 3419 /*******************************************************************/
 3420 static char *
 3421 sysprt_BLANKBOX(struct sstat *sstat, extraparam *notused, int badness, int *color) 
 3422 {
 3423         return "            ";
 3424 }
 3425 
 3426 sys_printdef syspdef_BLANKBOX = {"BLANKBOX", sysprt_BLANKBOX, NULL};