Evntrace.h 31 KB

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