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.

151 lines
4.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: PerfMacs.h
  6. * Content: Performance Instrumentation macros.
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 03/21/01 RichGr Created
  13. *
  14. * Usage:
  15. * As Whistler/XP and DX 8.1 are now locked down for beta 2, this should
  16. * not be included as part of the official builds. So just include this file
  17. * temporarily when you need to instrument some functions.
  18. * Specify these macros before and after what you want to time:
  19. START_QPC
  20. DoSomeWork
  21. END_QPC
  22. * Then temporarily change dndbg.cpp by replacing
  23. this:
  24. #include "dndbg.h"
  25. #include "memlog.h"
  26. #if defined(DEBUG)
  27. with this:
  28. #if defined(DPINST) && !defined(DEBUG)
  29. #define DEBUG
  30. #include "dndbg.h"
  31. #include "memlog.h"
  32. #undef DEBUG
  33. #else
  34. #include "dndbg.h"
  35. #include "memlog.h"
  36. #endif
  37. #if defined(DEBUG) || defined(DPINST)
  38. * To build the instrumented binaries, set C_DEFINES=-DDPINST in your razzle build
  39. * environment. Both free and checked builds can be instrumented. If you want to
  40. * put the bins in a different directory, set BUILD_ALT_DIR=i where 'i' is the character
  41. * you want to append to \obj.
  42. *
  43. * To get useful results, you will usually need to use the shared memory
  44. * log option (log=2 in win.ini) and run free binaries. If you run the checked
  45. * binaries, you should keep the amount of debug output low.
  46. *
  47. *
  48. ***************************************************************************/
  49. #ifndef __PERFMACS_H__
  50. #define __PERFMACS_H__
  51. #ifdef DEBUG
  52. #define DPINST
  53. #endif
  54. #ifdef DPINST
  55. #pragma message("DPINST is defined and binaries are instrumented")
  56. #define DPINST_CRITSEC FALSE // Specify TRUE or FALSE
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. //**********************************************************************
  61. // Constant definitions
  62. //**********************************************************************
  63. // #undef and #define this again before the code you're timing
  64. // if you want to change the logging threshold.
  65. #define QPC_THRESHOLD 10 // 10 usecs
  66. //**********************************************************************
  67. // Macro definitions
  68. //**********************************************************************
  69. // To provide local scope for n64QPCStart and n64QPCEnd, QPC_START has
  70. // an unbalanced open { and QPC_END has the balancing close }.
  71. #define START_QPC \
  72. { \
  73. __int64 n64QPCStart, n64QPCEnd, n64QPCDiff; \
  74. if (g_bQPC_Not_Inited) \
  75. { \
  76. QueryPerformanceFrequency((LARGE_INTEGER*)&g_n64QPCFrequency); \
  77. g_bQPC_Not_Inited = FALSE; \
  78. } \
  79. QueryPerformanceCounter((LARGE_INTEGER*)&n64QPCStart);
  80. // a) We can handle wraps.
  81. // b) Below a certain threshold, we don't want to log the elapsed time.
  82. // c) We don't compensate for thread switches.
  83. #define END_QPC \
  84. QueryPerformanceCounter((LARGE_INTEGER*)&n64QPCEnd); \
  85. if (n64QPCEnd >= n64QPCStart) \
  86. n64QPCDiff = n64QPCEnd - n64QPCStart; \
  87. else \
  88. n64QPCDiff = (0x7fffffffffffffff - n64QPCStart) + 1 + n64QPCEnd; \
  89. n64QPCDiff = n64QPCDiff * 1000000 / g_n64QPCFrequency; \
  90. if (n64QPCDiff < 0) \
  91. n64QPCDiff = 0; \
  92. if (n64QPCDiff >= QPC_THRESHOLD) \
  93. DebugPrintfX(__FILE__, __LINE__, DPF_MODNAME, DPF_SUBCOMP, DPF_ERRORLEVEL, "%d usecs", (DWORD)n64QPCDiff); \
  94. }
  95. //**********************************************************************
  96. // Redefinitions of existing macros
  97. //**********************************************************************
  98. #if DPINST_CRITSEC == TRUE
  99. #undef DNEnterCriticalSection
  100. #define DNEnterCriticalSection( arg ) DNTimeEnterCriticalSection( arg )
  101. #endif
  102. //**********************************************************************
  103. // Global Variable definitions
  104. //**********************************************************************
  105. static __int64 g_n64QPCFrequency = 0;
  106. static BOOL g_bQPC_Not_Inited = TRUE;
  107. //**********************************************************************
  108. // Function Prototypes
  109. //**********************************************************************
  110. void DebugPrintfX(LPCSTR szFile, DWORD dwLineNumber,LPCSTR szFnName, DWORD dwSubComp, volatile DWORD_PTR dwDetail, ...);
  111. #ifdef __cplusplus
  112. } //extern "C"
  113. #endif
  114. #else // NULL definition
  115. #define START_QPC
  116. #define END_QPC
  117. #endif //#ifdef DPINST
  118. #endif // __PERFMACS_H__