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.

1113 lines
33 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. EvnTrace.h
  5. Abstract:
  6. Public headers for event tracing control applications,
  7. consumers and providers
  8. --*/
  9. #ifndef _EVNTRACE_
  10. #define _EVNTRACE_
  11. #if defined(_WINNT_) || defined(WINNT)
  12. #ifndef WMIAPI
  13. #ifndef MIDL_PASS
  14. #ifdef _WMI_SOURCE_
  15. #define WMIAPI __stdcall
  16. #else
  17. #define WMIAPI DECLSPEC_IMPORT __stdcall
  18. #endif // _WMI_SOURCE
  19. #endif // MIDL_PASS
  20. #endif // WMIAPI
  21. #include <guiddef.h>
  22. //
  23. // EventTraceGuid is used to identify a event tracing session
  24. //
  25. DEFINE_GUID ( /* 68fdd900-4a3e-11d1-84f4-0000f80464e3 */
  26. EventTraceGuid,
  27. 0x68fdd900,
  28. 0x4a3e,
  29. 0x11d1,
  30. 0x84, 0xf4, 0x00, 0x00, 0xf8, 0x04, 0x64, 0xe3
  31. );
  32. //
  33. // SystemTraceControlGuid. Used to specify event tracing for kernel
  34. //
  35. DEFINE_GUID ( /* 9e814aad-3204-11d2-9a82-006008a86939 */
  36. SystemTraceControlGuid,
  37. 0x9e814aad,
  38. 0x3204,
  39. 0x11d2,
  40. 0x9a, 0x82, 0x00, 0x60, 0x08, 0xa8, 0x69, 0x39
  41. );
  42. //
  43. // EventTraceConfigGuid. Used to report system configuration records
  44. //
  45. DEFINE_GUID ( /* 01853a65-418f-4f36-aefc-dc0f1d2fd235 */
  46. EventTraceConfigGuid,
  47. 0x01853a65,
  48. 0x418f,
  49. 0x4f36,
  50. 0xae, 0xfc, 0xdc, 0x0f, 0x1d, 0x2f, 0xd2, 0x35
  51. );
  52. //
  53. // DefaultTraceSecurityGuid. Specifies the default event tracing security
  54. //
  55. DEFINE_GUID ( /* 0811c1af-7a07-4a06-82ed-869455cdf713 */
  56. DefaultTraceSecurityGuid,
  57. 0x0811c1af,
  58. 0x7a07,
  59. 0x4a06,
  60. 0x82, 0xed, 0x86, 0x94, 0x55, 0xcd, 0xf7, 0x13
  61. );
  62. #define KERNEL_LOGGER_NAMEW L"NT Kernel Logger"
  63. #define GLOBAL_LOGGER_NAMEW L"GlobalLogger"
  64. #define EVENT_LOGGER_NAMEW L"Event Log"
  65. #define KERNEL_LOGGER_NAMEA "NT Kernel Logger"
  66. #define GLOBAL_LOGGER_NAMEA "GlobalLogger"
  67. #define EVENT_LOGGER_NAMEA "Event Log"
  68. #define MAX_MOF_FIELDS 16 // Limit of USE_MOF_PTR fields
  69. typedef ULONG64 TRACEHANDLE, *PTRACEHANDLE;
  70. //
  71. // predefined generic event types (0x00 to 0x09 reserved).
  72. //
  73. #define EVENT_TRACE_TYPE_INFO 0x00 // Info or point event
  74. #define EVENT_TRACE_TYPE_START 0x01 // Start event
  75. #define EVENT_TRACE_TYPE_END 0x02 // End event
  76. #define EVENT_TRACE_TYPE_DC_START 0x03 // Collection start marker
  77. #define EVENT_TRACE_TYPE_DC_END 0x04 // Collection end marker
  78. #define EVENT_TRACE_TYPE_EXTENSION 0x05 // Extension/continuation
  79. #define EVENT_TRACE_TYPE_REPLY 0x06 // Reply event
  80. #define EVENT_TRACE_TYPE_DEQUEUE 0x07 // De-queue event
  81. #define EVENT_TRACE_TYPE_CHECKPOINT 0x08 // Generic checkpoint event
  82. #define EVENT_TRACE_TYPE_RESERVED9 0x09
  83. //
  84. // Predefined Event Tracing Levels for Software/Debug Tracing
  85. //
  86. //
  87. // Trace Level is UCHAR and passed in through the EnableLevel parameter
  88. // in EnableTrace API. It is retrieved by the provider using the
  89. // GetTraceEnableLevel macro.It should be interpreted as an integer value
  90. // to mean everything at or below that level will be traced.
  91. //
  92. // Here are the possible Levels.
  93. //
  94. #define TRACE_LEVEL_NONE 0 // Tracing is not on
  95. #define TRACE_LEVEL_FATAL 1 // Abnormal exit or termination
  96. #define TRACE_LEVEL_ERROR 2 // Severe errors that need logging
  97. #define TRACE_LEVEL_WARNING 3 // Warnings such as allocation failure
  98. #define TRACE_LEVEL_INFORMATION 4 // Includes non-error cases(e.g.,Entry-Exit)
  99. #define TRACE_LEVEL_VERBOSE 5 // Detailed traces from intermediate steps
  100. #define TRACE_LEVEL_RESERVED6 6
  101. #define TRACE_LEVEL_RESERVED7 7
  102. #define TRACE_LEVEL_RESERVED8 8
  103. #define TRACE_LEVEL_RESERVED9 9
  104. //
  105. // Event types for Process & Threads
  106. //
  107. #define EVENT_TRACE_TYPE_LOAD 0x0A // Load image
  108. //
  109. // Event types for IO subsystem
  110. //
  111. #define EVENT_TRACE_TYPE_IO_READ 0x0A
  112. #define EVENT_TRACE_TYPE_IO_WRITE 0x0B
  113. //
  114. // Event types for Memory subsystem
  115. //
  116. #define EVENT_TRACE_TYPE_MM_TF 0x0A // Transition fault
  117. #define EVENT_TRACE_TYPE_MM_DZF 0x0B // Demand Zero fault
  118. #define EVENT_TRACE_TYPE_MM_COW 0x0C // Copy on Write
  119. #define EVENT_TRACE_TYPE_MM_GPF 0x0D // Guard Page fault
  120. #define EVENT_TRACE_TYPE_MM_HPF 0x0E // Hard page fault
  121. //
  122. // Event types for Network subsystem, all protocols
  123. //
  124. #define EVENT_TRACE_TYPE_SEND 0x0A // Send
  125. #define EVENT_TRACE_TYPE_RECEIVE 0x0B // Receive
  126. #define EVENT_TRACE_TYPE_CONNECT 0x0C // Connect
  127. #define EVENT_TRACE_TYPE_DISCONNECT 0x0D // Disconnect
  128. #define EVENT_TRACE_TYPE_RETRANSMIT 0x0E // ReTransmit
  129. #define EVENT_TRACE_TYPE_ACCEPT 0x0F // Accept
  130. #define EVENT_TRACE_TYPE_RECONNECT 0x10 // ReConnect
  131. //
  132. // Event Types for the Header (to handle internal event headers)
  133. //
  134. #define EVENT_TRACE_TYPE_GUIDMAP 0x0A
  135. #define EVENT_TRACE_TYPE_CONFIG 0x0B
  136. #define EVENT_TRACE_TYPE_SIDINFO 0x0C
  137. #define EVENT_TRACE_TYPE_SECURITY 0x0D
  138. //
  139. // Event types for Registry subsystem
  140. //
  141. #define EVENT_TRACE_TYPE_REGCREATE 0x0A // NtCreateKey
  142. #define EVENT_TRACE_TYPE_REGOPEN 0x0B // NtOpenKey
  143. #define EVENT_TRACE_TYPE_REGDELETE 0x0C // NtDeleteKey
  144. #define EVENT_TRACE_TYPE_REGQUERY 0x0D // NtQueryKey
  145. #define EVENT_TRACE_TYPE_REGSETVALUE 0x0E // NtSetValueKey
  146. #define EVENT_TRACE_TYPE_REGDELETEVALUE 0x0F // NtDeleteValueKey
  147. #define EVENT_TRACE_TYPE_REGQUERYVALUE 0x10 // NtQueryValueKey
  148. #define EVENT_TRACE_TYPE_REGENUMERATEKEY 0x11 // NtEnumerateKey
  149. #define EVENT_TRACE_TYPE_REGENUMERATEVALUEKEY 0x12 // NtEnumerateValueKey
  150. #define EVENT_TRACE_TYPE_REGQUERYMULTIPLEVALUE 0x13 // NtQueryMultipleValueKey
  151. #define EVENT_TRACE_TYPE_REGSETINFORMATION 0x14 // NtSetInformationKey
  152. #define EVENT_TRACE_TYPE_REGFLUSH 0x15 // NtFlushKey
  153. #define EVENT_TRACE_TYPE_REGKCBDMP 0x16 // KcbDump/create
  154. //
  155. // Event types for system configuration records
  156. //
  157. #define EVENT_TRACE_TYPE_CONFIG_CPU 0x0A // CPU Configuration
  158. #define EVENT_TRACE_TYPE_CONFIG_PHYSICALDISK 0x0B // Physical Disk Configuration
  159. #define EVENT_TRACE_TYPE_CONFIG_LOGICALDISK 0x0C // Logical Disk Configuration
  160. #define EVENT_TRACE_TYPE_CONFIG_NIC 0x0D // NIC Configuration
  161. #define EVENT_TRACE_TYPE_CONFIG_VIDEO 0x0E // Video Adapter Configuration
  162. #define EVENT_TRACE_TYPE_CONFIG_SERVICES 0x0F // Active Services
  163. #define EVENT_TRACE_TYPE_CONFIG_POWER 0x10 // ACPI Configuration
  164. //
  165. // Enable flags for SystemControlGuid only
  166. //
  167. #define EVENT_TRACE_FLAG_PROCESS 0x00000001 // process start & end
  168. #define EVENT_TRACE_FLAG_THREAD 0x00000002 // thread start & end
  169. #define EVENT_TRACE_FLAG_IMAGE_LOAD 0x00000004 // image load
  170. #define EVENT_TRACE_FLAG_DISK_IO 0x00000100 // physical disk IO
  171. #define EVENT_TRACE_FLAG_DISK_FILE_IO 0x00000200 // requires disk IO
  172. #define EVENT_TRACE_FLAG_MEMORY_PAGE_FAULTS 0x00001000 // all page faults
  173. #define EVENT_TRACE_FLAG_MEMORY_HARD_FAULTS 0x00002000 // hard faults only
  174. #define EVENT_TRACE_FLAG_NETWORK_TCPIP 0x00010000 // tcpip send & receive
  175. #define EVENT_TRACE_FLAG_REGISTRY 0x00020000 // registry calls
  176. #define EVENT_TRACE_FLAG_DBGPRINT 0x00040000 // DbgPrint(ex) Calls
  177. //
  178. // Pre-defined Enable flags for everybody else
  179. //
  180. #define EVENT_TRACE_FLAG_EXTENSION 0x80000000 // indicates more flags
  181. #define EVENT_TRACE_FLAG_FORWARD_WMI 0x40000000 // Can forward to WMI
  182. #define EVENT_TRACE_FLAG_ENABLE_RESERVE 0x20000000 // Reserved
  183. //
  184. // Logger Mode flags
  185. //
  186. #define EVENT_TRACE_FILE_MODE_NONE 0x00000000 // logfile is off
  187. #define EVENT_TRACE_FILE_MODE_SEQUENTIAL 0x00000001 // log sequentially
  188. #define EVENT_TRACE_FILE_MODE_CIRCULAR 0x00000002 // log in circular manner
  189. #define EVENT_TRACE_FILE_MODE_APPEND 0x00000004 // append sequential log
  190. #define EVENT_TRACE_FILE_MODE_NEWFILE 0x00000008 // auto-switch log file
  191. #define EVENT_TRACE_FILE_MODE_PREALLOCATE 0x00000020 // pre-allocate mode
  192. #define EVENT_TRACE_REAL_TIME_MODE 0x00000100 // real time mode on
  193. #define EVENT_TRACE_DELAY_OPEN_FILE_MODE 0x00000200 // delay opening file
  194. #define EVENT_TRACE_BUFFERING_MODE 0x00000400 // buffering mode only
  195. #define EVENT_TRACE_PRIVATE_LOGGER_MODE 0x00000800 // Process Private Logger
  196. #define EVENT_TRACE_ADD_HEADER_MODE 0x00001000 // Add a logfile header
  197. #define EVENT_TRACE_USE_GLOBAL_SEQUENCE 0x00004000 // Use global sequence no.
  198. #define EVENT_TRACE_USE_LOCAL_SEQUENCE 0x00008000 // Use local sequence no.
  199. #define EVENT_TRACE_RELOG_MODE 0x00010000 // Relogger
  200. #define EVENT_TRACE_USE_PAGED_MEMORY 0x01000000 // Use pageable buffers
  201. //
  202. // internal control codes used.
  203. //
  204. #define EVENT_TRACE_CONTROL_QUERY 0
  205. #define EVENT_TRACE_CONTROL_STOP 1
  206. #define EVENT_TRACE_CONTROL_UPDATE 2
  207. #define EVENT_TRACE_CONTROL_FLUSH 3 // Flushes all the buffers
  208. //
  209. // Flags used by WMI Trace Message
  210. // Note that the order or value of these flags should NOT be changed as they are processed
  211. // in this order.
  212. //
  213. #define TRACE_MESSAGE_SEQUENCE 1 // Message should include a sequence number
  214. #define TRACE_MESSAGE_GUID 2 // Message includes a GUID
  215. #define TRACE_MESSAGE_COMPONENTID 4 // Message has no GUID, Component ID instead
  216. #define TRACE_MESSAGE_TIMESTAMP 8 // Message includes a timestamp
  217. #define TRACE_MESSAGE_PERFORMANCE_TIMESTAMP 16 // *Obsolete* Clock type is controlled by the logger
  218. #define TRACE_MESSAGE_SYSTEMINFO 32 // Message includes system information TID,PID
  219. #define TRACE_MESSAGE_FLAG_MASK 0xFFFF // Only the lower 16 bits of flags are placed in the message
  220. // those above 16 bits are reserved for local processing
  221. #define TRACE_MESSAGE_MAXIMUM_SIZE 8*1024 // the maximum size allowed for a single trace message
  222. // longer messages will return ERROR_BUFFER_OVERFLOW
  223. //
  224. // Flags to indicate to consumer which fields
  225. // in the EVENT_TRACE_HEADER are valid
  226. //
  227. #define EVENT_TRACE_USE_PROCTIME 0x0001 // ProcessorTime field is valid
  228. #define EVENT_TRACE_USE_NOCPUTIME 0x0002 // No Kernel/User/Processor Times
  229. #if _MSC_VER >= 1200
  230. #pragma warning(push)
  231. #endif
  232. #pragma warning (disable:4201)
  233. //
  234. // Trace header for all (except kernel) events. This is used to overlay
  235. // to bottom part of WNODE_HEADER to conserve space.
  236. //
  237. typedef struct _EVENT_TRACE_HEADER { // overlays WNODE_HEADER
  238. USHORT Size; // Size of entire record
  239. union {
  240. USHORT FieldTypeFlags; // Indicates valid fields
  241. struct {
  242. UCHAR HeaderType; // Header type - internal use only
  243. UCHAR MarkerFlags; // Marker - internal use only
  244. };
  245. };
  246. union {
  247. ULONG Version;
  248. struct {
  249. UCHAR Type; // event type
  250. UCHAR Level; // trace instrumentation level
  251. USHORT Version; // version of trace record
  252. } Class;
  253. };
  254. ULONG ThreadId; // Thread Id
  255. ULONG ProcessId; // Process Id
  256. LARGE_INTEGER TimeStamp; // time when event happens
  257. union {
  258. GUID Guid; // Guid that identifies event
  259. ULONGLONG GuidPtr; // use with WNODE_FLAG_USE_GUID_PTR
  260. };
  261. union {
  262. struct {
  263. ULONG ClientContext; // Reserved
  264. ULONG Flags; // Flags for header
  265. };
  266. struct {
  267. ULONG KernelTime; // Kernel Mode CPU ticks
  268. ULONG UserTime; // User mode CPU ticks
  269. };
  270. ULONG64 ProcessorTime; // Processor Clock
  271. };
  272. } EVENT_TRACE_HEADER, *PEVENT_TRACE_HEADER;
  273. //
  274. // This header is used to trace and track transaction co-relations
  275. //
  276. typedef struct _EVENT_INSTANCE_HEADER {
  277. USHORT Size;
  278. union {
  279. USHORT FieldTypeFlags; // Indicates valid fields
  280. struct {
  281. UCHAR HeaderType; // Header type - internal use only
  282. UCHAR MarkerFlags; // Marker - internal use only
  283. };
  284. };
  285. union {
  286. ULONG Version;
  287. struct {
  288. UCHAR Type;
  289. UCHAR Level;
  290. USHORT Version;
  291. } Class;
  292. };
  293. ULONG ThreadId;
  294. ULONG ProcessId;
  295. LARGE_INTEGER TimeStamp;
  296. ULONGLONG RegHandle;
  297. ULONG InstanceId;
  298. ULONG ParentInstanceId;
  299. union {
  300. struct {
  301. ULONG ClientContext; // Reserved
  302. ULONG Flags; // Flags for header
  303. };
  304. struct {
  305. ULONG KernelTime; // Kernel Mode CPU ticks
  306. ULONG UserTime; // User mode CPU ticks
  307. };
  308. ULONG64 ProcessorTime; // Processor Clock
  309. };
  310. ULONGLONG ParentRegHandle;
  311. } EVENT_INSTANCE_HEADER, *PEVENT_INSTANCE_HEADER;
  312. //
  313. // Following are structures and macros for use with USE_MOF_PTR
  314. //
  315. #define DEFINE_TRACE_MOF_FIELD(MOF, ptr, length, type) \
  316. (MOF)->DataPtr = (ULONG64) ptr; \
  317. (MOF)->Length = (ULONG) length; \
  318. (MOF)->DataType = (ULONG) type;
  319. typedef struct _MOF_FIELD {
  320. ULONG64 DataPtr; // Pointer to the field. Up to 64-bits only
  321. ULONG Length; // Length of the MOF field
  322. ULONG DataType; // Type of data
  323. } MOF_FIELD, *PMOF_FIELD;
  324. #if !(defined(_NTDDK_) || defined(_NTIFS_)) || defined(_WMIKM_)
  325. //
  326. // This is the header for every logfile. The memory for LoggerName
  327. // and LogFileName must be contiguous adjacent to this structure
  328. // Allows both user-mode and kernel-mode to understand the header
  329. //
  330. typedef struct _TRACE_LOGFILE_HEADER {
  331. ULONG BufferSize; // Logger buffer size in Kbytes
  332. union {
  333. ULONG Version; // Logger version
  334. struct {
  335. UCHAR MajorVersion;
  336. UCHAR MinorVersion;
  337. UCHAR SubVersion;
  338. UCHAR SubMinorVersion;
  339. } VersionDetail;
  340. };
  341. ULONG ProviderVersion; // defaults to NT version
  342. ULONG NumberOfProcessors; // Number of Processors
  343. LARGE_INTEGER EndTime; // Time when logger stops
  344. ULONG TimerResolution; // assumes timer is constant!!!
  345. ULONG MaximumFileSize; // Maximum in Mbytes
  346. ULONG LogFileMode; // specify logfile mode
  347. ULONG BuffersWritten; // used to file start of Circular File
  348. union {
  349. GUID LogInstanceGuid; // For RealTime Buffer Delivery
  350. struct {
  351. ULONG StartBuffers; // Count of buffers written at start.
  352. ULONG PointerSize; // Size of pointer type in bits
  353. ULONG EventsLost; // Events losts during log session
  354. ULONG CpuSpeedInMHz; // Cpu Speed in MHz
  355. };
  356. };
  357. #if defined(_WMIKM_)
  358. PWCHAR LoggerName;
  359. PWCHAR LogFileName;
  360. RTL_TIME_ZONE_INFORMATION TimeZone;
  361. #else
  362. LPWSTR LoggerName;
  363. LPWSTR LogFileName;
  364. TIME_ZONE_INFORMATION TimeZone;
  365. #endif
  366. LARGE_INTEGER BootTime;
  367. LARGE_INTEGER PerfFreq; // Reserved
  368. LARGE_INTEGER StartTime; // Reserved
  369. ULONG ReservedFlags; // Reserved
  370. ULONG BuffersLost;
  371. } TRACE_LOGFILE_HEADER, *PTRACE_LOGFILE_HEADER;
  372. #endif // !_NTDDK_ || _WMIKM_
  373. //
  374. // Instance Information to track parent child relationship of Instances.
  375. //
  376. typedef struct EVENT_INSTANCE_INFO {
  377. HANDLE RegHandle;
  378. ULONG InstanceId;
  379. } EVENT_INSTANCE_INFO, *PEVENT_INSTANCE_INFO;
  380. #if !defined(_WMIKM_) && !defined(_NTDDK_) && !defined(_NTIFS_)
  381. //
  382. // Structures that have UNICODE and ANSI versions are defined here
  383. //
  384. //
  385. // Logger configuration and running statistics. This structure is used
  386. // by user-mode callers, such as PDH library
  387. //
  388. typedef struct _EVENT_TRACE_PROPERTIES {
  389. WNODE_HEADER Wnode;
  390. //
  391. // data provided by caller
  392. ULONG BufferSize; // buffer size for logging (kbytes)
  393. ULONG MinimumBuffers; // minimum to preallocate
  394. ULONG MaximumBuffers; // maximum buffers allowed
  395. ULONG MaximumFileSize; // maximum logfile size (in MBytes)
  396. ULONG LogFileMode; // sequential, circular
  397. ULONG FlushTimer; // buffer flush timer, in seconds
  398. ULONG EnableFlags; // trace enable flags
  399. LONG AgeLimit; // age decay time, in minutes
  400. // data returned to caller
  401. ULONG NumberOfBuffers; // no of buffers in use
  402. ULONG FreeBuffers; // no of buffers free
  403. ULONG EventsLost; // event records lost
  404. ULONG BuffersWritten; // no of buffers written to file
  405. ULONG LogBuffersLost; // no of logfile write failures
  406. ULONG RealTimeBuffersLost; // no of rt delivery failures
  407. HANDLE LoggerThreadId; // thread id of Logger
  408. ULONG LogFileNameOffset; // Offset to LogFileName
  409. ULONG LoggerNameOffset; // Offset to LoggerName
  410. } EVENT_TRACE_PROPERTIES, *PEVENT_TRACE_PROPERTIES;
  411. // NOTE:
  412. // If AgeLimit is 0, default is used
  413. // If AgeLimit is < 0, buffer aging is turned off
  414. typedef struct _TRACE_GUID_PROPERTIES {
  415. GUID Guid;
  416. ULONG GuidType;
  417. ULONG LoggerId;
  418. ULONG EnableLevel;
  419. ULONG EnableFlags;
  420. BOOLEAN IsEnable;
  421. } TRACE_GUID_PROPERTIES, *PTRACE_GUID_PROPERTIES;
  422. //
  423. // Data Provider structures
  424. //
  425. // Used by RegisterTraceGuids()
  426. typedef struct _TRACE_GUID_REGISTRATION {
  427. LPCGUID Guid; // Guid of data block being registered or updated.
  428. HANDLE RegHandle; // Guid Registration Handle is returned.
  429. } TRACE_GUID_REGISTRATION, *PTRACE_GUID_REGISTRATION;
  430. //
  431. // Data consumer structures
  432. //
  433. // An EVENT_TRACE consists of a fixed header (EVENT_TRACE_HEADER) and
  434. // optionally a variable portion pointed to by MofData. The datablock
  435. // layout of the variable portion is unknown to the Logger and must
  436. // be obtained from WBEM CIMOM database.
  437. //
  438. typedef struct _EVENT_TRACE {
  439. EVENT_TRACE_HEADER Header; // Event trace header
  440. ULONG InstanceId; // Instance Id of this event
  441. ULONG ParentInstanceId; // Parent Instance Id.
  442. GUID ParentGuid; // Parent Guid;
  443. PVOID MofData; // Pointer to Variable Data
  444. ULONG MofLength; // Variable Datablock Length
  445. ULONG ClientContext; // Reserved
  446. } EVENT_TRACE, *PEVENT_TRACE;
  447. typedef struct _EVENT_TRACE_LOGFILEW
  448. EVENT_TRACE_LOGFILEW, *PEVENT_TRACE_LOGFILEW;
  449. typedef struct _EVENT_TRACE_LOGFILEA
  450. EVENT_TRACE_LOGFILEA, *PEVENT_TRACE_LOGFILEA;
  451. typedef ULONG (WINAPI * PEVENT_TRACE_BUFFER_CALLBACKW)
  452. (PEVENT_TRACE_LOGFILEW Logfile);
  453. typedef ULONG (WINAPI * PEVENT_TRACE_BUFFER_CALLBACKA)
  454. (PEVENT_TRACE_LOGFILEA Logfile);
  455. typedef VOID (WINAPI *PEVENT_CALLBACK)( PEVENT_TRACE pEvent );
  456. //
  457. // Prototype for service request callback. Data providers register with WMI
  458. // by passing a service request callback function that is called for all
  459. // wmi requests.
  460. typedef ULONG (
  461. #ifndef MIDL_PASS
  462. WINAPI
  463. #endif
  464. *WMIDPREQUEST)(
  465. IN WMIDPREQUESTCODE RequestCode,
  466. IN PVOID RequestContext,
  467. IN OUT ULONG *BufferSize,
  468. IN OUT PVOID Buffer
  469. );
  470. struct _EVENT_TRACE_LOGFILEW {
  471. LPWSTR LogFileName; // Logfile Name
  472. LPWSTR LoggerName; // LoggerName
  473. LONGLONG CurrentTime; // timestamp of last event
  474. ULONG BuffersRead; // buffers read to date
  475. ULONG LogFileMode; // Mode of the logfile
  476. EVENT_TRACE CurrentEvent; // Current Event from this stream.
  477. TRACE_LOGFILE_HEADER LogfileHeader; // logfile header structure
  478. PEVENT_TRACE_BUFFER_CALLBACKW // callback before each buffer
  479. BufferCallback; // is read
  480. //
  481. // following variables are filled for BufferCallback.
  482. //
  483. ULONG BufferSize;
  484. ULONG Filled;
  485. ULONG EventsLost;
  486. //
  487. // following needs to be propaged to each buffer
  488. //
  489. PEVENT_CALLBACK EventCallback; // callback for every event
  490. ULONG IsKernelTrace; // TRUE for kernel logfile
  491. PVOID Context; // reserved for internal use
  492. };
  493. struct _EVENT_TRACE_LOGFILEA {
  494. LPSTR LogFileName; // Logfile Name
  495. LPSTR LoggerName; // LoggerName
  496. LONGLONG CurrentTime; // timestamp of last event
  497. ULONG BuffersRead; // buffers read to date
  498. ULONG LogFileMode; // LogFile Mode.
  499. EVENT_TRACE CurrentEvent; // Current Event from this stream
  500. TRACE_LOGFILE_HEADER LogfileHeader; // logfile header structure
  501. PEVENT_TRACE_BUFFER_CALLBACKA // callback before each buffer
  502. BufferCallback; // is read
  503. //
  504. // following variables are filled for BufferCallback.
  505. //
  506. ULONG BufferSize;
  507. ULONG Filled;
  508. ULONG EventsLost;
  509. //
  510. // following needs to be propaged to each buffer
  511. //
  512. PEVENT_CALLBACK EventCallback; // callback for every event
  513. ULONG IsKernelTrace; // TRUE for kernel logfile
  514. PVOID Context; // reserved for internal use
  515. };
  516. //
  517. // Define generic structures
  518. //
  519. #if defined(_UNICODE) || defined(UNICODE)
  520. #define PEVENT_TRACE_BUFFER_CALLBACK PEVENT_TRACE_BUFFER_CALLBACKW
  521. #define EVENT_TRACE_LOGFILE EVENT_TRACE_LOGFILEW
  522. #define PEVENT_TRACE_LOGFILE PEVENT_TRACE_LOGFILEW
  523. #define KERNEL_LOGGER_NAME KERNEL_LOGGER_NAMEW
  524. #define GLOBAL_LOGGER_NAME GLOBAL_LOGGER_NAMEW
  525. #define EVENT_LOGGER_NAME EVENT_LOGGER_NAMEW
  526. #else
  527. #define PEVENT_TRACE_BUFFER_CALLBACK PEVENT_TRACE_BUFFER_CALLBACKA
  528. #define EVENT_TRACE_LOGFILE EVENT_TRACE_LOGFILEA
  529. #define PEVENT_TRACE_LOGFILE PEVENT_TRACE_LOGFILEA
  530. #define KERNEL_LOGGER_NAME KERNEL_LOGGER_NAMEA
  531. #define GLOBAL_LOGGER_NAME GLOBAL_LOGGER_NAMEA
  532. #define EVENT_LOGGER_NAME EVENT_LOGGER_NAMEA
  533. #endif
  534. #if _MSC_VER >= 1200
  535. #pragma warning(pop)
  536. #endif
  537. #ifdef __cplusplus
  538. extern "C" {
  539. #endif
  540. //
  541. // Logger control APIs
  542. //
  543. //
  544. // Use the routine below to start an event trace session
  545. //
  546. // ULONG
  547. // StartTrace(
  548. // OUT PTRACEHANDLE TraceHandle,
  549. // IN LPTSTR InstanceName,
  550. // IN OUT PEVENT_TRACE_PROPERTIES Properties
  551. // );
  552. EXTERN_C
  553. ULONG
  554. WMIAPI
  555. StartTraceW(
  556. OUT PTRACEHANDLE TraceHandle,
  557. IN LPCWSTR InstanceName,
  558. IN OUT PEVENT_TRACE_PROPERTIES Properties
  559. );
  560. EXTERN_C
  561. ULONG
  562. WMIAPI
  563. StartTraceA(
  564. OUT PTRACEHANDLE TraceHandle,
  565. IN LPCSTR InstanceName,
  566. IN OUT PEVENT_TRACE_PROPERTIES Properties
  567. );
  568. //
  569. // Use the routine below to stop an event trace session
  570. //
  571. //
  572. // ULONG
  573. // StopTrace(
  574. // IN TRACEHANDLE TraceHandle,
  575. // IN LPTSTR InstanceName,
  576. // IN OUT PEVENT_TRACE_PROPERTIES Properties
  577. // );
  578. EXTERN_C
  579. ULONG
  580. WMIAPI
  581. StopTraceW(
  582. IN TRACEHANDLE TraceHandle,
  583. IN LPCWSTR InstanceName,
  584. IN OUT PEVENT_TRACE_PROPERTIES Properties
  585. );
  586. EXTERN_C
  587. ULONG
  588. WMIAPI
  589. StopTraceA(
  590. IN TRACEHANDLE TraceHandle,
  591. IN LPCSTR InstanceName,
  592. IN OUT PEVENT_TRACE_PROPERTIES Properties
  593. );
  594. //
  595. // Use the routine below to query the properties of an event trace session
  596. //
  597. // ULONG
  598. // QueryTrace(
  599. // IN TRACEHANDLE TraceHandle,
  600. // IN LPTSTR InstanceName,
  601. // IN OUT PEVENT_TRACE_PROPERTIES Properties
  602. // );
  603. EXTERN_C
  604. ULONG
  605. WMIAPI
  606. QueryTraceW(
  607. IN TRACEHANDLE TraceHandle,
  608. IN LPCWSTR InstanceName,
  609. IN OUT PEVENT_TRACE_PROPERTIES Properties
  610. );
  611. EXTERN_C
  612. ULONG
  613. WMIAPI
  614. QueryTraceA(
  615. IN TRACEHANDLE TraceHandle,
  616. IN LPCSTR InstanceName,
  617. IN OUT PEVENT_TRACE_PROPERTIES Properties
  618. );
  619. //
  620. // Use the routine below to update certain properties of an event trace session
  621. //
  622. // ULONG
  623. // UpdateTrace(
  624. // IN (PTRACEHANDLE TraceHandle,
  625. // IN LPTSTR InstanceName,
  626. // IN OUT PEVENT_TRACE_PROPERTIES Properties
  627. // );
  628. EXTERN_C
  629. ULONG
  630. WMIAPI
  631. UpdateTraceW(
  632. IN TRACEHANDLE TraceHandle,
  633. IN LPCWSTR InstanceName,
  634. IN OUT PEVENT_TRACE_PROPERTIES Properties
  635. );
  636. EXTERN_C
  637. ULONG
  638. WMIAPI
  639. UpdateTraceA(
  640. IN TRACEHANDLE TraceHandle,
  641. IN LPCSTR InstanceName,
  642. IN OUT PEVENT_TRACE_PROPERTIES Properties
  643. );
  644. //
  645. // Use the routine below to request that all active buffers an event trace
  646. // session be "flushed", or written out.
  647. //
  648. #if (WINVER >= 0x0501)
  649. // ULONG
  650. // FlushTrace(
  651. // IN TRACEHANDLE TraceHandle,
  652. // IN LPTSTR InstanceName,
  653. // IN OUT PEVENT_TRACE_PROPERTIES Properties
  654. // );
  655. EXTERN_C
  656. ULONG
  657. WMIAPI
  658. FlushTraceW(
  659. IN TRACEHANDLE TraceHandle,
  660. IN LPCWSTR InstanceName,
  661. IN OUT PEVENT_TRACE_PROPERTIES Properties
  662. );
  663. EXTERN_C
  664. ULONG
  665. WMIAPI
  666. FlushTraceA(
  667. IN TRACEHANDLE TraceHandle,
  668. IN LPCSTR InstanceName,
  669. IN OUT PEVENT_TRACE_PROPERTIES Properties
  670. );
  671. #endif
  672. //
  673. // Generic trace control routine
  674. //
  675. EXTERN_C
  676. ULONG
  677. WMIAPI
  678. ControlTraceW(
  679. IN TRACEHANDLE TraceHandle,
  680. IN LPCWSTR InstanceName,
  681. IN OUT PEVENT_TRACE_PROPERTIES Properties,
  682. IN ULONG ControlCode
  683. );
  684. EXTERN_C
  685. ULONG
  686. WMIAPI
  687. ControlTraceA(
  688. IN TRACEHANDLE TraceHandle,
  689. IN LPCSTR InstanceName,
  690. IN OUT PEVENT_TRACE_PROPERTIES Properties,
  691. IN ULONG ControlCode
  692. );
  693. //
  694. // ULONG
  695. // QueryAllTraces(
  696. // OUT PEVENT_TRACE_PROPERTIES *PropertyArray,
  697. // IN ULONG PropertyArrayCount,
  698. // OUT PULONG LoggerCount
  699. // );
  700. //
  701. EXTERN_C
  702. ULONG
  703. WMIAPI
  704. QueryAllTracesW(
  705. OUT PEVENT_TRACE_PROPERTIES *PropertyArray,
  706. IN ULONG PropertyArrayCount,
  707. OUT PULONG LoggerCount
  708. );
  709. EXTERN_C
  710. ULONG
  711. WMIAPI
  712. QueryAllTracesA(
  713. OUT PEVENT_TRACE_PROPERTIES *PropertyArray,
  714. IN ULONG PropertyArrayCount,
  715. OUT PULONG LoggerCount
  716. );
  717. //
  718. // Data Provider APIs
  719. //
  720. EXTERN_C
  721. ULONG
  722. WMIAPI
  723. CreateTraceInstanceId(
  724. IN HANDLE RegHandle,
  725. IN OUT PEVENT_INSTANCE_INFO pInstInfo
  726. );
  727. EXTERN_C
  728. ULONG
  729. WMIAPI
  730. EnableTrace(
  731. IN ULONG Enable,
  732. IN ULONG EnableFlag,
  733. IN ULONG EnableLevel,
  734. IN LPCGUID ControlGuid,
  735. IN TRACEHANDLE TraceHandle
  736. );
  737. //
  738. // Use the routine below to generate and record an event trace
  739. //
  740. EXTERN_C
  741. ULONG
  742. WMIAPI
  743. TraceEvent(
  744. IN TRACEHANDLE TraceHandle,
  745. IN PEVENT_TRACE_HEADER EventTrace
  746. );
  747. EXTERN_C
  748. ULONG
  749. WMIAPI
  750. TraceEventInstance(
  751. IN TRACEHANDLE TraceHandle,
  752. IN PEVENT_INSTANCE_HEADER EventTrace,
  753. IN PEVENT_INSTANCE_INFO pInstInfo,
  754. IN PEVENT_INSTANCE_INFO pParentInstInfo
  755. );
  756. //
  757. // Use the routine below to register a guid for tracing
  758. //
  759. //
  760. // ULONG
  761. // RegisterTraceGuids(
  762. // IN WMIDPREQUEST RequestAddress,
  763. // IN PVOID RequestContext,
  764. // IN LPCGUID ControlGuid,
  765. // IN ULONG GuidCount,
  766. // IN PTRACE_GUID_REGISTRATION TraceGuidReg,
  767. // IN LPCTSTR MofImagePath,
  768. // IN LPCTSTR MofResourceName,
  769. // OUT PTRACEHANDLE RegistrationHandle
  770. // );
  771. //
  772. EXTERN_C
  773. ULONG
  774. WMIAPI
  775. RegisterTraceGuidsW(
  776. IN WMIDPREQUEST RequestAddress,
  777. IN PVOID RequestContext,
  778. IN LPCGUID ControlGuid,
  779. IN ULONG GuidCount,
  780. IN PTRACE_GUID_REGISTRATION TraceGuidReg,
  781. IN LPCWSTR MofImagePath,
  782. IN LPCWSTR MofResourceName,
  783. OUT PTRACEHANDLE RegistrationHandle
  784. );
  785. EXTERN_C
  786. ULONG
  787. WMIAPI
  788. RegisterTraceGuidsA(
  789. IN WMIDPREQUEST RequestAddress,
  790. IN PVOID RequestContext,
  791. IN LPCGUID ControlGuid,
  792. IN ULONG GuidCount,
  793. IN PTRACE_GUID_REGISTRATION TraceGuidReg,
  794. IN LPCSTR MofImagePath,
  795. IN LPCSTR MofResourceName,
  796. OUT PTRACEHANDLE RegistrationHandle
  797. );
  798. #if (WINVER >= 0x0501)
  799. EXTERN_C
  800. ULONG
  801. WMIAPI
  802. EnumerateTraceGuids(
  803. IN OUT PTRACE_GUID_PROPERTIES *GuidPropertiesArray,
  804. IN ULONG PropertyArrayCount,
  805. OUT PULONG GuidCount
  806. );
  807. #endif
  808. EXTERN_C
  809. ULONG
  810. WMIAPI
  811. UnregisterTraceGuids(
  812. IN TRACEHANDLE RegistrationHandle
  813. );
  814. EXTERN_C
  815. TRACEHANDLE
  816. WMIAPI
  817. GetTraceLoggerHandle(
  818. IN PVOID Buffer
  819. );
  820. EXTERN_C
  821. UCHAR
  822. WMIAPI
  823. GetTraceEnableLevel(
  824. IN TRACEHANDLE TraceHandle
  825. );
  826. EXTERN_C
  827. ULONG
  828. WMIAPI
  829. GetTraceEnableFlags(
  830. IN TRACEHANDLE TraceHandle
  831. );
  832. //
  833. // Data Consumer APIs and structures start here
  834. //
  835. //
  836. // TRACEHANDLE
  837. // OpenTrace(
  838. // IN OUT PEVENT_TRACE_LOGFILE Logfile
  839. // );
  840. //
  841. EXTERN_C
  842. TRACEHANDLE
  843. WMIAPI
  844. OpenTraceA(
  845. IN OUT PEVENT_TRACE_LOGFILEA Logfile
  846. );
  847. EXTERN_C
  848. TRACEHANDLE
  849. WMIAPI
  850. OpenTraceW(
  851. IN OUT PEVENT_TRACE_LOGFILEW Logfile
  852. );
  853. EXTERN_C
  854. ULONG
  855. WMIAPI
  856. ProcessTrace(
  857. IN PTRACEHANDLE HandleArray,
  858. IN ULONG HandleCount,
  859. IN LPFILETIME StartTime,
  860. IN LPFILETIME EndTime
  861. );
  862. EXTERN_C
  863. ULONG
  864. WMIAPI
  865. CloseTrace(
  866. IN TRACEHANDLE TraceHandle
  867. );
  868. EXTERN_C
  869. ULONG
  870. WMIAPI
  871. SetTraceCallback(
  872. IN LPCGUID pGuid,
  873. IN PEVENT_CALLBACK EventCallback
  874. );
  875. EXTERN_C
  876. ULONG
  877. WMIAPI
  878. RemoveTraceCallback (
  879. IN LPCGUID pGuid
  880. );
  881. //
  882. // The routines for tracing Messages follow
  883. //
  884. EXTERN_C
  885. ULONG
  886. __cdecl
  887. TraceMessage(
  888. IN TRACEHANDLE LoggerHandle,
  889. IN ULONG MessageFlags,
  890. IN LPGUID MessageGuid,
  891. IN USHORT MessageNumber,
  892. ...
  893. );
  894. EXTERN_C
  895. ULONG
  896. TraceMessageVa(
  897. IN TRACEHANDLE LoggerHandle,
  898. IN ULONG MessageFlags,
  899. IN LPGUID MessageGuid,
  900. IN USHORT MessageNumber,
  901. IN va_list MessageArgList
  902. );
  903. #ifdef __cplusplus
  904. } // extern "C"
  905. #endif
  906. //
  907. //
  908. // Define the encoding independent routines
  909. //
  910. #if defined(UNICODE) || defined(_UNICODE)
  911. #define RegisterTraceGuids RegisterTraceGuidsW
  912. #define StartTrace StartTraceW
  913. #define ControlTrace ControlTraceW
  914. #if defined(__TRACE_W2K_COMPATIBLE)
  915. #define StopTrace(a,b,c) ControlTraceW((a),(b),(c), \
  916. EVENT_TRACE_CONTROL_STOP)
  917. #define QueryTrace(a,b,c) ControlTraceW((a),(b),(c), \
  918. EVENT_TRACE_CONTROL_QUERY)
  919. #define UpdateTrace(a,b,c) ControlTraceW((a),(b),(c), \
  920. EVENT_TRACE_CONTROL_UPDATE)
  921. #else
  922. #define StopTrace StopTraceW
  923. #define QueryTrace QueryTraceW
  924. #define UpdateTrace UpdateTraceW
  925. #endif
  926. #if (WINVER >= 0x0501)
  927. #define FlushTrace FlushTraceW
  928. #endif
  929. #define QueryAllTraces QueryAllTracesW
  930. #define OpenTrace OpenTraceW
  931. #else
  932. #define RegisterTraceGuids RegisterTraceGuidsA
  933. #define StartTrace StartTraceA
  934. #define ControlTrace ControlTraceA
  935. #if defined(__TRACE_W2K_COMPATIBLE)
  936. #define StopTrace(a,b,c) ControlTraceA((a),(b),(c), \
  937. EVENT_TRACE_CONTROL_STOP)
  938. #define QueryTrace(a,b,c) ControlTraceA((a),(b),(c), \
  939. EVENT_TRACE_CONTROL_QUERY)
  940. #define UpdateTrace(a,b,c) ControlTraceA((a),(b),(c), \
  941. EVENT_TRACE_CONTROL_UPDATE)
  942. #else
  943. #define StopTrace StopTraceA
  944. #define QueryTrace QueryTraceA
  945. #define UpdateTrace UpdateTraceA
  946. #endif
  947. #if (WINVER >= 0x0501)
  948. #define FlushTrace FlushTraceA
  949. #endif
  950. #define QueryAllTraces QueryAllTracesA
  951. #define OpenTrace OpenTraceA
  952. #endif // UNICODE
  953. #endif /* _WMIKM_ && _NTDDK_ */
  954. #endif // WINNT
  955. #endif /* _EVNTRACE_ */