LAMA
|
00001 00033 #ifndef LAMA_LAMASIMPLETIMETRACER_HPP_ 00034 #define LAMA_LAMASIMPLETIMETRACER_HPP_ 00035 00036 // for dll_import 00037 #include <lama/config.hpp> 00038 00039 // base classes 00040 #include <lama/tracing/LAMABaseTracer.hpp> 00041 00042 #include <list> 00043 #include <string> 00044 #include <boost/thread/mutex.hpp> 00045 #include <omp.h> 00046 00051 class LAMASimpleTimeTracer : public LAMABaseTracer 00052 { 00053 public: 00054 00055 inline LAMASimpleTimeTracer(const char* name, const char* file, int lno); 00056 00057 inline ~LAMASimpleTimeTracer(); 00058 00059 /* be careful this is the spentLastTime since the last call of this function, */ 00060 /* not only the one of the last function call */ 00061 static double spentLast( const char* name ) ; 00062 00063 static void printTimer(); 00064 00065 private: 00066 00067 static std::list<std::pair<std::string,double> > timerList; 00068 00069 static boost::mutex access_mutex; // needed to make time thread-safe 00070 00071 const std::string mName; 00072 00073 double mStopTime; 00074 00075 const double mStartTime; // mStartTime should be initialized last 00076 }; 00077 00078 inline LAMASimpleTimeTracer::LAMASimpleTimeTracer(const char* name, const char* /*file*/, int /*lno*/) 00079 : mName(name), mStopTime(0.0), mStartTime( omp_get_wtime() ) 00080 { 00081 } 00082 00083 inline LAMASimpleTimeTracer::~LAMASimpleTimeTracer() 00084 { 00085 mStopTime = omp_get_wtime(); 00086 00087 double runTime = mStopTime - mStartTime; 00088 if ( getRuntime() > 0.0 ) 00089 { 00090 runTime = getRuntime(); 00091 } 00092 00093 std::pair<std::string,double> value = std::make_pair( mName, runTime ); 00094 { 00095 boost::mutex::scoped_lock scoped_lock( access_mutex ); 00096 timerList.push_back( value ); 00097 } 00098 } 00099 00100 #endif // LAMA_LAMASIMPLETIMETRACER_HPP_