"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/gnu/memmeter.cc" (11 Jul 2020, 1741 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 "memmeter.cc" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.18_vs_1.19.

    1 //
    2 //  Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov )
    3 //  2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org )
    4 //
    5 //  This file may be distributed under terms of the GPL
    6 //
    7 
    8 #include "memmeter.h"
    9 #include "xosview.h"
   10 #include <fstream>
   11 #include <sstream>
   12 #include <stdlib.h>
   13 #include <error.h>
   14 
   15 extern "C" {
   16 #include <mach/mach_traps.h>
   17 #include <mach/mach_interface.h>
   18 }
   19 
   20 MemMeter::MemMeter( XOSView *parent )
   21 : FieldMeterGraph( parent, 4, "MEM", "ACT/INACT/WIRE/FREE" ){
   22 }
   23 
   24 MemMeter::~MemMeter( void ){
   25 }
   26 
   27 void MemMeter::checkResources( void ){
   28   FieldMeterGraph::checkResources();
   29 
   30   setfieldcolor( 0, parent_->getResource( "memActiveColor" ) );
   31   setfieldcolor( 1, parent_->getResource( "memInactiveColor" ) );
   32   setfieldcolor( 2, parent_->getResource( "memCacheColor" ) );
   33   setfieldcolor( 3, parent_->getResource( "memFreeColor" ) );
   34   priority_ = atoi (parent_->getResource( "memPriority" ) );
   35   dodecay_ = parent_->isResourceTrue( "memDecay" );
   36   useGraph_ = parent_->isResourceTrue( "memGraph" );
   37   SetUsedFormat (parent_->getResource("memUsedFormat"));
   38 }
   39 
   40 void MemMeter::checkevent( void ){
   41   getmeminfo();
   42   drawfields();
   43 }
   44 
   45 void MemMeter::getmeminfo( void ){
   46   kern_return_t err;
   47 
   48   err = vm_statistics (mach_task_self(), &vmstats);
   49   if (err) {
   50     error (0, err, "vm_statistics");
   51     parent_->done(1);
   52     return;
   53   }
   54 
   55   fields_[0] = (double) vmstats.active_count * vmstats.pagesize;
   56   fields_[1] = (double) vmstats.inactive_count * vmstats.pagesize;;
   57   fields_[2] = (double) vmstats.wire_count * vmstats.pagesize;;
   58   fields_[3] = (double) vmstats.free_count * vmstats.pagesize;;
   59   total_ = fields_[0] + fields_[1] + fields_[2] + fields_[3];
   60 
   61   FieldMeterDecay::setUsed (total_ - fields_[3], total_);
   62 }