afProfiler.h
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:1k
源码类别:

其他游戏

开发平台:

Visual C++

  1. #ifndef AF_PROFILE
  2. #define AF_PROFILE
  3. #include "afList.h"
  4. #include "afString.h"
  5. #include <windows.h>
  6. /// afProfiler provides precise profiling methods
  7. /**
  8.  *  afProfiler uses the processors VERY HIGH PRECISSION
  9.  *  timer functions, which are precise enough to bench
  10.  *  even single assembler commands...
  11.  */
  12. class afProfiler
  13. {
  14. public:
  15. afProfiler(const char* nName);
  16. ~afProfiler();
  17. void beginSection();
  18. void endSection();
  19. static void logResult();
  20. protected:
  21. static bool globalBegin();
  22. static bool globalEnd();
  23. int listIndex;
  24. LARGE_INTEGER beginTime;
  25. struct ProfileInfo
  26. {
  27. public:
  28. afString name;
  29. LARGE_INTEGER time;
  30. };
  31. friend bool operator==(const ProfileInfo&, const ProfileInfo&) 
  32. {  return false;  }
  33. static afList<ProfileInfo> timerList;
  34. static LARGE_INTEGER globalBeginTime;
  35. };
  36. inline void afProfiler::beginSection()
  37. {
  38. QueryPerformanceCounter(&beginTime);
  39. }
  40. inline void
  41. afProfiler::endSection()
  42. {
  43. LARGE_INTEGER& time = timerList.getAt(listIndex).time;
  44. LARGE_INTEGER tmpTime;
  45. QueryPerformanceCounter(&tmpTime);
  46. time.QuadPart += tmpTime.QuadPart - beginTime.QuadPart;
  47. }
  48. #endif