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.

406 lines
12 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
  3. // Copyright (c) 2002 OSR Open Systems Resources, Inc.
  4. //
  5. // TraceView.h : main header file for the TraceView application
  6. //////////////////////////////////////////////////////////////////////////////
  7. #pragma once
  8. #ifndef __AFXWIN_H__
  9. #error include 'stdafx.h' before including this file for PCH
  10. #endif
  11. #include "resource.h" // main symbols
  12. #if !defined(INLINE)
  13. #define INLINE __inline
  14. #endif
  15. #include "afxtempl.h"
  16. //
  17. // Command line tool stuff
  18. //
  19. #if !defined(EVENT_TRACE_USE_KBYTES_FOR_SIZE)
  20. #define EVENT_TRACE_USE_KBYTES_FOR_SIZE 0x00002000 // Use KBytes as file size unit
  21. #endif
  22. #if !defined(EVENT_TRACE_KD_FILTER_MODE)
  23. #define EVENT_TRACE_KD_FILTER_MODE 0x00080000 // KD_FILTER
  24. #endif
  25. #define DEFAULT_LOG_BUFFER_SIZE 1024
  26. #define SIZEEVENTBUF 32768
  27. #define TRACE_FORMAT_SEARCH_PATH L"TRACE_FORMAT_SEARCH_PATH"
  28. typedef struct _TRACE_ENABLE_FLAG_EXTENSION {
  29. USHORT Offset; // Offset to the flag array in structure
  30. UCHAR Length; // Length of flag array in ULONGs
  31. UCHAR Flag; // Must be set to EVENT_TRACE_FLAG_EXTENSION
  32. } TRACE_ENABLE_FLAG_EXTENSION, *PTRACE_ENABLE_FLAG_EXTENSION;
  33. typedef struct _WMI_CLIENT_CONTEXT {
  34. UCHAR ProcessorNumber;
  35. UCHAR Alignment;
  36. USHORT LoggerId;
  37. } WMI_CLIENT_CONTEXT, *PWMI_CLIENT_CONTEXT;
  38. typedef struct _WMI_BUFFER_STATE {
  39. ULONG Free:1;
  40. ULONG InUse:1;
  41. ULONG Flush:1;
  42. ULONG Unused:29;
  43. } WMI_BUFFER_STATE, *PWMI_BUFFER_STATE;
  44. typedef struct _WMI_BUFFER_HEADER {
  45. union {
  46. WNODE_HEADER Wnode;
  47. struct {
  48. ULONG64 Reserved1;
  49. ULONG64 Reserved2;
  50. LARGE_INTEGER Reserved3;
  51. union{
  52. struct {
  53. PVOID Alignment;
  54. SINGLE_LIST_ENTRY SlistEntry;
  55. };
  56. LIST_ENTRY Entry;
  57. };
  58. };
  59. struct {
  60. LONG ReferenceCount; // Buffer reference count
  61. ULONG SavedOffset; // Temp saved offset
  62. ULONG CurrentOffset; // Current offset
  63. ULONG UsePerfClock; // UsePerfClock flag
  64. LARGE_INTEGER TimeStamp;
  65. GUID Guid;
  66. WMI_CLIENT_CONTEXT ClientContext;
  67. union {
  68. WMI_BUFFER_STATE State;
  69. ULONG Flags;
  70. };
  71. };
  72. };
  73. ULONG Offset;
  74. USHORT BufferFlag;
  75. USHORT BufferType;
  76. union {
  77. GUID InstanceGuid;
  78. struct {
  79. PVOID LoggerContext;
  80. SINGLE_LIST_ENTRY GlobalEntry;
  81. };
  82. };
  83. } WMI_BUFFER_HEADER, *PWMI_BUFFER_HEADER;
  84. typedef struct _WMI_TRACE_PACKET { // must be ULONG!!
  85. USHORT Size;
  86. union{
  87. USHORT HookId;
  88. struct {
  89. UCHAR Type;
  90. UCHAR Group;
  91. };
  92. };
  93. } WMI_TRACE_PACKET, *PWMI_TRACE_PACKET;
  94. //
  95. // 64-bit Trace header for kernel events
  96. //
  97. typedef struct _SYSTEM_TRACE_HEADER {
  98. union {
  99. ULONG Marker;
  100. struct {
  101. USHORT Version;
  102. UCHAR HeaderType;
  103. UCHAR Flags;
  104. };
  105. };
  106. union {
  107. ULONG Header; // both sizes must be the same!
  108. WMI_TRACE_PACKET Packet;
  109. };
  110. ULONG ThreadId;
  111. ULONG ProcessId;
  112. LARGE_INTEGER SystemTime;
  113. ULONG KernelTime;
  114. ULONG UserTime;
  115. } SYSTEM_TRACE_HEADER, *PSYSTEM_TRACE_HEADER;
  116. // Constants
  117. const LONG SIZESUMMARYBLOCK = 16384;
  118. //
  119. // GUI stuff
  120. //
  121. // Log session display flags
  122. #define LOGSESSION_DISPLAY_STATE 0x00000001
  123. #define LOGSESSION_DISPLAY_EVENTCOUNT 0x00000002
  124. #define LOGSESSION_DISPLAY_LOSTEVENTS 0x00000004
  125. #define LOGSESSION_DISPLAY_BUFFERSREAD 0x00000008
  126. #define LOGSESSION_DISPLAY_FLAGS 0x00000010
  127. #define LOGSESSION_DISPLAY_FLUSHTIME 0x00000020
  128. #define LOGSESSION_DISPLAY_MAXBUF 0x00000040
  129. #define LOGSESSION_DISPLAY_MINBUF 0x00000080
  130. #define LOGSESSION_DISPLAY_BUFFERSIZE 0x00000100
  131. #define LOGSESSION_DISPLAY_DECAYTIME 0x00000200
  132. #define LOGSESSION_DISPLAY_CIR 0x00000400
  133. #define LOGSESSION_DISPLAY_SEQ 0x00000800
  134. #define LOGSESSION_DISPLAY_NEWFILE 0x00001000
  135. #define LOGSESSION_DISPLAY_GLOBALSEQ 0x00002000
  136. #define LOGSESSION_DISPLAY_LOCALSEQ 0x00004000
  137. #define LOGSESSION_DISPLAY_LEVEL 0x00008000
  138. //
  139. // Log session column numbers
  140. //
  141. typedef enum _LOG_SESSION_OPTIONS {
  142. State=0,
  143. EventCount,
  144. LostEvents,
  145. BuffersRead,
  146. Flags,
  147. FlushTime,
  148. MaximumBuffers,
  149. MinimumBuffers,
  150. BufferSize,
  151. DecayTime,
  152. Circular,
  153. Sequential,
  154. NewFile,
  155. GlobalSequence,
  156. LocalSequence,
  157. Level,
  158. MaxLogSessionOptions
  159. } LOG_SESSION_OPTIONS,*PLOG_SESSION_OPTIONS;
  160. // Trace output display flags
  161. // if we ever go over 32 items, we will just create
  162. // another set of 32 'extended' flags
  163. #define TRACEOUTPUT_DISPLAY_PROVIDERNAME 0x00000001
  164. #define TRACEOUTPUT_DISPLAY_FILENAME 0x00000002
  165. #define TRACEOUTPUT_DISPLAY_LINENUMBER 0x00000004
  166. #define TRACEOUTPUT_DISPLAY_FUNCTIONNAME 0x00000008
  167. #define TRACEOUTPUT_DISPLAY_PROCESSID 0x00000010
  168. #define TRACEOUTPUT_DISPLAY_THREADID 0x00000020
  169. #define TRACEOUTPUT_DISPLAY_CPUNUMBER 0x00000040
  170. #define TRACEOUTPUT_DISPLAY_SEQNUMBER 0x00000080
  171. #define TRACEOUTPUT_DISPLAY_SYSTEMTIME 0x00000100
  172. #define TRACEOUTPUT_DISPLAY_KERNELTIME 0x00000200
  173. #define TRACEOUTPUT_DISPLAY_USERTIME 0x00000400
  174. #define TRACEOUTPUT_DISPLAY_INDENT 0x00000800
  175. #define TRACEOUTPUT_DISPLAY_FLAGSNAME 0x00001000
  176. #define TRACEOUTPUT_DISPLAY_LEVELNAME 0x00002000
  177. #define TRACEOUTPUT_DISPLAY_COMPNAME 0x00004000
  178. #define TRACEOUTPUT_DISPLAY_SUBCOMPNAME 0x00008000
  179. #define TRACEOUTPUT_DISPLAY_MESSAGE 0x00010000
  180. // Trace output column numbers
  181. typedef enum _TRACE_OUTPUT_COLUMNS {
  182. ProviderName = 0,
  183. FileName,
  184. LineNumber,
  185. FunctionName,
  186. ProcessId,
  187. ThreadId,
  188. CpuNumber,
  189. SeqNumber,
  190. SystemTime,
  191. KernelTime,
  192. UserTime,
  193. Indent,
  194. FlagsName,
  195. LevelName,
  196. ComponentName,
  197. SubComponentName,
  198. Message,
  199. MaxTraceSessionOptions
  200. } TRACE_SESSION_OPTIONS,*PTRACE_SESSION_OPTIONS;
  201. //
  202. // Log session state values
  203. //
  204. typedef enum _LOG_SESSION_STATE {
  205. Stopped=0,
  206. Stopping,
  207. Running,
  208. Existing,
  209. Grouping,
  210. UnGrouping
  211. } LOG_SESSION_STATE,*PLOG_SESSION_STATE;
  212. typedef struct _MOF_INFO
  213. {
  214. LIST_ENTRY Entry;
  215. LPTSTR strDescription;
  216. ULONG EventCount;
  217. GUID Guid;
  218. PLIST_ENTRY ItemHeader;
  219. LPTSTR strType;
  220. LONG TypeIndex;
  221. ULONG TypeOfType;
  222. LPTSTR TypeFormat;
  223. INT Indent;
  224. } MOF_INFO, *PMOF_INFO;
  225. typedef void (*PEND_TRACE_COMPLETE_CALLBACK)(PVOID pContext);
  226. const ULONG CHAR_PIXELS_WIDTH = 11;
  227. const ULONG MAX_LOG_SESSIONS = 64;
  228. const ULONG EVENT_BUFFER_SIZE = 32768;
  229. const MAX_STR_LENGTH = 1024;
  230. const MAX_ENABLE_FLAGS = 10;
  231. const HDN_ITEMRCLICK = (HDN_LAST - 1);
  232. //
  233. // Custom messages
  234. //
  235. CONST LONG WM_PARAMETER_CHANGED = (WM_USER + 0x1000);
  236. CONST LONG WM_USER_START_GROUP = (WM_USER + 0x1001);
  237. CONST LONG WM_USER_COMPLETE_GROUP = (WM_USER + 0x1002);
  238. CONST LONG WM_USER_START_UNGROUP = (WM_USER + 0x1003);
  239. CONST LONG WM_USER_COMPLETE_UNGROUP = (WM_USER + 0x1004);
  240. CONST LONG WM_USER_UPDATE_LOGSESSION_LIST = (WM_USER + 0x1005);
  241. CONST LONG WM_USER_UPDATE_LOGSESSION_DATA = (WM_USER + 0x1006);
  242. CONST LONG WM_USER_TRACE_DONE = (WM_USER + 0x1007);
  243. CONST LONG WM_USER_AUTOSIZECOLUMNS = (WM_USER + 0x1008);
  244. //
  245. // Our trace event message formatting class
  246. //
  247. class CTraceMessage
  248. {
  249. public:
  250. CTraceMessage() {};
  251. ~CTraceMessage() {};
  252. GUID m_TraceGuid; // Message Guid
  253. CString m_GuidName; // %1 Guid Friendly Name String
  254. CString m_GuidTypeName; // %2 Guid Type Name String
  255. ULONG m_ThreadId; // %3 Thread ID Value
  256. SYSTEMTIME m_SystemTime; // %4 System Time Value
  257. ULONG m_UserTime; // %5 Kernel Time Value
  258. ULONG m_KernelTime; // %6 User Time Value
  259. ULONG m_SequenceNum; // %7 Sequence Number Value
  260. ULONG m_ProcessId; // %8 Process ID Value
  261. ULONG m_CpuNumber; // %9 CPU Number Value
  262. ULONG m_Indent; // Indentation level Value
  263. CString m_FlagsName; // Trace Flag settings Name String
  264. CString m_LevelName; // Trace Level Name String
  265. CString m_FunctionName; // Function Name String
  266. CString m_ComponentName; // Component Name String
  267. CString m_SubComponentName; // SubComponent Name String
  268. CString m_Message; // Message String
  269. };
  270. // CTraceViewApp:
  271. // See TraceView.cpp for the implementation of this class
  272. //
  273. class CTraceViewApp : public CWinApp
  274. {
  275. public:
  276. CTraceViewApp();
  277. ~CTraceViewApp();
  278. BOOL InitializeConsole();
  279. LONG CommandLine();
  280. LONG StartSession();
  281. LONG StopSession();
  282. LONG ListActiveSessions(BOOL bKill);
  283. LONG QueryActiveSession();
  284. LONG FlushActiveBuffers();
  285. LONG UpdateActiveSession();
  286. LONG EnumerateRegisteredGuids();
  287. LONG EnableProvider(BOOL bEnable);
  288. LONG ConsumeTraceEvents();
  289. LONG ExtractPdbInfo();
  290. void DisplayHelp();
  291. void PrintLoggerStatus(ULONG Status);
  292. LPCTSTR DecodeStatus(ULONG Status);
  293. LONG GetGuids(LPCTSTR GuidFile);
  294. void sync_with_stdio();
  295. void DisplayVersionInfo();
  296. BOOL CheckFile(LPTSTR fileName);
  297. static ULONG BufferCallback(PEVENT_TRACE_LOGFILE pLog);
  298. static void DumpEvent(PEVENT_TRACE pEvent);
  299. CTraceMessage *AllocateTraceEventBlock();
  300. void FreeTraceEventBlocks(CArray<CTraceMessage*, CTraceMessage*> &TraceArray);
  301. // Overrides
  302. public:
  303. virtual BOOL InitInstance();
  304. virtual int ExitInstance();
  305. virtual BOOL OnIdle(LONG lCount);
  306. // Implementation
  307. public:
  308. afx_msg void OnAppAbout();
  309. CString m_traceDirectory;
  310. CArray<CTraceMessage*, CTraceMessage*> m_traceBlockArray;
  311. HANDLE m_hTraceBlockMutex;
  312. //
  313. // member variables used for control command line interface
  314. //
  315. PEVENT_TRACE_PROPERTIES m_pLoggerInfo;
  316. CString m_errorMsg;
  317. ULONG m_globalLoggerStartValue;
  318. CStringArray m_guidArray;
  319. BOOL m_bCreatedConsole;
  320. //
  321. // member variables used for consumption command line interface
  322. //
  323. FILE *m_pDumpFile;
  324. FILE *m_pSummaryFile;
  325. BOOL m_bDebugDisplay;
  326. BOOL m_bDisplayOnly;
  327. BOOL m_bSummaryOnly;
  328. BOOL m_bNoSummary;
  329. BOOL m_bVerbose;
  330. BOOL m_bFixUp;
  331. BOOL m_bODSOutput;
  332. BOOL m_bTMFSpecified;
  333. BOOL m_bCSVMode;
  334. BOOL m_bNoCSVHeader;
  335. BOOL m_bCSVHeader;
  336. TCHAR m_summaryBlock[SIZESUMMARYBLOCK];
  337. PEVENT_TRACE_LOGFILE m_evmFile[MAXLOGFILES];
  338. ULONG m_logFileCount;
  339. ULONG m_userMode;
  340. TCHAR *m_traceMask;
  341. TCHAR m_eventBuf[SIZEEVENTBUF];
  342. BYTE m_eventBufCSV[SIZEEVENTBUF * sizeof(TCHAR)];
  343. CHAR m_eventBufA[SIZEEVENTBUF*sizeof(WCHAR)];
  344. FILETIME m_lastTime;
  345. ULONG m_totalBuffersRead;
  346. ULONG m_totalEventsLost;
  347. ULONG m_totalEventCount;
  348. ULONG m_timerResolution;
  349. ULONG m_bufferWrap;
  350. __int64 m_elapseTime;
  351. PLIST_ENTRY m_eventListHead;
  352. DECLARE_MESSAGE_MAP()
  353. afx_msg void OnHelpHelpTopics();
  354. };
  355. extern CTraceViewApp theApp;