pf_performance_timer.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef PF_PERFORMANCE_TIMER_HPP
00013 #define PF_PERFORMANCE_TIMER_HPP
00014
00015 extern uint64 ottd_rdtsc();
00016
00017 struct CPerformanceTimer
00018 {
00019 int64 m_start;
00020 int64 m_acc;
00021
00022 CPerformanceTimer() : m_start(0), m_acc(0) {}
00023
00024 FORCEINLINE void Start()
00025 {
00026 m_start = QueryTime();
00027 }
00028
00029 FORCEINLINE void Stop()
00030 {
00031 m_acc += QueryTime() - m_start;
00032 }
00033
00034 FORCEINLINE int Get(int64 coef)
00035 {
00036 return (int)(m_acc * coef / QueryFrequency());
00037 }
00038
00039 FORCEINLINE int64 QueryTime()
00040 {
00041 return ottd_rdtsc();
00042 }
00043
00044 FORCEINLINE int64 QueryFrequency()
00045 {
00046 return ((int64)2200 * 1000000);
00047 }
00048 };
00049
00050 struct CPerfStartReal
00051 {
00052 CPerformanceTimer *m_pperf;
00053
00054 FORCEINLINE CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf)
00055 {
00056 if (m_pperf != NULL) m_pperf->Start();
00057 }
00058
00059 FORCEINLINE ~CPerfStartReal()
00060 {
00061 Stop();
00062 }
00063
00064 FORCEINLINE void Stop()
00065 {
00066 if (m_pperf != NULL) {
00067 m_pperf->Stop();
00068 m_pperf = NULL;
00069 }
00070 }
00071 };
00072
00073 struct CPerfStartFake
00074 {
00075 FORCEINLINE CPerfStartFake(CPerformanceTimer& perf) {}
00076 FORCEINLINE ~CPerfStartFake() {}
00077 FORCEINLINE void Stop() {}
00078 };
00079
00080 typedef CPerfStartFake CPerfStart;
00081
00082 #endif