Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FreeMemReportControl.cc

Go to the documentation of this file.
00001 #include "FreeMemReportControl.h"
00002 #ifdef PLATFORM_APERIOS
00003 #  include <AnalyzerAPI.h>
00004 #  include <AnalyzerError.h>
00005 #endif
00006 
00007 void FreeMemReportControl::processEvent(const EventBase& e) {
00008   ASSERTRET(e.getGeneratorID()==EventBase::timerEGID,"Unexpected event");
00009   if(e.getSourceID()==0) {
00010     report();
00011   } else if(e.getSourceID()==1) {
00012     size_t freemem=freeMem();
00013     if(freemem<low_mem) {
00014       if(!isWarning) {
00015         isWarning=true;
00016         serr->printf("WARNING: Low memory: %lu\n",(unsigned long)freemem);
00017       }
00018     } else {
00019       if(isWarning) {
00020         isWarning=false;
00021         report();
00022       }
00023     }
00024   } else
00025     ASSERT(false,"Unexpected timer event");
00026 }
00027   
00028 void FreeMemReportControl::refresh() {
00029   char tmp[256];
00030   sprintf(tmp,"Free Mem: %lu",(unsigned long)freeMem());
00031   options[1]->setName(tmp);
00032   ControlBase::refresh();
00033   report();
00034 }
00035 
00036 
00037 //! reports size of free memory - if this is below low_mem, also generates a warning
00038 void FreeMemReportControl::report() {
00039   size_t freemem=freeMem();
00040   sout->printf("%lu bytes free\n",(unsigned long)freemem);
00041   if(freemem<low_mem)
00042     if(isWarning)
00043       serr->printf("WARNING: Low memory: %lu\n",(unsigned long)freemem);
00044   resetTimerFreq();
00045 }
00046 
00047 //! returns the size of the free memory
00048 size_t FreeMemReportControl::freeMem() {
00049   size_t freemem;
00050 #ifdef PLATFORM_APERIOS
00051   if (AnalyzerGetSizeOfFreeMemory(&freemem)!=azrSUCCESS)
00052     sout->printf("Aperios error: getsizeoffreememory failed\n");
00053 #else
00054   freemem=-1U;
00055 #endif
00056   return freemem;
00057 }
00058 
00059 void FreeMemReportControl::resetTimerFreq() {
00060   if(report_freq<0)
00061     erouter->removeTimer(this,0);
00062   else
00063     erouter->addTimer(this,0,report_freq,true);
00064   erouter->addTimer(this,1,monitor_freq,true);
00065 }
00066 
00067 /*! @file
00068  * @brief Implements FreeMemReportControl, which gives reports on free memory size at various (configurable) rates
00069  * @author ejt (object), alokl (core function)
00070  *
00071  * $Author: ejt $
00072  * $Name: tekkotsu-2_4_1 $
00073  * $Revision: 1.6 $
00074  * $State: Exp $
00075  * $Date: 2005/02/05 07:27:26 $
00076  */
00077 

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:47 2005 by Doxygen 1.4.4