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.

352 lines
7.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. perfdiag.hxx
  5. Abstract:
  6. Performance diagnostics
  7. Author:
  8. Richard L Firth (rfirth) 24-Jan-1997
  9. Revision History:
  10. 24-Jan-1997 rfirth
  11. Created
  12. --*/
  13. #if !defined(_PERFDIAG_)
  14. #define _PERFDIAG_
  15. //
  16. // perf event (PE_) definitions
  17. //
  18. //#define USE_ICECAP_FOR_DOWNLOAD_PROFILING 1
  19. #define PE_START 1
  20. #define PE_END 2
  21. #define PE_CLIENT_REQUEST_START 3
  22. #define PE_CLIENT_REQUEST_END 4
  23. #define PE_CLIENT_REQUEST_QUEUED 5
  24. #define PE_WORKER_REQUEST_START 6
  25. #define PE_WORKER_REQUEST_END 7
  26. #define PE_APP_CALLBACK_START 8
  27. #define PE_APP_CALLBACK_END 9
  28. #define PE_NAMERES_START 10
  29. #define PE_NAMERES_END 11
  30. #define PE_CONNECT_START 12
  31. #define PE_CONNECT_END 13
  32. #define PE_SEND_START 14
  33. #define PE_SEND_END 15
  34. #define PE_RECEIVE_START 16
  35. #define PE_RECEIVE_END 17
  36. #define PE_PEEK_RECEIVE_START 18
  37. #define PE_PEEK_RECEIVE_END 19
  38. #define PE_SOCKET_CLOSE_START 20
  39. #define PE_SOCKET_CLOSE_END 21
  40. #define PE_ACQUIRE_KEEP_ALIVE 22
  41. #define PE_RELEASE_KEEP_ALIVE 23
  42. #define PE_SOCKET_ERROR 24
  43. #define PE_CACHE_READ_CHECK_START 25
  44. #define PE_CACHE_READ_CHECK_END 26
  45. #define PE_CACHE_WRITE_CHECK_START 27
  46. #define PE_CACHE_WRITE_CHECK_END 28
  47. #define PE_CACHE_RETRIEVE_START 29
  48. #define PE_CACHE_RETRIEVE_END 30
  49. #define PE_CACHE_READ_START 31
  50. #define PE_CACHE_READ_END 32
  51. #define PE_CACHE_WRITE_START 33
  52. #define PE_CACHE_WRITE_END 34
  53. #define PE_CACHE_CREATE_FILE_START 35
  54. #define PE_CACHE_CREATE_FILE_END 36
  55. #define PE_CACHE_CLOSE_FILE_START 37
  56. #define PE_CACHE_CLOSE_FILE_END 38
  57. #define PE_CACHE_EXPIRY_CHECK_START 39
  58. #define PE_CACHE_EXPIRY_CHECK_END 40
  59. #define PE_YIELD_SELECT_START 41
  60. #define PE_YIELD_SELECT_END 42
  61. #define PE_YIELD_OBJECT_WAIT_START 43
  62. #define PE_YIELD_OBJECT_WAIT_END 44
  63. #define PE_YIELD_SLEEP_START 45
  64. #define PE_YIELD_SLEEP_END 46
  65. #define PE_TRACE 47
  66. #define PE_ENTER_PATH 48
  67. #define PE_LEAVE_PATH 49
  68. #define PE_TRACE_PATH 50
  69. //
  70. // API prototypes
  71. //
  72. #if defined(__cplusplus)
  73. extern "C" {
  74. #endif
  75. VOID
  76. __declspec(dllexport)
  77. WINAPI
  78. WininetPerfLog(
  79. IN DWORD dwEvent,
  80. IN DWORD dwInfo1,
  81. IN DWORD dwInfo2,
  82. IN HINTERNET hInternet
  83. );
  84. #if defined(__cplusplus)
  85. }
  86. #endif
  87. #if defined(USE_PERF_DIAG)
  88. //
  89. // manifests
  90. //
  91. //#define DEFAULT_PE_LOG_RECORDS 4096
  92. #define DEFAULT_PE_LOG_RECORDS 16384
  93. //
  94. // types
  95. //
  96. typedef struct {
  97. LARGE_INTEGER liTime;
  98. DWORD dwThreadId;
  99. DWORD dwThreadPriority;
  100. HINTERNET hInternet;
  101. DWORD dwEvent;
  102. DWORD dwInfo;
  103. DWORD dwInfo2;
  104. } PERF_INFO, * LPPERF_INFO;
  105. //
  106. // prototypes
  107. //
  108. VOID
  109. PerfSleep(
  110. DWORD dwMilliseconds
  111. );
  112. int PerfSelect(
  113. int nfds,
  114. fd_set FAR * readfds,
  115. fd_set FAR * writefds,
  116. fd_set FAR * exceptfds,
  117. const struct timeval FAR * timeout
  118. );
  119. DWORD
  120. PerfWaitForSingleObject(
  121. HANDLE hObject,
  122. DWORD dwTimeout
  123. );
  124. //
  125. // classes
  126. //
  127. class CPerfDiag {
  128. private:
  129. LPBYTE m_lpbPerfBuffer;
  130. DWORD m_dwPerfBufferLen;
  131. LPBYTE m_lpbEnd;
  132. LPBYTE m_lpbNext;
  133. BOOL m_bFull;
  134. BOOL m_bStarted;
  135. BOOL m_bStartFinished;
  136. LARGE_INTEGER m_liStartTime;
  137. LPPERF_INFO get_next_record(VOID);
  138. VOID get_perf_time(PLARGE_INTEGER pTime) {
  139. QueryPerformanceCounter(pTime);
  140. }
  141. VOID get_time(LPPERF_INFO lpInfo) {
  142. get_perf_time(&lpInfo->liTime);
  143. }
  144. VOID free_perf_buffer(VOID) {
  145. if (m_lpbPerfBuffer) {
  146. m_lpbPerfBuffer = (LPBYTE)FREE_MEMORY(m_lpbPerfBuffer);
  147. INET_ASSERT(!m_lpbPerfBuffer);
  148. }
  149. }
  150. VOID perf_start(VOID) {
  151. while (!m_bStartFinished) {
  152. if (InterlockedExchange((LPLONG)&m_bStarted, TRUE) == FALSE) {
  153. get_perf_time(&m_liStartTime);
  154. Init();
  155. m_bStartFinished = TRUE;
  156. }
  157. if (!m_bStartFinished) {
  158. Sleep(0);
  159. }
  160. }
  161. }
  162. public:
  163. CPerfDiag();
  164. ~CPerfDiag();
  165. VOID Init(DWORD dwNumberOfRecords = DEFAULT_PE_LOG_RECORDS) {
  166. CreateBuffer(dwNumberOfRecords);
  167. }
  168. VOID CreateBuffer(LPBYTE lpbBuffer, DWORD dwBufferLength) {
  169. }
  170. VOID CreateBuffer(DWORD dwNumberOfRecords = DEFAULT_PE_LOG_RECORDS) {
  171. free_perf_buffer();
  172. m_dwPerfBufferLen = dwNumberOfRecords * sizeof(PERF_INFO);
  173. m_lpbPerfBuffer = (LPBYTE)ALLOCATE_MEMORY(LMEM_FIXED, m_dwPerfBufferLen);
  174. if (m_lpbPerfBuffer) {
  175. m_lpbEnd = m_lpbPerfBuffer + m_dwPerfBufferLen;
  176. m_lpbNext = m_lpbPerfBuffer;
  177. m_bFull = FALSE;
  178. } else {
  179. OutputDebugString("*** Cannot create performance buffer\n");
  180. }
  181. }
  182. VOID Log(DWORD dwEvent, DWORD dwInfo = 0);
  183. VOID Log(DWORD dwEvent, DWORD dwInfo, DWORD dwThreadId, HINTERNET hInternet);
  184. VOID Log(DWORD dwEvent, DWORD dwInfo, DWORD dwInfo2, DWORD dwThreadId, HINTERNET hInternet);
  185. VOID Dump(VOID);
  186. };
  187. //
  188. // global data
  189. //
  190. extern CPerfDiag * GlobalPerfDiag;
  191. //
  192. // macros
  193. //
  194. #define PERF_INIT() \
  195. if (!GlobalPerfDiag) GlobalPerfDiag = New CPerfDiag
  196. #define PERF_END() \
  197. if (GlobalPerfDiag) delete GlobalPerfDiag
  198. #define PERF_LOG \
  199. if (GlobalPerfDiag) GlobalPerfDiag->Log
  200. #define PERF_DUMP() \
  201. if (GlobalPerfDiag) GlobalPerfDiag->Dump()
  202. #define PERF_Sleep(n) \
  203. PerfSleep(n)
  204. #define PERF_Select(n, pReadfds, pWritefds, pExceptfds, pTimeout) \
  205. PerfSelect(n, pReadfds, pWritefds, pExceptfds, pTimeout)
  206. #define PERF_WaitForSingleObject(hObject, dwTimeout) \
  207. PerfWaitForSingleObject(hObject, dwTimeout)
  208. #else
  209. #define PERF_INIT() \
  210. /* NOTHING */
  211. #define PERF_END() \
  212. /* NOTHING */
  213. #define PERF_LOG \
  214. (VOID)
  215. #define PERF_DUMP() \
  216. /* NOTHING */
  217. #define PERF_Sleep(n) \
  218. Sleep(n)
  219. #define PERF_Select(n, pReadfds, pWritefds, pExceptfds, pTimeout) \
  220. _I_select(n, pReadfds, pWritefds, pExceptfds, pTimeout)
  221. #define PERF_WaitForSingleObject(hObject, dwTimeout) \
  222. WaitForSingleObject(hObject, dwTimeout)
  223. #endif // defined(USE_PERF_DIAG)
  224. //#define PERF_ENTER(Name) \
  225. // StartCAP()
  226. //#define PERF_LEAVE(Name) \
  227. // StopCAP()
  228. #if defined(USE_PERF_DIAG)
  229. #define PERF_LOG_EX \
  230. WininetPerfLog
  231. #define PERF_ID(Name) \
  232. (LPCSTR)(# Name)
  233. #define PERF_TRACE(Name, Info) \
  234. WininetPerfLog(PE_TRACE_PATH, Info, (DWORD)PERF_ID(Name), 0)
  235. #define PERF_ENTER(Name) \
  236. WininetPerfLog(PE_ENTER_PATH, 0, (DWORD)PERF_ID(Name), 0)
  237. #define PERF_LEAVE(Name) \
  238. WininetPerfLog(PE_LEAVE_PATH, 0, (DWORD)PERF_ID(Name), 0)
  239. #else
  240. #define PERF_LOG_EX \
  241. /* NOTHING */
  242. #define PERF_ID(Name) \
  243. /* NOTHING */
  244. #define PERF_TRACE(Name, Info) \
  245. /* NOTHING */
  246. #ifdef USE_ICECAP_FOR_DOWNLOAD_PROFILING
  247. #define PERF_ENTER(Name) \
  248. StartCAP()
  249. #define PERF_LEAVE(Name) \
  250. StopCAP()
  251. #else
  252. #define PERF_ENTER(Name) \
  253. /* NOTHING */
  254. #define PERF_LEAVE(Name) \
  255. /* NOTHING */
  256. #endif // defined(USE_ICECAP_FOR_DOWNLOAD_PROFILING)
  257. #endif // defined(USE_PERF_DIAG)
  258. #define STOP_SENDREQ_PERF() \
  259. /* nothing */
  260. #define START_SENDREQ_PERF() \
  261. /* nothing */
  262. #endif // defined(_PERFDIAG_)