Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.5 KiB

  1. #define _100NS_IN_MS (10*1000)
  2. #define NANOSECONDS 10000000
  3. #define CONVERT_PERFORMANCE_TIME(Frequency, PerformanceTime) \
  4. ((((ULONGLONG)(ULONG)(PerformanceTime).HighPart * NANOSECONDS / (Frequency)) << 32) + \
  5. ((((((ULONGLONG)(ULONG)(PerformanceTime).HighPart * NANOSECONDS) % (Frequency)) << 32) + \
  6. ((ULONGLONG)(PerformanceTime).LowPart * NANOSECONDS)) / (Frequency)))
  7. #ifdef DEBUG
  8. #include "trace.h"
  9. #define VIDPERF(Y,X) CPerfVidCtl __cperfvidctl(Y,X);
  10. #define VIDPERF_FUNC CPerfVidCtl __cperfvidctl(TRACE_ERROR, __FUNCTION__);
  11. #define VIDPERF_FUNC2 CPerfVidCtl __cperfvidctl(TRACE_ALWAYS, __FUNCTION__);
  12. class CPerfCounter
  13. /*++
  14. Abstract:
  15. This provides a simple performace counter. Simply call Start() to
  16. start counting. Calling Stop() will spit out the results. You can
  17. optional specify a name for your counter.
  18. Author:
  19. Sam Clement (samclem) 24-Feb-2000
  20. Bryan A. Woodruff (bryanw) 10-Jun-2001
  21. Refactored for use with IOTest
  22. Luke W. McCullough (LukeM) 01-Jan-2002
  23. Added VidCtl Specific Class and Debug state
  24. --*/
  25. {
  26. public:
  27. CPerfCounter() : m_Name(NULL) { _Setup(); }
  28. explicit CPerfCounter(const char* Name) : m_Name(Name) { _Setup(); }
  29. ~CPerfCounter() {}
  30. void _Setup()
  31. {
  32. ZeroMemory(&m_StartTime, sizeof(m_StartTime));
  33. ZeroMemory(&m_CurrentTime, sizeof(m_CurrentTime));
  34. ZeroMemory(&m_CounterFreq, sizeof(m_CounterFreq));
  35. QueryPerformanceFrequency(&m_CounterFreq);
  36. QueryPerformanceCounter(&m_StartTime);
  37. }
  38. void Reset()
  39. {
  40. QueryPerformanceCounter(&m_StartTime);
  41. }
  42. LONGLONG Stop()
  43. {
  44. QueryPerformanceCounter(&m_CurrentTime);
  45. m_CurrentTime.QuadPart = m_CurrentTime.QuadPart - m_StartTime.QuadPart;
  46. m_CurrentTime.QuadPart = CONVERT_PERFORMANCE_TIME(m_CounterFreq.QuadPart, m_CurrentTime);
  47. return m_CurrentTime.QuadPart;
  48. }
  49. LONGLONG GetLastTime()
  50. {
  51. return m_CurrentTime.QuadPart;
  52. }
  53. void Trace()
  54. {
  55. Stop();
  56. (void)StringCchPrintfA(m_Outbuf, sizeof(m_Outbuf) / sizeof(m_Outbuf[0]), "\n*\n* PerfCounter: %s%s%s%ld ms\n*\n",
  57. (m_Name ? "(" : ""),
  58. (m_Name ? m_Name : ""),
  59. (m_Name ? ") " : ""),
  60. (m_CurrentTime.QuadPart / _100NS_IN_MS));
  61. puts( m_Outbuf );
  62. }
  63. private:
  64. LARGE_INTEGER m_StartTime;
  65. LARGE_INTEGER m_CurrentTime;
  66. LARGE_INTEGER m_CounterFreq;
  67. const char* m_Name;
  68. char m_Outbuf[MAX_PATH];
  69. };
  70. class CPerfVidCtl : public CPerfCounter{
  71. private:
  72. char* dbString;
  73. DWORD traceLevel;
  74. public:
  75. CPerfVidCtl(DWORD tLevel, char *debugString){
  76. traceLevel = tLevel;
  77. dbString = new char[strlen(debugString)+1];
  78. lstrcpynA(dbString, debugString, strlen(debugString)+1);
  79. _Setup();
  80. Reset();
  81. TRACELSM(traceLevel, (dbgDump << dbString << " : Start"), "");
  82. }
  83. ~CPerfVidCtl(){
  84. if(!!dbString){
  85. LONGLONG curTime = Stop();
  86. TRACELSM(traceLevel, (dbgDump << dbString << " : End :" << (unsigned long)(curTime / _100NS_IN_MS) << "." << (unsigned long)(curTime % _100NS_IN_MS) << " ms"), "");
  87. }
  88. delete[] dbString;
  89. }
  90. };
  91. #else
  92. //
  93. // No perf counter. Make it an empty object (should be optimized out)
  94. //
  95. class CPerfCounter
  96. {
  97. public:
  98. inline CPerfCounter() {}
  99. inline explicit CPerfCounter(const char* Name) {}
  100. inline ~CPerfCounter() {}
  101. inline void Reset() {}
  102. inline LONGLONG Stop() { return 0; }
  103. inline LONGLONG GetLastTime() { return 0; }
  104. inline void Trace() {}
  105. };
  106. #define VIDPERF(X,Y)
  107. #define VIDPERF_FUNC
  108. #endif