Evntrace.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:31k
源码类别:

模拟服务器

开发平台:

C/C++

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