Homepage Demos Overview Downloads Tutorials Reference
Credits

FreeMemReportControl.cc

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

Tekkotsu v2.2
Generated Tue Oct 19 14:19:14 2004 by Doxygen 1.3.9.1