Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

Reporter.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_ImageSet_Reporter_h
00002 #define Impala_Core_ImageSet_Reporter_h
00003 
00004 #include "Basis/CmdOptions.h"
00005 #include "Basis/Timer.h"
00006 #include "Core/ImageSet/Listener.h"
00007 #include "Core/ImageSet/ImageSet.h"
00008 
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace ImageSet
00014 {
00015 
00016 
00024 class Reporter : public Listener
00025 {
00026 public:
00027 
00028     Reporter(Reporter* master)
00029     {
00030         mMaster = master;
00031         CmdOptions& options = CmdOptions::GetInstance();
00032         mReport = options.GetInt("report");
00033         mNrDone = 0;
00034         mReportArray = true;
00035         mAllocUsageStart = Array::ArraySystem::Instance().AllocUsage();
00036     }
00037 
00038     virtual void
00039     HandleNewWalk(ImageSet* is)
00040     {
00041         if (mMaster)
00042             ILOG_DEBUG("..   new walk");
00043     }
00044 
00045     virtual void
00046     HandleNewWalk(ImageSet* is, int nrBookmarks)
00047     {
00048         if (mMaster)
00049             ILOG_DEBUG("..   new walk, nrBookmarks = " << nrBookmarks);
00050         mNrBookmarks = nrBookmarks;
00051     }
00052 
00053     virtual void
00054     HandleNewDir(ImageSet* is, int dirId)
00055     {
00056         if (mMaster)
00057             ILOG_DEBUG("..   new dir id = " << dirId);
00058     }
00059 
00060     virtual void
00061     HandleDoneDir(ImageSet* is, int dirId)
00062     {
00063         if (mMaster)
00064         {
00065             ILOG_INFO("..   done dir id = " << dirId);
00066             if (mReportArray)
00067             {
00068                 int usage = Array::ArraySystem::Instance().AllocUsage();
00069                 ILOG_INFO("Alloc usage = " << usage - mAllocUsageStart);
00070             }
00071         }
00072     }
00073 
00074     virtual void
00075     HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im)
00076     {
00077         if (mMaster)
00078             ILOG_DEBUG("..   new file id = " << fileId);
00079         if (mMaster)
00080         {
00081             mMaster->AllDoneFile();
00082             return;
00083         }
00084         mDoPrint = false;
00085         mNrDone++;
00086         if ((mReport > 0) && (mNrDone % mReport == 0))
00087             mDoPrint = true;
00088         if (mDoPrint)
00089         {
00090             int nrFiles = is->NrFiles();
00091             int perc = (int) (((double) fileId / (double) nrFiles) * 100);
00092             ILOG_INFO("--   file " << fileId << " of " << nrFiles
00093                       << " (at " << perc << "%); did " << mNrDone);
00094         }
00095         Array::ArraySystem::Instance().MarkMemoryUsage(false);
00096     }
00097 
00098     virtual void
00099     HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im,
00100                   Geometry::Rectangle rect, String anno)
00101     {
00102         if (mMaster)
00103             ILOG_DEBUG("..   new file id = " << fileId);
00104         if (mMaster)
00105         {
00106             mMaster->AllDoneFile();
00107             return;
00108         }
00109         mDoPrint = false;
00110         mNrDone++;
00111         if ((mReport > 0) && (mNrDone % mReport == 0))
00112             mDoPrint = true;
00113         if (mDoPrint)
00114         {
00115             int nrFiles = mNrBookmarks;
00116             int perc = (int) (((double)mNrDone / (double)nrFiles) * 100);
00117             ILOG_INFO("--   file " << mNrDone << " of " << nrFiles
00118                       << " (at " << perc << "%)");
00119         }
00120         Array::ArraySystem::Instance().MarkMemoryUsage(false);
00121     }
00122 
00123     virtual void
00124     HandleDoneWalk(ImageSet* is)
00125     {
00126         if (mMaster)
00127             ILOG_DEBUG("..   done walk");
00128     }
00129 
00130     virtual void
00131     HandleDoneWalk(ImageSet* is, int nrBookmarks)
00132     {
00133         if (mMaster)
00134             ILOG_DEBUG("..   done walk, nrBookmarks = " << nrBookmarks);
00135     }
00136 
00137     void
00138     SetReportArray(bool flag)
00139     {
00140         mReportArray = flag;
00141     }
00142 
00143     void
00144     FinalReport()
00145     {
00146         ILOG_INFO("DONE time total=" << mTimerTotal.SplitTime()
00147                   << " error=" << ILOG_ERROR_COUNT);
00148     }
00149 
00150     bool
00151     DoPrint()
00152     {
00153         return mDoPrint;
00154     }
00155 
00156 private:
00157 
00158     void
00159     AllDoneFile()
00160     {
00161         if (mReportArray)
00162             Array::ArraySystem::Instance().CheckMemoryUsageSinceMark(false);
00163         if (mDoPrint)
00164         {
00165             ILOG_INFO("++ avg time=" << mTimerReport.SplitTimeStr(mReport)
00166                       << " total=" << mTimerTotal.SplitTimeStr()
00167                       << " error=" << ILOG_ERROR_COUNT);
00168             mTimerReport.Start();
00169         }
00170     }
00171 
00172     Reporter*   mMaster;
00173     int         mReport;
00174     int         mNrDone;
00175     bool        mReportArray;
00176     int         mAllocUsageStart;
00177     Timer       mTimerTotal;
00178     Timer       mTimerReport;
00179     bool        mDoPrint;
00180     int         mNrBookmarks;
00181 
00182     ILOG_VAR_DEC;
00183 };
00184 
00185 ILOG_VAR_INIT(Reporter, Impala.Core.ImageSet);
00186 
00187 } // namespace ImageSet
00188 } // namespace Core
00189 } // namespace Impala
00190 
00191 #endif

Generated on Thu Jan 13 09:04:31 2011 for ImpalaSrc by  doxygen 1.5.1