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.

271 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. trace.h
  5. Abstract:
  6. SIS Groveler debugging trace include file
  7. Authors:
  8. John Douceur, 1998
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #ifndef _INC_TRACE
  14. #define _INC_TRACE
  15. // The following lines are a temporary hack to allow the DPRINTF() and
  16. // TPRINTF() macros in the database.cpp, extract.cpp, groveler.cpp, and
  17. // scan.cpp files to continue to operate. Each instance of the DPRINTF()
  18. // or TPRINTF() macro should be replaced by an instance of the TRACE_PRINTF()
  19. // macro, with an appropriate component parameter (TC_database, TC_extract,
  20. // TC_groveler, or TC_scan) and an appropriate detail parameter. Then, this
  21. // comment block and all lines of code up to the next comment block should
  22. // be deleted.
  23. #define DPRINTF(args) TRACE_PRINTF(TC_groveler, 1, args)
  24. #define TPRINTF(args) TRACE_PRINTF(TC_groveler, 2, args)
  25. #if defined(TRACELEVEL) && DBG
  26. #if TRACELEVEL == 3
  27. #define TRACE_TYPE 2 // immediate printout
  28. #define TRACE_IOSTREAM 2 // print to stderr
  29. #define TRACE_GROVELER 1 // print DPRINTF() but not TPRINTF()
  30. #define TRACE_DATABASE 1
  31. #define TRACE_EXTRACT 1
  32. #define TRACE_SCAN 1
  33. #define TRACE_SISDRIVE 2
  34. #endif // TRACELEVEL == 3
  35. #endif /* TRACELEVEL */
  36. /*
  37. * Define TRACE_TYPE, TRACE_FILENAME, and TRACE_IOSTREAM in sources file.
  38. * These settings take effect at compile time and cannot be changed thereafter.
  39. *
  40. * TRACE_TYPE:
  41. * If not defined, none
  42. * 0 == none
  43. * 1 == delayed
  44. * 2 == immediate
  45. *
  46. * TRACE_FILENAME
  47. * Name of destination file for output of trace prints.
  48. * If not defined, then no output to file.
  49. *
  50. * TRACE_IOSTREAM
  51. * If not defined, no output to stream
  52. * 0 == no output to stream
  53. * 1 == stdout
  54. * 2 == stderr
  55. *
  56. * Define trace contextual detail indicators in sources file if desired.
  57. * These settings provide initial values for variables that may be changed by
  58. * a debugger during run time. Each contextual detail indicator indicates
  59. * the level of trace detail that should be printed for that component.
  60. * Greater numbers indicate greater levels of detail. If an indicator is
  61. * zero or not defined, then no trace information is printed for this
  62. * component (unless the component has a TRACE_PRINTF() macro that specifies
  63. * a detail level of zero, indicating that it should always be displayed in
  64. * a trace). The contextual detail indicators currently supported are:
  65. * TRACE_MAIN
  66. * TRACE_CENTCTRL
  67. * TRACE_CONFEST
  68. * TRACE_DATABASE
  69. * TRACE_DECAYACC
  70. * TRACE_DISKINFO
  71. * TRACE_ETIMER
  72. * TRACE_EVENT
  73. * TRACE_EVENTLOG
  74. * TRACE_EXTRACT
  75. * TRACE_FILTER
  76. * TRACE_GROVELER
  77. * TRACE_MEANCOMP
  78. * TRACE_MUTEX
  79. * TRACE_PARAMS
  80. * TRACE_PARTCTRL
  81. * TRACE_PATHLIST
  82. * TRACE_PEAKFIND
  83. * TRACE_REGISTRY
  84. * TRACE_SCAN
  85. * TRACE_SERVICE
  86. * TRACE_SHARE
  87. * TRACE_SISDRIVE
  88. * TRACE_UTILITY
  89. *
  90. * To add a new component to the trace facility, follow these steps:
  91. * 1) add its name to the comment above
  92. * 2) add an entry to the TraceComponent enumeration below
  93. * 3) add an #ifndef-#define-#endif tuple to the list in trace.cpp
  94. * 4) add an initializer to the trace_components array in trace.cpp
  95. *
  96. * To change the trace detail level for a given component during run time,
  97. * set the element in the trace_detail[] array indexed by the TraceComponent
  98. * enumeration for the desired component to the desired detail level.
  99. *
  100. */
  101. #ifndef TRACE_TYPE
  102. #define TRACE_TYPE 0
  103. #endif /* TRACE_TYPE */
  104. #ifndef TRACE_IOSTREAM
  105. #define TRACE_IOSTREAM 0
  106. #endif /* TRACE_IOSTREAM */
  107. #if TRACE_TYPE > 0
  108. enum TraceComponent
  109. {
  110. TC_main,
  111. TC_centctrl,
  112. TC_confest,
  113. TC_database,
  114. TC_decayacc,
  115. TC_diskinfo,
  116. TC_etimer,
  117. TC_event,
  118. TC_eventlog,
  119. TC_extract,
  120. TC_filter,
  121. TC_groveler,
  122. TC_meancomp,
  123. TC_mutex,
  124. TC_params,
  125. TC_partctrl,
  126. TC_pathlist,
  127. TC_peakfind,
  128. TC_registry,
  129. TC_scan,
  130. TC_service,
  131. TC_share,
  132. TC_sisdrive,
  133. TC_utility,
  134. num_trace_components
  135. };
  136. class Tracer
  137. {
  138. public:
  139. static void trace_printf(
  140. _TCHAR *format,
  141. ...);
  142. #if TRACE_TYPE == 1
  143. static void print_trace_log();
  144. #endif // TRACE_TYPE == 1
  145. #ifdef TRACE_FILENAME
  146. static void open_trace_file();
  147. static void close_trace_file();
  148. #endif /* TRACE_FILENAME */
  149. private:
  150. Tracer() {}
  151. ~Tracer() {}
  152. #if TRACE_TYPE == 1
  153. enum
  154. {
  155. trace_buffer_size = 4000,
  156. trace_entry_limit = 256
  157. };
  158. struct TraceBuffer;
  159. friend struct TraceBuffer;
  160. struct TraceBuffer
  161. {
  162. TraceBuffer *next;
  163. _TCHAR buffer[trace_buffer_size];
  164. };
  165. static int position;
  166. static TraceBuffer *trace_log;
  167. static TraceBuffer *current_buffer;
  168. static TraceBuffer *free_list;
  169. #endif // TRACE_TYPE == 1
  170. #ifdef TRACE_FILENAME
  171. static FILE *file_stream;
  172. #endif /* TRACE_FILENAME */
  173. #if TRACE_IOSTREAM != 0
  174. static FILE *io_stream;
  175. #endif // TRACE_IOSTREAM
  176. };
  177. extern int trace_detail[num_trace_components];
  178. #define TRACE_PRINTF(component, detail, args) \
  179. { \
  180. if (detail <= trace_detail[component]) \
  181. { \
  182. Tracer::trace_printf ## args ; \
  183. } \
  184. }
  185. #if TRACE_TYPE == 1
  186. #define PRINT_TRACE_LOG() Tracer::print_trace_log()
  187. #else // TRACE_TYPE == 1
  188. #define PRINT_TRACE_LOG()
  189. #endif // TRACE_TYPE == 1
  190. #ifdef TRACE_FILENAME
  191. #define OPEN_TRACE_FILE() Tracer::open_trace_file()
  192. #define CLOSE_TRACE_FILE() Tracer::close_trace_file()
  193. #else /* TRACE_FILENAME */
  194. #define OPEN_TRACE_FILE()
  195. #define CLOSE_TRACE_FILE()
  196. #endif /* TRACE_FILENAME */
  197. #else // TRACE_TYPE > 0
  198. #define TRACE_PRINTF(component, detail, args)
  199. #define PRINT_TRACE_LOG()
  200. #define OPEN_TRACE_FILE()
  201. #define CLOSE_TRACE_FILE()
  202. #endif // TRACE_TYPE > 0
  203. #endif /* _INC_TRACE */