"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/sunos5/MeterMaker.cc" (11 Jul 2020, 2045 Bytes) of package /linux/misc/xosview-1.23.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 "MeterMaker.cc" see the Fossies "Dox" file reference documentation.

    1 //  
    2 //  Initial port performed by Greg Onufer (exodus@cheers.bungi.com)
    3 //
    4 
    5 #include "MeterMaker.h"
    6 #include "xosview.h"
    7 #include "kstats.h"
    8 #include "cpumeter.h"
    9 #include "memmeter.h"
   10 #include "swapmeter.h"
   11 #include "loadmeter.h"
   12 #include "pagemeter.h"
   13 #include "diskmeter.h"
   14 #include "netmeter.h"
   15 #include "intratemeter.h"
   16 #include <string.h>
   17 #include <stdlib.h>
   18 #include <unistd.h>
   19 
   20 
   21 MeterMaker::MeterMaker(XOSView *xos)
   22 {
   23   _xos = xos;
   24 }
   25 
   26 void MeterMaker::makeMeters(void)
   27 {
   28   kstat_ctl_t *kc;
   29 
   30   kc = kstat_open();
   31   if (kc == NULL)
   32     return;
   33 
   34   if (_xos->isResourceTrue("load"))
   35     push(new LoadMeter(_xos, kc));
   36 
   37   // Standard meters (usually added, but users could turn them off)
   38   if (_xos->isResourceTrue("cpu")) {
   39     bool single, both, all;
   40     int cpuCount = sysconf(_SC_NPROCESSORS_ONLN);
   41 
   42     single = (strncmp(_xos->getResource("cpuFormat"), "single", 2) == 0);
   43     both = (strncmp(_xos->getResource("cpuFormat"), "both", 2) == 0);
   44     all = (strncmp(_xos->getResource("cpuFormat"), "all", 2) == 0);
   45 
   46     if (strncmp(_xos->getResource("cpuFormat"), "auto", 2) == 0) {
   47       if (cpuCount == 1 || cpuCount > 4)
   48         single = true;
   49       else
   50         all = true;
   51     }
   52 
   53     if (single || both)
   54       push(new CPUMeter(_xos, kc, -1));
   55 
   56     if (all || both) {
   57       KStatList *cpulist = KStatList::getList(kc, KStatList::CPU_STAT);
   58       for (unsigned int i = 0; i < cpulist->count(); i++)
   59         push(new CPUMeter(_xos, kc, (*cpulist)[i]->ks_instance));
   60     }
   61   }
   62 
   63   if (_xos->isResourceTrue("mem"))
   64     push(new MemMeter(_xos, kc));
   65 
   66   if (_xos->isResourceTrue("disk"))
   67     push(new DiskMeter(_xos, kc, atof(_xos->getResource("diskBandwidth"))));
   68 
   69   if (_xos->isResourceTrue("swap"))
   70     push(new SwapMeter(_xos, kc));
   71 
   72   if (_xos->isResourceTrue("page"))
   73     push(new PageMeter(_xos, kc, atof(_xos->getResource("pageBandwidth"))));
   74 
   75   if (_xos->isResourceTrue("net"))
   76     push(new NetMeter(_xos, kc, atof(_xos->getResource("netBandwidth"))));
   77 
   78   if (_xos->isResourceTrue("irqrate"))
   79     push(new IrqRateMeter(_xos, kc));
   80 }