LAMA
/home/brandes/workspace/LAMA/src/lama/tracing/RegionTable.hpp
Go to the documentation of this file.
00001 
00034 #ifndef LAMA_REGION_TABLE_HPP_
00035 #define LAMA_REGION_TABLE_HPP_
00036 
00037 // for dll_import
00038 #include <lama/config.hpp>
00039 
00040 // others
00041 #include <lama/task/Thread.hpp>
00042 
00043 // logging
00044 #include <logging/logging.hpp>
00045 
00046 #include <cstring>
00047 #include <cstdio>
00048 #include <vector>
00049 #include <map>
00050 
00051 namespace tracing
00052 {
00053 
00074 class LAMA_DLL_IMPORTEXPORT RegionTable
00075 {
00076 
00077 public:
00078 
00084     RegionTable( lama::Thread::Id threadId );
00085 
00088     ~RegionTable();
00089 
00092     lama::Thread::Id getId() const
00093     {
00094         return mThreadId;
00095     }
00096 
00104     int getRegion( const char* id, const char* file, int lno );
00105 
00108     void init();
00109 
00112     void start( int regionId, double wallTime );
00113 
00120     void stop( int regionId, double wallTime );
00121 
00124     void stop( const char* regionName, double wallTime );
00125 
00130     double elapsed( int regionId );
00131 
00134     double spent( int regionId );
00135 
00138     double spentExclusive( int regionId );
00139 
00142     double spentLast( int regionId );
00143 
00146     const char* getName( int regionId );
00147 
00150     void printTimer();
00151 
00152     void printTimer( FILE* f );
00153 
00154 private:
00155 
00156     LAMA_LOG_DECL_STATIC_LOGGER( logger );
00157 
00158     struct CmpString
00159     {
00160         bool operator()( const char* a, const char* b ) const
00161         {
00162             return std::strcmp( a, b) < 0;
00163         }
00164     };
00165 
00168     struct RegionEntry
00169     {
00170         RegionEntry() 
00171         {
00172             mLastTime      = 0.0;
00173             mInclusiveTime = 0.0;
00174             mExclusiveTime = 0.0;
00175             mCalls         = 0;
00176         }
00177 
00178         double mLastTime;         // time of last call 
00179         double mInclusiveTime;    // time totally spent in a region
00180         double mExclusiveTime;    // time exclusively spent in a region
00181 
00182         std::string mName;
00183 
00184         const char* mFile;
00185         int mLine;
00186 
00187         int mCalls;
00188     };
00189 
00192     struct CallEntry
00193     {
00194         CallEntry( int region, double timeStart )
00195         {
00196             mRegion = region;
00197             mTimeStart = timeStart;
00198         }
00199 
00200         int mRegion;        
00201         double mTimeStart;  
00202     };
00203 
00204     std::vector<CallEntry> callStack;
00205 
00206     std::vector<RegionEntry> array;   
00207 
00208     lama::Thread::Id mThreadId;
00209 
00216     std::map<const char*, int, CmpString> mapTimer;  
00217 };
00218 
00219 }
00220 
00221 #endif //LAMA_REGION_TABLE_HPP_