Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FreeMemReportControl.cc

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

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:40 2016 by Doxygen 1.6.3