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.

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