SimpleNGL 1.0
|
00001 #ifndef TIMER_H 00002 #define TIMER_H 00003 00006 00007 #include <iostream> 00008 #include <string> 00009 #include <sys/time.h> 00010 #include <cmath> 00011 00012 #include <map> 00013 00016 class Record 00017 { 00018 public: 00020 Record(); 00022 float m_secs; 00024 float m_best; 00026 float m_worst; 00028 float m_total; 00030 float m_cycles; 00032 timeval m_startT; 00034 timeval m_endT; 00035 }; 00036 00039 class Timer 00040 { 00041 public: 00043 Timer(); 00044 00047 void startCycle( const std::string &_recordName ); 00048 00051 void endCycle( const std::string &_recordName ); 00052 00055 inline float peek( const std::string &_recordName ) 00056 { 00057 Record r = m_records[_recordName]; 00058 gettimeofday(&(r.m_endT), NULL); 00059 00060 return ( r.m_endT.tv_sec - r.m_startT.tv_sec ) * 1000.0 + ( r.m_endT.tv_usec - r.m_startT.tv_usec ) / 1000.0; 00061 } 00062 00065 void addRecord( const std::string &_name ); 00066 00069 void reset( const std::string &_recordName ); 00070 00074 void writeToCSV( const std::string &_file, const std::string &_recordName ); 00075 00078 void writeAllToCSV(const std::string &_file ); 00079 00082 std::string getRecord( const std::string &_recordName ); 00083 00085 std::string getAll(); 00086 00087 private: 00089 std::map<std::string, Record> m_records; 00090 }; 00091 00092 #endif