Tekkotsu 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 (%+ld)\n",(unsigned long)freemem,(long)(freemem-lastReport));
00041   lastReport=freemem;
00042   if(freemem<low_mem)
00043     if(isWarning)
00044       serr->printf("WARNING: Low memory: %lu\n",(unsigned long)freemem);
00045   resetTimerFreq();
00046 }
00047 
00048 //! returns the size of the free memory
00049 size_t FreeMemReportControl::freeMem() {
00050   size_t freemem;
00051 #ifdef PLATFORM_APERIOS
00052   if (AnalyzerGetSizeOfFreeMemory(&freemem)!=azrSUCCESS)
00053     sout->printf("Aperios error: getsizeoffreememory failed\n");
00054 #else
00055   freemem=-1U;
00056 #endif
00057   return freemem;
00058 }
00059 
00060 void FreeMemReportControl::resetTimerFreq() {
00061   if(report_freq<0)
00062     erouter->removeTimer(this,0);
00063   else
00064     erouter->addTimer(this,0,report_freq,true);
00065   erouter->addTimer(this,1,monitor_freq,true);
00066 }
00067 
00068 /*! @file
00069  * @brief Implements FreeMemReportControl, which gives reports on free memory size at various (configurable) rates
00070  * @author ejt (object), alokl (core function)
00071  *
00072  * $Author: ejt $
00073  * $Name: tekkotsu-4_0 $
00074  * $Revision: 1.7 $
00075  * $State: Exp $
00076  * $Date: 2006/09/25 23:26:56 $
00077  */
00078 

Tekkotsu v4.0
Generated Thu Nov 22 00:54:53 2007 by Doxygen 1.5.4