| |
| |
| #ifndef T_STOPWATCH_INCLUDED |
| #define T_STOPWATCH_INCLUDED |
| |
| #include "tcommon.h" |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TNZCORE_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| #ifdef _WIN32 |
| #include "windows.h" |
| #endif |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifdef _WIN32 |
| |
| #define TM_TOTAL DWORD |
| #define TM_USER __int64 |
| #define TM_SYSTEM __int64 |
| #define START DWORD |
| #define START_USER FILETIME |
| #define START_SYSTEM FILETIME |
| #else |
| |
| #define TM_TOTAL clock_t |
| #define TM_USER clock_t |
| #define TM_SYSTEM clock_t |
| #define START clock_t |
| #define START_USER clock_t |
| #define START_SYSTEM clock_t |
| #endif |
| |
| class DVAPI TStopWatch |
| { |
| string m_name; |
| |
| TM_TOTAL m_tm; |
| TM_USER m_tmUser; |
| TM_SYSTEM m_tmSystem; |
| START m_start; |
| START_USER m_startUser; |
| START_SYSTEM m_startSystem; |
| |
| #ifdef WIN32 |
| LARGE_INTEGER m_hrStart; |
| #endif |
| |
| bool m_active; |
| bool m_isRunning; |
| |
| void setStartToCurrentTime(); |
| void getElapsedTime(TM_TOTAL &tm, TM_USER &user, TM_SYSTEM &system); |
| |
| public: |
| TStopWatch(string name = ""); |
| ~TStopWatch(); |
| |
| void reset(); |
| |
| |
| void start(bool resetFlag = false); |
| void stop(); |
| |
| |
| |
| TUINT32 getTotalTime(); |
| |
| |
| TUINT32 getUserTime(); |
| |
| |
| TUINT32 getSystemTime(); |
| |
| const string &getName() { return m_name; }; |
| void setName(string name) { m_name = name; }; |
| |
| |
| operator string(); |
| |
| |
| void print(ostream &out); |
| void print(); |
| |
| private: |
| static TStopWatch StopWatch[10]; |
| |
| public: |
| |
| |
| |
| static TStopWatch &global(int index) |
| { |
| assert(0 <= index && index < 10); |
| return StopWatch[index]; |
| }; |
| |
| |
| |
| |
| |
| static void printGlobals(ostream &out); |
| static void printGlobals(); |
| }; |
| |
| |
| |
| #endif |
| |