Leaked source code of windows server 2003
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.

243 lines
7.5 KiB

  1. //
  2. // perfct.cpp
  3. //
  4. #include "private.h"
  5. #include "perfct.h"
  6. #ifdef DEBUG
  7. extern DBG_MEMSTATS s_Dbg_MemStats;
  8. DBG_MEM_COUNTER g_rgPerfObjCounters[] =
  9. {
  10. { TEXT("CAnchorRef: "), 0 },
  11. { TEXT("CRange: "), 0 },
  12. { TEXT("CLoaderACP: "), 0 },
  13. { TEXT("CACPWrap: "), 0 },
  14. { TEXT("CAnchorList: "), 0 },
  15. { TEXT("CAnchor: "), 0 },
  16. { TEXT("CEnumAppPropRanges: "), 0 },
  17. { TEXT("CAppProperty: "), 0 },
  18. { TEXT("CEnumUberRanges: "), 0 },
  19. { TEXT("CUberProperty: "), 0 },
  20. { TEXT("CEnumProperties: "), 0 },
  21. { TEXT("CProperty: "), 0 },
  22. { TEXT("CCategoryMgr: "), 0 },
  23. { TEXT("CEnumCategories: "), 0 },
  24. { TEXT("CCompartmentMgr: "), 0 },
  25. { TEXT("CEnumCompartment: "), 0 },
  26. { TEXT("CCompartment: "), 0 },
  27. { TEXT("CGlobalCompartment: "), 0 },
  28. { TEXT("CCompartmentSub: "), 0 },
  29. { TEXT("CEditRecord: "), 0 },
  30. { TEXT("CEnumPropertyRanges: "), 0 },
  31. { TEXT("CInputContext: "), 0 },
  32. { TEXT("CSpanSet: "), 0 },
  33. { TEXT("PROPERTYLIST: "), 0 },
  34. { TEXT("---------------------"), 0 },
  35. { TEXT("CACPWrap::GetText "), 0 },
  36. { TEXT("CACPWrap:GetText:loop"), 0 },
  37. { TEXT("ShiftRegion:GetText "), 0 },
  38. { TEXT("GetTextComp:GetText "), 0 },
  39. { TEXT("PlainTextOff:GetText "), 0 },
  40. { TEXT("ATOF GetText calls: "), 0 },
  41. { TEXT("ShiftCond:GetText "), 0 },
  42. { TEXT("---------------------"), 0 },
  43. { TEXT("ATOF calls: "), 0 },
  44. { TEXT("ATON calls: "), 0 },
  45. { TEXT("Normalize calls: "), 0 },
  46. { TEXT("ShiftRegion calls: "), 0 },
  47. { TEXT("Renormalize calls: "), 0 },
  48. { TEXT("---------------------"), 0 },
  49. { TEXT("CreateRangeACP "), 0 },
  50. { TEXT("Lazy:Norm "), 0 },
  51. { TEXT("---------------------"), 0 },
  52. { TEXT("ITfRange::ShiftStart "), 0 },
  53. { TEXT("ITfRange::ShiftEnd "), 0 },
  54. { TEXT("ITfRange::GetText "), 0 },
  55. { TEXT("ITfRange::SetText "), 0 },
  56. { TEXT("CAnchorRef::Shift "), 0 },
  57. { TEXT("key down events "), 0 },
  58. };
  59. #endif // DEBUG
  60. #ifdef PERF_DUMP
  61. LARGE_INTEGER g_liPerfFreq = { 0 };
  62. ULONG g_cStrokes = 0;
  63. struct
  64. {
  65. LARGE_INTEGER liStart[PERF_STROKE_ARRAYSIZE];
  66. LARGE_INTEGER liEnd[PERF_STROKE_ARRAYSIZE];
  67. }
  68. g_rgPerfStrokes[2048] = { 0 };
  69. BOOL Perf_Init()
  70. {
  71. QueryPerformanceFrequency(&g_liPerfFreq);
  72. return TRUE;
  73. }
  74. //+---------------------------------------------------------------------------
  75. //
  76. // Perf_GetTicks
  77. //
  78. //----------------------------------------------------------------------------
  79. LARGE_INTEGER GetTicks()
  80. {
  81. LARGE_INTEGER li;
  82. if (g_liPerfFreq.QuadPart != 0)
  83. {
  84. QueryPerformanceCounter(&li);
  85. }
  86. else
  87. {
  88. li.LowPart = GetTickCount();
  89. li.HighPart = 0;
  90. }
  91. return li;
  92. }
  93. //+---------------------------------------------------------------------------
  94. //
  95. // Perf_GetTickDifference
  96. //
  97. //----------------------------------------------------------------------------
  98. ULONG GetTickDifference(LARGE_INTEGER liStartTicks, LARGE_INTEGER liEndTicks)
  99. {
  100. liEndTicks.QuadPart -= liStartTicks.QuadPart;
  101. if (g_liPerfFreq.QuadPart != 0)
  102. {
  103. liEndTicks.QuadPart /= (g_liPerfFreq.QuadPart / 1000);
  104. }
  105. return liEndTicks.LowPart;
  106. }
  107. //+---------------------------------------------------------------------------
  108. //
  109. // Perf_StartStroke
  110. //
  111. //----------------------------------------------------------------------------
  112. void Perf_StartStroke(UINT iIndex)
  113. {
  114. LARGE_INTEGER liPrevTotal;
  115. if (g_cStrokes < ARRAYSIZE(g_rgPerfStrokes))
  116. {
  117. liPrevTotal.QuadPart = g_rgPerfStrokes[g_cStrokes].liEnd[iIndex].QuadPart - g_rgPerfStrokes[g_cStrokes].liStart[iIndex].QuadPart;
  118. g_rgPerfStrokes[g_cStrokes].liStart[iIndex].QuadPart = GetTicks().QuadPart - liPrevTotal.QuadPart;
  119. }
  120. }
  121. //+---------------------------------------------------------------------------
  122. //
  123. // Perf_EndStroke
  124. //
  125. //----------------------------------------------------------------------------
  126. void Perf_EndStroke(UINT iIndex)
  127. {
  128. if (g_cStrokes < ARRAYSIZE(g_rgPerfStrokes))
  129. {
  130. g_rgPerfStrokes[g_cStrokes].liEnd[iIndex] = GetTicks();
  131. }
  132. if (iIndex == PERF_STROKE_DOWN)
  133. {
  134. g_cStrokes++;
  135. }
  136. }
  137. #include <stdio.h>
  138. //+---------------------------------------------------------------------------
  139. //
  140. // Perf_DumpStats
  141. //
  142. //----------------------------------------------------------------------------
  143. void Perf_DumpStats()
  144. {
  145. //
  146. // add the application name to check the cicero's performance.
  147. //
  148. static const TCHAR *c_rgPerfProcesses[] =
  149. {
  150. TEXT("notepad.exe"),
  151. };
  152. FILE *file;
  153. TCHAR ach[MAX_PATH];
  154. DWORD cch;
  155. DWORD cchTest;
  156. LONG i;
  157. //
  158. // only dump perf info for certain processes
  159. //
  160. for (i=0; i<ARRAYSIZE(c_rgPerfProcesses); i++)
  161. {
  162. cchTest = lstrlen(c_rgPerfProcesses[i]);
  163. if ((cch = GetModuleFileName(0, ach, ARRAYSIZE(ach))) < cchTest)
  164. continue;
  165. if (lstrcmpi(ach+cch-cchTest, c_rgPerfProcesses[i]) != 0)
  166. continue;
  167. break;
  168. }
  169. if (i == ARRAYSIZE(c_rgPerfProcesses))
  170. return;
  171. file = fopen("c:\\perf.txt", "w");
  172. fprintf(file, "****************************************************************\n");
  173. fprintf(file, "Cicero Perf Counters (%s)\n", c_rgPerfProcesses[i]);
  174. fprintf(file, "****************************************************************\n");
  175. fprintf(file, "\n\n");
  176. #ifdef DEBUG
  177. for (i=0; i<ARRAYSIZE(g_rgPerfObjCounters); i++)
  178. {
  179. fprintf(file, "%s %d\n", g_rgPerfObjCounters[i].pszDesc, g_rgPerfObjCounters[i].uCount);
  180. }
  181. fprintf(file, "\n\n");
  182. fprintf(file, "cicMemAlloc: %d\n", s_Dbg_MemStats.uTotalMemAllocCalls);
  183. fprintf(file, "cicMemAllocClear: %d\n", s_Dbg_MemStats.uTotalMemAllocClearCalls);
  184. fprintf(file, "cicMemReAlloc: %d\n", s_Dbg_MemStats.uTotalMemReAllocCalls);
  185. #endif // DEBUG
  186. fprintf(file, "\n\n");
  187. for (i=0; i<(int)min(g_cStrokes, ARRAYSIZE(g_rgPerfStrokes)); i++)
  188. {
  189. ULONG ulElapsedDn = GetTickDifference(g_rgPerfStrokes[i].liStart[PERF_STROKE_DOWN], g_rgPerfStrokes[i].liEnd[PERF_STROKE_DOWN]);
  190. ULONG ulElapsedUp = GetTickDifference(g_rgPerfStrokes[i].liStart[PERF_STROKE_UP], g_rgPerfStrokes[i].liEnd[PERF_STROKE_UP]);
  191. ULONG ulElapsedTestDn = GetTickDifference(g_rgPerfStrokes[i].liStart[PERF_STROKE_TESTDOWN], g_rgPerfStrokes[i].liEnd[PERF_STROKE_TESTDOWN]);
  192. ULONG ulElapsedTestUp = GetTickDifference(g_rgPerfStrokes[i].liStart[PERF_STROKE_TESTUP], g_rgPerfStrokes[i].liEnd[PERF_STROKE_TESTUP]);
  193. ULONG ulElapsedGetMessage = GetTickDifference(g_rgPerfStrokes[i].liStart[PERF_STROKE_GETMSG], g_rgPerfStrokes[i].liEnd[PERF_STROKE_GETMSG]);
  194. ULONG ulPrev = (i == 0) ? 0 : GetTickDifference(g_rgPerfStrokes[i-1].liEnd[PERF_STROKE_DOWN], g_rgPerfStrokes[i].liEnd[PERF_STROKE_DOWN]);
  195. ULONG ulPercent = (i == 0) ? 0 : (ulElapsedDn+ulElapsedUp+ulElapsedTestUp+ulElapsedTestDn)*100/ulPrev;
  196. fprintf(file, "KeyDown %d: %d/%d/%d/%d (%d) (%d%% of %d)\n", i,
  197. ulElapsedDn, ulElapsedUp, ulElapsedTestDn, ulElapsedTestUp, ulElapsedGetMessage, ulPercent, ulPrev);
  198. }
  199. fclose(file);
  200. }
  201. #endif // PERF_DUMP