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.

297 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. trace.cpp
  5. Abstract:
  6. SIS Groveler debugging tracer
  7. Authors:
  8. John Douceur, 1998
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "all.hxx"
  14. #if TRACE_TYPE > 0
  15. #ifndef TRACE_MAIN
  16. #define TRACE_MAIN 0
  17. #endif /* TRACE_MAIN */
  18. #ifndef TRACE_CENTCTRL
  19. #define TRACE_CENTCTRL 0
  20. #endif /* TRACE_CENTCTRL */
  21. #ifndef TRACE_CONFEST
  22. #define TRACE_CONFEST 0
  23. #endif /* TRACE_CONFEST */
  24. #ifndef TRACE_DATABASE
  25. #define TRACE_DATABASE 0
  26. #endif /* TRACE_DATABASE */
  27. #ifndef TRACE_DECAYACC
  28. #define TRACE_DECAYACC 0
  29. #endif /* TRACE_DECAYACC */
  30. #ifndef TRACE_DISKINFO
  31. #define TRACE_DISKINFO 0
  32. #endif /* TRACE_DISKINFO */
  33. #ifndef TRACE_ETIMER
  34. #define TRACE_ETIMER 0
  35. #endif /* TRACE_ETIMER */
  36. #ifndef TRACE_EVENT
  37. #define TRACE_EVENT 0
  38. #endif /* TRACE_EVENT */
  39. #ifndef TRACE_EVENTLOG
  40. #define TRACE_EVENTLOG 0
  41. #endif /* TRACE_EVENTLOG */
  42. #ifndef TRACE_EXTRACT
  43. #define TRACE_EXTRACT 0
  44. #endif /* TRACE_EXTRACT */
  45. #ifndef TRACE_FILTER
  46. #define TRACE_FILTER 0
  47. #endif /* TRACE_FILTER */
  48. #ifndef TRACE_GROVELER
  49. #define TRACE_GROVELER 0
  50. #endif /* TRACE_GROVELER */
  51. #ifndef TRACE_MEANCOMP
  52. #define TRACE_MEANCOMP 0
  53. #endif /* TRACE_MEANCOMP */
  54. #ifndef TRACE_MUTEX
  55. #define TRACE_MUTEX 0
  56. #endif /* TRACE_MUTEX */
  57. #ifndef TRACE_PARAMS
  58. #define TRACE_PARAMS 0
  59. #endif /* TRACE_PARAMS */
  60. #ifndef TRACE_PARTCTRL
  61. #define TRACE_PARTCTRL 0
  62. #endif /* TRACE_PARTCTRL */
  63. #ifndef TRACE_PATHLIST
  64. #define TRACE_PATHLIST 0
  65. #endif /* TRACE_PATHLIST */
  66. #ifndef TRACE_PEAKFIND
  67. #define TRACE_PEAKFIND 0
  68. #endif /* TRACE_PEAKFIND */
  69. #ifndef TRACE_REGISTRY
  70. #define TRACE_REGISTRY 0
  71. #endif /* TRACE_REGISTRY */
  72. #ifndef TRACE_SCAN
  73. #define TRACE_SCAN 0
  74. #endif /* TRACE_SCAN */
  75. #ifndef TRACE_SERVICE
  76. #define TRACE_SERVICE 0
  77. #endif /* TRACE_SERVICE */
  78. #ifndef TRACE_SHARE
  79. #define TRACE_SHARE 0
  80. #endif /* TRACE_SHARE */
  81. #ifndef TRACE_SISDRIVE
  82. #define TRACE_SISDRIVE 0
  83. #endif /* TRACE_SISDRIVE */
  84. #ifndef TRACE_UTILITY
  85. #define TRACE_UTILITY 0
  86. #endif /* TRACE_UTILITY */
  87. int trace_detail[num_trace_components] =
  88. {
  89. TRACE_MAIN,
  90. TRACE_CENTCTRL,
  91. TRACE_CONFEST,
  92. TRACE_DATABASE,
  93. TRACE_DECAYACC,
  94. TRACE_DISKINFO,
  95. TRACE_ETIMER,
  96. TRACE_EVENT,
  97. TRACE_EVENTLOG,
  98. TRACE_EXTRACT,
  99. TRACE_FILTER,
  100. TRACE_GROVELER,
  101. TRACE_MEANCOMP,
  102. TRACE_MUTEX,
  103. TRACE_PARAMS,
  104. TRACE_PARTCTRL,
  105. TRACE_PATHLIST,
  106. TRACE_PEAKFIND,
  107. TRACE_REGISTRY,
  108. TRACE_SCAN,
  109. TRACE_SERVICE,
  110. TRACE_SHARE,
  111. TRACE_SISDRIVE,
  112. TRACE_UTILITY
  113. };
  114. #if TRACE_TYPE == 1
  115. int Tracer::position = trace_buffer_size;
  116. Tracer::TraceBuffer * Tracer::trace_log = 0;
  117. Tracer::TraceBuffer * Tracer::current_buffer = 0;
  118. Tracer::TraceBuffer * Tracer::free_list = 0;
  119. #endif // TRACE_TYPE == 1
  120. #ifdef TRACE_FILENAME
  121. FILE * Tracer::file_stream = 0;
  122. #endif /* TRACE_FILENAME */
  123. #if TRACE_IOSTREAM == 1
  124. FILE * Tracer::io_stream = stdout;
  125. #elif TRACE_IOSTREAM != 0
  126. FILE * Tracer::io_stream = stderr;
  127. #endif // TRACE_IOSTREAM
  128. void
  129. Tracer::trace_printf(
  130. _TCHAR *format,
  131. ...)
  132. {
  133. ASSERT(format != 0);
  134. #if TRACE_TYPE == 1
  135. if (position >= trace_buffer_size - trace_entry_limit)
  136. {
  137. TraceBuffer *new_buffer;
  138. if (free_list == 0)
  139. {
  140. new_buffer = new TraceBuffer;
  141. }
  142. else
  143. {
  144. new_buffer = free_list;
  145. free_list = free_list->next;
  146. }
  147. ASSERT(new_buffer != 0);
  148. new_buffer->next = 0;
  149. if (current_buffer == 0)
  150. {
  151. trace_log = new_buffer;
  152. }
  153. else
  154. {
  155. current_buffer->next = new_buffer;
  156. }
  157. current_buffer = new_buffer;
  158. position = 0;
  159. }
  160. ASSERT(current_buffer != 0);
  161. va_list ap;
  162. va_start(ap, format);
  163. int result = _vsntprintf(&current_buffer->buffer[position],
  164. trace_entry_limit, format, ap);
  165. va_end(ap);
  166. if (result >= trace_entry_limit || result < 0)
  167. {
  168. position += trace_entry_limit;
  169. _tcscpy(&current_buffer->buffer[position - 4], _T("...\n"));
  170. }
  171. else
  172. {
  173. position += result;
  174. }
  175. ASSERT(position < trace_buffer_size);
  176. #else // TRACE_TYPE == 1
  177. va_list ap;
  178. #ifdef TRACE_FILENAME
  179. if (file_stream != 0)
  180. {
  181. va_start(ap, format);
  182. _vftprintf(file_stream, format, ap);
  183. va_end(ap);
  184. }
  185. #endif /* TRACE_FILENAME */
  186. #if TRACE_IOSTREAM != 0
  187. va_start(ap, format);
  188. _vftprintf(io_stream, format, ap);
  189. va_end(ap);
  190. #endif // TRACE_IOSTREAM != 0
  191. #endif // TRACE_TYPE == 1
  192. }
  193. #if TRACE_TYPE == 1
  194. void
  195. Tracer::print_trace_log()
  196. {
  197. TraceBuffer *buffer = trace_log;
  198. while (buffer != 0)
  199. {
  200. #ifdef TRACE_FILENAME
  201. if (file_stream != 0)
  202. {
  203. _ftprintf(file_stream, _T("%s"), buffer->buffer);
  204. }
  205. #endif /* TRACE_FILENAME */
  206. #if TRACE_IOSTREAM != 0
  207. ASSERT(io_stream != 0);
  208. _ftprintf(io_stream, _T("%s"), buffer->buffer);
  209. #endif // TRACE_IOSTREAM != 0
  210. TraceBuffer *next_buffer = buffer->next;
  211. buffer->next = free_list;
  212. free_list = buffer;
  213. buffer = next_buffer;
  214. }
  215. trace_log = 0;
  216. current_buffer = 0;
  217. position = 0;
  218. }
  219. #endif // TRACE_TYPE == 1
  220. #ifdef TRACE_FILENAME
  221. void Tracer::open_trace_file()
  222. {
  223. file_stream = _tfopen(_T(TRACE_FILENAME), _T("w"));
  224. if (file_stream == 0)
  225. {
  226. PRINT_DEBUG_MSG((_T("GROVELER: Unable to open trace file ") _T(TRACE_FILENAME)));
  227. }
  228. }
  229. void Tracer::close_trace_file()
  230. {
  231. if (file_stream != 0)
  232. {
  233. fclose(file_stream);
  234. }
  235. }
  236. #endif /* TRACE_FILENAME */
  237. #endif // TRACE_TYPE > 0