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.

210 lines
6.2 KiB

  1. #ifndef _WT_TRACE_H_
  2. #define _WT_TRACE_H_
  3. #define TRACEID WTG.g_TraceId
  4. //
  5. // constants and macros used for tracing
  6. //
  7. #define WT_TRACE_ANY ((DWORD)0xFFFF0000 | TRACE_USE_MASK)
  8. #define WT_TRACE_ENTER ((DWORD)0x00010000 | TRACE_USE_MASK)
  9. #define WT_TRACE_LEAVE ((DWORD)0x00020000 | TRACE_USE_MASK)
  10. #define WT_TRACE_TIMER ((DWORD)0x00100000 | TRACE_USE_MASK)
  11. #define WT_TRACE_RECEIVE ((DWORD)0x00200000 | TRACE_USE_MASK)
  12. #define WT_TRACE_CS ((DWORD)0x00400000 | TRACE_USE_MASK)
  13. #define WT_TRACE_EVENT ((DWORD)0x00800000 | TRACE_USE_MASK)
  14. #define WT_TRACE_WT ((DWORD)0x01000000 | TRACE_USE_MASK)
  15. #define WT_TRACE_START ((DWORD)0x02000000 | TRACE_USE_MASK)
  16. #define WT_TRACE_STOP ((DWORD)0x04000000 | TRACE_USE_MASK)
  17. #define WT_TRACE_WAIT_TIMER ((DWORD)0x10000000 | TRACE_USE_MASK)
  18. #define WAIT_DBG 1
  19. #if WAIT_DBG
  20. #define ENTER_CRITICAL_SECTION(pcs, type, proc) \
  21. TRACE2(CS,"----To enter %s in %s", type, proc); \
  22. EnterCriticalSection(pcs); \
  23. TRACE2(CS,"----Entered %s in %s", type, proc)
  24. #define LEAVE_CRITICAL_SECTION(pcs, type, proc) \
  25. TRACE2(CS,"----Left %s in %s", type, proc); \
  26. LeaveCriticalSection(pcs)
  27. #define WAIT_FOR_SINGLE_OBJECT( event, time, type, proc) \
  28. TRACE2(EVENT, "++++To wait for singleObj %s in %s", type, proc); \
  29. WaitForSingleObject(event, time); \
  30. TRACE2(EVENT, "++++WaitForSingleObj returned %s in %s", type, proc)
  31. #define SET_EVENT(event, type, proc) \
  32. TRACE2(EVENT, "++++SetEvent %s in %s", type, proc); \
  33. SetEvent(event)
  34. #else
  35. #define ENTER_CRITICAL_SECTION(pcs, type, proc) \
  36. EnterCriticalSection(pcs)
  37. #define LEAVE_CRITICAL_SECTION(pcs, type, proc) \
  38. LeaveCriticalSection(pcs)
  39. #define WAIT_FOR_SINGLE_OBJECT( event, time, type, proc) \
  40. WaitForSingleObject(event, time)
  41. #define SET_EVENT(event, type, proc) \
  42. SetEvent(event)
  43. #endif
  44. #define TRACESTART() \
  45. TRACEID = TraceRegister("WAIT_THREAD")
  46. #define TRACESTOP() \
  47. TraceDeregister(TRACEID)
  48. #define ETRACE0(a) \
  49. TracePrintfEx(TRACEID, WT_TRACE_ANY, a)
  50. #define TRACE0(l,a) \
  51. TracePrintfEx(TRACEID, WT_TRACE_ ## l, a)
  52. #define TRACE1(l,a,b) \
  53. TracePrintfEx(TRACEID, WT_TRACE_ ## l, a, b)
  54. #define TRACE2(l,a,b,c) \
  55. TracePrintfEx(TRACEID, WT_TRACE_ ## l, a, b, c)
  56. #define TRACE3(l,a,b,c,d) \
  57. TracePrintfEx(TRACEID, WT_TRACE_ ## l, a, b, c, d)
  58. #define TRACE4(l,a,b,c,d,e) \
  59. TracePrintfEx(TRACEID, WT_TRACE_ ## l, a, b, c, d, e)
  60. #define TRACE5(l,a,b,c,d,e,f) \
  61. TracePrintfEx(TRACEID, WT_TRACE_ ## l, a, b, c, d, e, f)
  62. #define TRACEDUMP(l,a,b,c) \
  63. TraceDumpEx(TRACEID,l,a,b,c,TRUE)
  64. #define DBG2 0
  65. #if DBG
  66. #define TRACE_ENTER(str) \
  67. TracePrintfEx(TRACEID, WT_TRACE_ENTER, str)
  68. #define TRACE_LEAVE(str) \
  69. TracePrintfEx(TRACEID, WT_TRACE_LEAVE, str)
  70. #else
  71. #define TRACE_ENTER(str)
  72. #define TRACE_LEAVE(str)
  73. #endif
  74. //
  75. // Event logging macros
  76. //
  77. #define LOGLEVEL WTG.g_LogLevel
  78. #define LOGHANDLE WTG.g_LogHandle
  79. #define LOGERR RouterLogError
  80. #define LOGWARN RouterLogWarning
  81. #define LOGINFO RouterLogInformation
  82. #define LOGWARNDATA RouterLogWarningData
  83. //
  84. // constants used for logging
  85. //
  86. #define WT_LOGGING_NONE 0
  87. #define WT_LOGGING_ERROR 1
  88. #define WT_LOGGING_WARN 2
  89. #define WT_LOGGING_INFO 3
  90. // Error logging
  91. #define LOGERR0(msg,err) \
  92. if (LOGLEVEL >= WT_LOGGING_ERROR) \
  93. LOGERR(LOGHANDLE,WTLOG_ ## msg,0,NULL,(err))
  94. #define LOGERR1(msg,a,err) \
  95. if (LOGLEVEL >= WT_LOGGING_ERROR) \
  96. LOGERR(LOGHANDLE,WTLOG_ ## msg,1,&(a),(err))
  97. #define LOGERR2(msg,a,b,err) \
  98. if (LOGLEVEL >= WT_LOGGING_ERROR) { \
  99. LPSTR _asz[2] = { (a), (b) }; \
  100. LOGERR(LOGHANDLE,WTLOG_ ## msg,2,_asz,(err)); \
  101. }
  102. #define LOGERR3(msg,a,b,c,err) \
  103. if (LOGLEVEL >= WT_LOGGING_ERROR) { \
  104. LPSTR _asz[3] = { (a), (b), (c) }; \
  105. LOGERR(LOGHANDLE,WTLOG_ ## msg,3,_asz,(err)); \
  106. }
  107. #define LOGERR4(msg,a,b,c,d,err) \
  108. if (LOGLEVEL >= WT_LOGGING_ERROR) { \
  109. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  110. LOGERR(LOGHANDLE,WTLOG_ ## msg,4,_asz,(err)); \
  111. }
  112. // Warning logging
  113. #define LOGWARN0(msg,err) \
  114. if (LOGLEVEL >= WT_LOGGING_WARN) \
  115. LOGWARN(LOGHANDLE,WTLOG_ ## msg,0,NULL,(err))
  116. #define LOGWARN1(msg,a,err) \
  117. if (LOGLEVEL >= WT_LOGGING_WARN) \
  118. LOGWARN(LOGHANDLE,WTLOG_ ## msg,1,&(a),(err))
  119. #define LOGWARN2(msg,a,b,err) \
  120. if (LOGLEVEL >= WT_LOGGING_WARN) { \
  121. LPSTR _asz[2] = { (a), (b) }; \
  122. LOGWARN(LOGHANDLE,WTLOG_ ## msg,2,_asz,(err)); \
  123. }
  124. #define LOGWARN3(msg,a,b,c,err) \
  125. if (LOGLEVEL >= WT_LOGGING_WARN) { \
  126. LPSTR _asz[3] = { (a), (b), (c) }; \
  127. LOGWARN(LOGHANDLE,WTLOG_ ## msg,3,_asz,(err)); \
  128. }
  129. #define LOGWARN4(msg,a,b,c,d,err) \
  130. if (LOGLEVEL >= WT_LOGGING_WARN) { \
  131. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  132. LOGWARN(LOGHANDLE,WTLOG_ ## msg,4,_asz,(err)); \
  133. }
  134. #define LOGWARNDATA2(msg,a,b,dw,buf) \
  135. if (LOGLEVEL >= WT_LOGGING_WARN) { \
  136. LPSTR _asz[2] = { (a), (b) }; \
  137. LOGWARNDATA(LOGHANDLE,WTLOG_ ## msg,2,_asz,(dw),(buf)); \
  138. }
  139. // Information logging
  140. #define LOGINFO0(msg,err) \
  141. if (LOGLEVEL >= WT_LOGGING_INFO) \
  142. LOGINFO(LOGHANDLE,WTLOG_ ## msg,0,NULL,(err))
  143. #define LOGINFO1(msg,a,err) \
  144. if (LOGLEVEL >= WT_LOGGING_INFO) \
  145. LOGINFO(LOGHANDLE,WTLOG_ ## msg,1,&(a),(err))
  146. #define LOGINFO2(msg,a,b,err) \
  147. if (LOGLEVEL >= WT_LOGGING_INFO) { \
  148. LPSTR _asz[2] = { (a), (b) }; \
  149. LOGINFO(LOGHANDLE,WTLOG_ ## msg,2,_asz,(err)); \
  150. }
  151. #define LOGINFO3(msg,a,b,c,err) \
  152. if (LOGLEVEL >= WT_LOGGING_INFO) { \
  153. LPSTR _asz[3] = { (a), (b), (c) }; \
  154. LOGINFO(LOGHANDLE,WTLOG_ ## msg,3,_asz,(err)); \
  155. }
  156. #define LOGINFO4(msg,a,b,c,d,err) \
  157. if (LOGLEVEL >= WT_LOGGING_INFO) { \
  158. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  159. LOGINFO(LOGHANDLE,WTLOG_ ## msg,4,_asz,(err)); \
  160. }
  161. #endif //_WT_TRACE_H_