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.

379 lines
13 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. WsbTrace.h
  5. Abstract:
  6. This header file defines the part of the platform code that is
  7. responsible for function tracing.
  8. Author:
  9. Chuck Bardeen [cbardeen] 29-Oct-1996
  10. Revision History:
  11. Brian Dodd [brian] 09-May-1996 - Added event logging
  12. --*/
  13. #ifndef _WSBTRACE_
  14. #define _WSBTRACE_
  15. #include "wsb.h"
  16. #include "rsbuild.h"
  17. #include "ntverp.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. // The size of the trace statement buffer including NULL termination
  22. #define WSB_TRACE_BUFF_SIZE 1024
  23. // These define the event log levels
  24. #define WSB_LOG_LEVEL_NONE 0 // Nothing is written the the event log
  25. #define WSB_LOG_LEVEL_ERROR 1 // Errors only (severity 3)
  26. #define WSB_LOG_LEVEL_WARNING 2 // Errors and Warnings (severity 2)
  27. #define WSB_LOG_LEVEL_INFORMATION 3 // Errors, Warnings, and Information (severity 1)
  28. #define WSB_LOG_LEVEL_COMMENT 4 // All Message Types (includes severity 0)
  29. #define WSB_LOG_LEVEL_DEFAULT 3 // Something reasonable.
  30. // These define where the trace output should be written.
  31. #define WSB_TRACE_OUT_NONE 0x00000000L // No output
  32. #define WSB_TRACE_OUT_DEBUG_SCREEN 0x00000001L // Output to the debug screen
  33. #define WSB_TRACE_OUT_FILE 0x00000002L // Output to a file
  34. #define WSB_TRACE_OUT_STDOUT 0x00000004L // Output to standard out
  35. #define WSB_TRACE_OUT_FILE_COPY 0x00000008L // Save copy of trace file
  36. #define WSB_TRACE_OUT_MULTIPLE_FILES 0x00000010L // Output to multiple files
  37. #define WSB_TRACE_OUT_FLAGS_SET 0x00010000L // Indicates other flags are set
  38. #define WSB_TRACE_OUT_ALL 0xffffffffL
  39. // These macros define the module assignments for the bits used to
  40. // control whether tracing is enabled. Each bit should only be used once,
  41. // the granularity will be fairly large.
  42. #define WSB_TRACE_BIT_NONE 0x0000000000000000L
  43. #define WSB_TRACE_BIT_PLATFORM 0x0000000000000001L
  44. #define WSB_TRACE_BIT_RMS 0x0000000000000002L
  45. #define WSB_TRACE_BIT_SEG 0x0000000000000004L // Remove when dependencies are gone
  46. #define WSB_TRACE_BIT_META 0x0000000000000004L
  47. #define WSB_TRACE_BIT_HSMENG 0x0000000000000008L
  48. #define WSB_TRACE_BIT_JOB 0x0000000000000010L
  49. #define WSB_TRACE_BIT_HSMTSKMGR 0x0000000000000020L
  50. #define WSB_TRACE_BIT_FSA 0x0000000000000040L
  51. #define WSB_TRACE_BIT_DATAMIGRATER 0x0000000000000080L
  52. #define WSB_TRACE_BIT_DATARECALLER 0x0000000000000100L
  53. #define WSB_TRACE_BIT_DATAVERIFIER 0x0000000000000200L
  54. #define WSB_TRACE_BIT_UI 0x0000000000000400L
  55. #define WSB_TRACE_BIT_HSMCONN 0x0000000000000800L
  56. #define WSB_TRACE_BIT_DATAMOVER 0x0000000000001000L
  57. #define WSB_TRACE_BIT_IDB 0x0000000000002000L
  58. #define WSB_TRACE_BIT_TEST 0x0000000000004000L
  59. #define WSB_TRACE_BIT_COPYMEDIA 0x0000000000008000L
  60. #define WSB_TRACE_BIT_PERSISTENCE 0x0000000000010000L
  61. #define WSB_TRACE_BIT_HSMSERV 0x0000000000020000L
  62. #define WSB_TRACE_BIT_ALL 0xffffffffffffffffL
  63. // These macros are used to provide function call trace information into
  64. // the log. Each function (method) that wants to be traceable needs at a
  65. // minimum to use the following three macros. The first macro needs to be
  66. // put at the top of the source code file and defines to which module the
  67. // code in that file belongs.
  68. //
  69. // #define WSB_TRACE_IS WSB_TRACE_BIT_PLATFORM
  70. //
  71. // The next two macros are used once per function. They are variable
  72. // macros, which allows the writer of the function to list the values
  73. // of the input and output parameters.
  74. //
  75. // HRESULT CWsbSample::Do(BOOL shouldWrite) {
  76. // HRESULT hr = S_OK;
  77. //
  78. // WsbTraceIn("CWsbSample::Do", "shouldWrite = <%ls>", WsbBoolAsString(shouldWrite));
  79. //
  80. // ... some code ....
  81. //
  82. // WsbTraceOut("CWsbSample::Do", "hr = <%ls>", WsbHrAsString(hr));
  83. //
  84. // return(hr);
  85. // }
  86. //
  87. // Notice that some helper functions have been defined to help provide an
  88. // a written description for the value of certain types. Additional helper
  89. // helper functions should be created as needed.
  90. /*++
  91. Macro Name:
  92. WsbTraceIn
  93. Macro Description:
  94. This macro is used to provide function call trace information into
  95. the log. It should be put at the start of the function.
  96. Arguments:
  97. methodName - The name of the function.
  98. argString - A printf type format string. Additional arguments can
  99. follow.
  100. --*/
  101. #define WsbTraceIn if ((g_WsbTraceEntryExit == TRUE) && ((g_WsbTraceModules & WSB_TRACE_IS) != 0)) WsbTraceEnter
  102. /*++
  103. Macro Name:
  104. WsbTraceOut
  105. Macro Description:
  106. This macro is used to provide function call trace information into
  107. the log. It should be put at the end of the function.
  108. Arguments:
  109. methodName - The name of the function.
  110. argString - A printf type format string. Additional arguments can
  111. follow.
  112. --*/
  113. #define WsbTraceOut if ((g_WsbTraceEntryExit == TRUE) && ((g_WsbTraceModules & WSB_TRACE_IS) != 0)) WsbTraceExit
  114. /*++
  115. Macro Name:
  116. WsbLogEvent
  117. Macro Description:
  118. This routine writes a message into the system event log. The message
  119. is also written to the application trace file.
  120. Arguments:
  121. eventId - The message Id to log.
  122. dataSize - Size of arbitrary data.
  123. data - Arbitrary data buffer to display with the message.
  124. Inserts - Message inserts that are merged with the message description specified by
  125. eventId. The number of inserts must match the number specified by the
  126. message description. The last insert must be NULL to indicate the
  127. end of the insert list.
  128. Notes:
  129. It's a small optimization to check if logging is turned on, first. Determining if the
  130. message is actually logged still requires the first parameter. Unlike trace, log activity
  131. should be minimal and only when there are problems. The overhead of the calls seems
  132. reasonable.
  133. --*/
  134. #define WsbLogEvent \
  135. if ( g_WsbLogLevel ) WsbSetEventInfo( __FILE__, __LINE__, VER_PRODUCTBUILD, RS_BUILD_VERSION ); \
  136. if ( g_WsbLogLevel ) WsbTraceAndLogEvent
  137. /*++
  138. Macro Name:
  139. WsbLogEventV
  140. Macro Description:
  141. This macro is used to write a message into the system event log. The message
  142. is also written to the application trace file.
  143. This macro is similar to WsbLogEvent, but takes a va_list as the fourth argument.
  144. Arguments:
  145. eventId - The message Id to log.
  146. dataSize - Size of arbitrary data.
  147. data - Arbitrary data buffer to display with the message.
  148. inserts - An array of message inserts that are merged with the message description
  149. specified by eventId. The number of inserts must match the number
  150. specified by the message description. The last insert must be NULL,
  151. to indicate the end of the insert list.
  152. Notes:
  153. It's a small optimization to check if logging is turned on, first. Determining if the
  154. message is actually logged still requires the first parameter. Unlike trace, log activity
  155. should be minimal and only when there are problems. The overhead of the calls seems
  156. reasonable.
  157. --*/
  158. #define WsbLogEventV \
  159. if ( g_WsbLogLevel ) WsbSetEventInfo( __FILE__, __LINE__, VER_PRODUCTBUILD, RS_BUILD_VERSION ); \
  160. if ( g_WsbLogLevel ) WsbTraceAndLogEventV
  161. /*++
  162. Macro Name:
  163. WsbTrace
  164. Macro Description:
  165. This macro is used to provide a printf style message into the trace file.
  166. Arguments:
  167. argString - A printf type format string. Additional arguments can
  168. follow.
  169. --*/
  170. #define WsbTrace if ((g_WsbTraceModules & WSB_TRACE_IS) != 0) WsbTracef
  171. /*++
  172. Macro Name:
  173. WsbTraceAlways
  174. Macro Description:
  175. This macro is used to provide a printf style message into the trace file.
  176. The trace is printed if tracing has been started regardless of the
  177. WSB_TRACE_IS settings.
  178. Arguments:
  179. argString - A printf type format string. Additional arguments can
  180. follow.
  181. --*/
  182. #define WsbTraceAlways WsbTracef
  183. /*++
  184. Macro Name:
  185. WsbTraceBuffer
  186. Macro Description:
  187. This macro is used to provide buffer dump to the trace file.
  188. Arguments:
  189. Same as WsbTraceBufferAsBytes
  190. --*/
  191. #define WsbTraceBuffer if ((g_WsbTraceModules & WSB_TRACE_IS) != 0) WsbTraceBufferAsBytes
  192. // The following global variable is used to compare against to determine
  193. // the modules for which debugging should be enabled.
  194. extern WSB_EXPORT LONGLONG g_WsbTraceModules;
  195. extern WSB_EXPORT IWsbTrace *g_pWsbTrace;
  196. extern WSB_EXPORT LONG g_WsbTraceCount;
  197. extern WSB_EXPORT BOOL g_WsbTraceEntryExit;
  198. extern WSB_EXPORT WORD g_WsbLogLevel;
  199. extern WSB_EXPORT BOOL g_WsbLogSnapShotOn;
  200. extern WSB_EXPORT WORD g_WsbLogSnapShotLevel;
  201. extern WSB_EXPORT OLECHAR g_pWsbLogSnapShotPath[];
  202. extern WSB_EXPORT BOOL g_WsbLogSnapShotResetTrace;
  203. // Trace functions
  204. extern WSB_EXPORT void WsbSetEventInfo( char *fileName, DWORD lineNo, DWORD ntBuild, DWORD rsBuild );
  205. extern WSB_EXPORT void WsbTraceInit( void );
  206. extern WSB_EXPORT void WsbTraceCleanupThread(void);
  207. extern WSB_EXPORT void WsbTraceEnter(OLECHAR* methodName, OLECHAR* argString, ...);
  208. extern WSB_EXPORT void WsbTraceExit(OLECHAR* methodName, OLECHAR* argString, ...);
  209. extern WSB_EXPORT void WsbTracef(OLECHAR* argString, ...);
  210. extern WSB_EXPORT void WsbTraceAndLogEvent(DWORD eventId, DWORD dataSize, LPVOID data, ... /* last argument is NULL */);
  211. extern WSB_EXPORT void WsbTraceAndLogEventV(DWORD eventId, DWORD dataSize, LPVOID data, va_list *arguments /* last element is NULL */);
  212. extern WSB_EXPORT void WsbTraceAndPrint(DWORD eventId, ... /* last argument is NULL */);
  213. extern WSB_EXPORT void WsbTraceAndPrintV(DWORD eventId, va_list *arguments /* last element is NULL */);
  214. extern WSB_EXPORT void WsbTraceBufferAsBytes( DWORD size, LPVOID bufferP );
  215. extern WSB_EXPORT void WsbTraceTerminate(void);
  216. extern WSB_EXPORT ULONG WsbTraceThreadOff(void);
  217. extern WSB_EXPORT ULONG WsbTraceThreadOffCount(void);
  218. extern WSB_EXPORT ULONG WsbTraceThreadOn(void);
  219. // Helper Functions
  220. //
  221. // NOTE: Be careful with some of these helper functions, since they
  222. // use static memory and a second call to the function will overwrite
  223. // the results of the first call to the function. Also, some functions
  224. // end up calling each other and sharing memory between them (i.e.
  225. // WsbPtrToGuidAsString() calls WsbGuidAsString()).
  226. extern WSB_EXPORT const OLECHAR* WsbBoolAsString(BOOL boolean);
  227. extern WSB_EXPORT const OLECHAR* WsbFiletimeAsString(BOOL isRelative, FILETIME filetime);
  228. extern WSB_EXPORT const OLECHAR* WsbGuidAsString(GUID guid);
  229. extern WSB_EXPORT const OLECHAR* WsbHrAsString(HRESULT hr);
  230. extern WSB_EXPORT const OLECHAR* WsbLongAsString(LONG inLong);
  231. extern WSB_EXPORT const OLECHAR* WsbLonglongAsString(LONGLONG llong);
  232. extern WSB_EXPORT const OLECHAR* WsbStringAsString(OLECHAR* pStr);
  233. extern WSB_EXPORT const OLECHAR* WsbPtrToBoolAsString(BOOL* pBool);
  234. extern WSB_EXPORT const OLECHAR* WsbPtrToFiletimeAsString(BOOL isRelative, FILETIME *pFiletime);
  235. extern WSB_EXPORT const OLECHAR* WsbPtrToGuidAsString(GUID* pGuid);
  236. extern WSB_EXPORT const OLECHAR* WsbPtrToHrAsString(HRESULT *pHr);
  237. extern WSB_EXPORT const OLECHAR* WsbPtrToLonglongAsString(LONGLONG *pLlong);
  238. extern WSB_EXPORT const OLECHAR* WsbPtrToLongAsString(LONG* pLong);
  239. extern WSB_EXPORT const OLECHAR* WsbPtrToShortAsString(SHORT* pShort);
  240. extern WSB_EXPORT const OLECHAR* WsbPtrToByteAsString(BYTE* pByte);
  241. extern WSB_EXPORT const OLECHAR* WsbPtrToStringAsString(OLECHAR** pString);
  242. extern WSB_EXPORT const OLECHAR* WsbPtrToUliAsString(ULARGE_INTEGER* pUli);
  243. extern WSB_EXPORT const OLECHAR* WsbPtrToUlongAsString(ULONG* pUlong);
  244. extern WSB_EXPORT const OLECHAR* WsbPtrToUshortAsString(USHORT* pUshort);
  245. extern WSB_EXPORT const OLECHAR* WsbPtrToPtrAsString(void** ppVoid);
  246. extern WSB_EXPORT const OLECHAR* WsbAbbreviatePath(const OLECHAR* path, USHORT length);
  247. extern WSB_EXPORT HRESULT WsbShortSizeFormat64(__int64 dw64, LPTSTR szBuf);
  248. #ifdef __cplusplus
  249. /*++
  250. Class Name:
  251. WsbQuickString
  252. Class Description:
  253. Quick string storage class
  254. --*/
  255. class WSB_EXPORT WsbQuickString {
  256. public:
  257. WsbQuickString ( const OLECHAR * sz ) { m_sz = WsbAllocString ( sz ); }
  258. ~WsbQuickString ( ) { if ( m_sz ) WsbFreeString ( m_sz ); }
  259. operator OLECHAR * () { return ( m_sz ); }
  260. private:
  261. BSTR m_sz;
  262. WsbQuickString ( ) { m_sz = 0; }
  263. };
  264. #define WsbStringCopy( a ) ((OLECHAR *)WsbQuickString ( a ) )
  265. }
  266. #endif
  267. #endif // _WSBTRACE_