00001 #ifndef __GXPROFILER_H 00002 #define __GXPROFILER_H 00003 00004 00005 #include "GXStandardDefines.h" 00006 #include "GXHashTable.h" 00007 #include "GXHashableString.h" 00008 00009 struct GXProfileElement 00010 { 00011 public: 00012 00013 CGXHashableString sFunctionName; 00014 __int64 i64StartTick; 00015 __int64 iCallCount; 00016 00017 float fSecondCount; 00018 00019 00020 00021 00022 public: 00023 GXProfileElement() 00024 { 00025 i64StartTick=0; 00026 iCallCount=0; 00027 fSecondCount=0.0f; 00028 } 00029 00030 00031 bool operator==(GXProfileElement& Target) 00032 { 00033 return sFunctionName==Target.sFunctionName; 00034 } 00035 00036 00037 UINT HashCode() 00038 { 00039 return sFunctionName.HashCode(); 00040 } 00041 00042 00043 bool Assign(GXProfileElement& Source) 00044 { 00045 if(!sFunctionName.Assign(Source.sFunctionName)) 00046 { 00047 return false; 00048 } 00049 i64StartTick=Source.i64StartTick; 00050 iCallCount=Source.iCallCount; 00051 fSecondCount=Source.fSecondCount; 00052 00053 return true; 00054 } 00055 00056 00057 00058 }; 00059 00060 00061 00062 00063 00064 class CGXProfiler 00065 { 00066 public: 00067 CGXProfiler(); 00068 virtual ~CGXProfiler(); 00069 00070 virtual bool Init(); 00071 00072 virtual bool FunctionEnter(char* szFunctionName);//not thread safe!!! 00073 virtual bool FunctionExit(); 00074 00075 00076 virtual void IteratorFirst(); 00077 virtual bool IteratorHasMore(); 00078 virtual bool IteratorNext(GXProfileElement* pOut); 00079 00080 protected: 00081 static __int64 x_i64TicksPerSecond; 00082 CGXHashTable<GXProfileElement> m_HashTable; 00083 00084 GXProfileElement m_CurrentFunctionElement; 00085 }; 00086 00087 00088 00089 00090 __int64 GetCurrentTick(); 00091 __int64 GetTicksPerSecond(); 00092 00093 00094 00095 00096 00097 #endif