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.

168 lines
9.0 KiB

  1. /****************************************************************************/
  2. /* Copyright(C) Microsoft Corporation 1998 */
  3. /****************************************************************************/
  4. /****************************************************************************/
  5. /* */
  6. /* CPU Cycle counter */
  7. /* */
  8. /****************************************************************************/
  9. #if defined(OS_WIN32) && !defined(DC_DEBUG) && defined(_M_IX86) && defined(PERF)
  10. /****************************************************************************/
  11. /* */
  12. /* CPU Cycle counter macros */
  13. /* */
  14. /****************************************************************************/
  15. /****************************************************************************/
  16. /* variables used to store the count */
  17. /****************************************************************************/
  18. #define MAX_FNS 12
  19. /****************************************************************************/
  20. /* Counter identifiers */
  21. /****************************************************************************/
  22. #define FC_MEM2SCRN_BITBLT 0
  23. #define FC_DSTBLT_TYPE 1
  24. #define FC_PATBLT_TYPE 2
  25. #define FC_OPAQUERECT_TYPE 3
  26. #define FC_SCRBLT_TYPE 4
  27. #define FC_MEMBLT_TYPE 5
  28. #define FC_LINETO_TYPE 6
  29. #define FC_POLYLINE_TYPE 7
  30. #define FC_INDEX_TYPE 8
  31. #define FC_UHADDUPDATEREGION 9
  32. #define FC_UHSETCLIPREGION 10
  33. #define FC_UHPROCESSPALETTEPDU 11
  34. #define FC_POLYGONSC_TYPE 12
  35. #define FC_POLYGONCB_TYPE 13
  36. #define FC_ELLIPSESC_TYPE 14
  37. #define FC_ELLIPSECB_TYPE 15
  38. #define FC_FAST_INDEX_TYPE 16
  39. #define FC_FAST_GLYPH_TYPE 17
  40. /****************************************************************************/
  41. /* Routines to measure the count before and after */
  42. /****************************************************************************/
  43. #define TIMERSTART \
  44. { \
  45. unsigned long startHi; \
  46. unsigned long startLo; \
  47. unsigned long endHi; \
  48. unsigned long endLo; \
  49. \
  50. unsigned long timeLo; \
  51. unsigned long timeHi; \
  52. \
  53. \
  54. _asm mov eax,0 \
  55. _asm mov edx,0 \
  56. \
  57. _asm _emit 0Fh \
  58. _asm _emit 31h \
  59. _asm mov startHi, edx \
  60. _asm mov startLo, eax \
  61. #define TIMERSTOP \
  62. _asm mov eax,0 \
  63. _asm mov edx,0 \
  64. \
  65. _asm _emit 0Fh \
  66. _asm _emit 31h \
  67. _asm mov endHi, edx \
  68. _asm mov endLo, eax \
  69. #define UPDATECOUNTER(fn) \
  70. callCount[fn]++; \
  71. \
  72. if (endLo < startLo) \
  73. { \
  74. timeLo = 0xFFFFFFFF - (startLo - endLo - 1); \
  75. endHi--; \
  76. } \
  77. else \
  78. { \
  79. timeLo = endLo - startLo; \
  80. } \
  81. \
  82. timeHi = endHi - startHi; \
  83. \
  84. cycleCountLo[fn] = (unsigned long)(cycleCountLo[fn] + timeLo);\
  85. \
  86. if (cycleCountLo[fn] < timeLo) \
  87. { \
  88. timeHi++; \
  89. } \
  90. \
  91. cycleCountHi[fn] += timeHi; \
  92. }
  93. #define RESET_COUNTERS \
  94. { \
  95. int idx; \
  96. for (idx = 0; idx < MAX_FNS; idx++)\
  97. { \
  98. callCount[idx] = 0; \
  99. cycleCountHi[idx] = 0; \
  100. cycleCountLo[idx] = 0; \
  101. } \
  102. \
  103. OutputDebugString(_T("Counters Reset\n")); \
  104. \
  105. } \
  106. #define OUTPUT_COUNTERS \
  107. { \
  108. int idx; \
  109. TCHAR result[80]; \
  110. TCHAR fnNames[MAX_FNS][30] = \
  111. { \
  112. _T("BitmapRect sub order *"), \
  113. _T("DSTBLT order"), \
  114. _T("PATBLT order"), \
  115. _T("OPAQUERECT order"), \
  116. _T("SCRBLT order"), \
  117. _T("MEMBLT order **"), \
  118. _T("LINETO order **"), \
  119. _T("POLYLINE order"), \
  120. _T("INDEX (glyph) order *"), \
  121. _T("UHAddUpdateRegion *"), \
  122. _T("UHSetClipRegion *"), \
  123. _T("UHProcessPalettePDU *"), \
  124. _T("POLYGONSC order"), \
  125. _T("POLYGONCB order"), \
  126. _T("ELLIPSESC order"), \
  127. _T("ELLIPSECB order"), \
  128. _T("FASTINDEX order"), \
  129. _T("FASTGLYPH order")
  130. }; \
  131. \
  132. OutputDebugString(_T("******************************************")\
  133. _T("\n")); \
  134. _stprintf(result, _T("%-29s %-6s %-12s %-12s\n"), _T("Operation"),\
  135. _T("Hits"), _T("High cycles"), _T("Low cycles")); \
  136. \
  137. OutputDebugString(result); \
  138. for (idx = 0; idx < MAX_FNS; idx++) \
  139. { \
  140. _stprintf(result, _T("%-29s %6lu %12lu %12lu\n"), \
  141. fnNames[idx], callCount[idx], \
  142. cycleCountHi[idx], cycleCountLo[idx]); \
  143. OutputDebugString(result); \
  144. } \
  145. OutputDebugString(_T("******************************************")\
  146. _T("\n")); \
  147. } \
  148. #else
  149. #define MAX_FNS
  150. #define TIMERSTART
  151. #define TIMERSTOP
  152. #define UPDATECOUNTER(fn)
  153. #define RESET_COUNTERS
  154. #define OUTPUT_COUNTERS
  155. #endif