Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
6.1 KiB

  1. //---------------------------------------------------------------------------
  2. // File: EtwTrace
  3. //
  4. // A Managed wrapper for Event Tracing for Windows
  5. //
  6. // Author: Melur Raghuraman
  7. // Date: 01 Oct 2001
  8. //---------------------------------------------------------------------------
  9. using System;
  10. using System.Runtime.InteropServices;
  11. namespace Microsoft.Win32.Diagnostics
  12. {
  13. [System.CLSCompliant(false)]
  14. [StructLayout(LayoutKind.Explicit, Size=16)]
  15. internal struct MofField
  16. {
  17. [FieldOffset(0)]
  18. internal unsafe void * DataPointer;
  19. [FieldOffset(8)]
  20. internal uint DataLength;
  21. [FieldOffset(12)]
  22. internal uint DataType;
  23. }
  24. [System.CLSCompliant(false)]
  25. [StructLayout(LayoutKind.Explicit, Size=208)] // Full Size 192
  26. internal struct BaseEvent
  27. {
  28. [FieldOffset(0)]
  29. internal uint BufferSize;
  30. [FieldOffset(4)]
  31. internal uint ProviderId;
  32. [FieldOffset(8)]
  33. internal ulong HistoricalContext;
  34. [FieldOffset(16)]
  35. internal Int64 TimeStamp;
  36. [FieldOffset(24)]
  37. internal System.Guid Guid;
  38. [FieldOffset(40)]
  39. internal uint ClientContext;
  40. [FieldOffset(44)]
  41. internal uint Flags;
  42. //
  43. // We have allocated enough space for 10 MOF_FIELD structures
  44. // at the bottom. That is 1 argument descriptor, 1 FormatString and 8 arguments.
  45. //
  46. [FieldOffset(48)]
  47. internal MofField UserData;
  48. }
  49. [System.CLSCompliant(false)]
  50. [StructLayout(LayoutKind.Explicit, Size=8)]
  51. internal struct TraceGuidRegistration
  52. {
  53. [FieldOffset(0)]
  54. internal unsafe System.Guid *Guid;
  55. [FieldOffset(4)]
  56. internal unsafe void* RegHandle;
  57. }
  58. [System.CLSCompliant(false)]
  59. [System.Security.SuppressUnmanagedCodeSecurity]
  60. public sealed class EtwTrace
  61. {
  62. // Ensure class cannot be instantiated by making the constructor private
  63. private EtwTrace() {}
  64. // Enumerations
  65. //
  66. public sealed class RequestCodes
  67. {
  68. // Ensure class cannot be instantiated
  69. private RequestCodes() {}
  70. public const uint GetAllData = 0; // Never Used
  71. public const uint GetSingleInstance = 1; // Never Used
  72. public const uint SetSingleInstance = 2; // Never Used
  73. public const uint SetSingleItem = 3; // Never Used
  74. public const uint EnableEvents = 4; // Enable Tracing
  75. public const uint DisableEvents = 5; // Disable Tracing
  76. public const uint EnableCollection = 6; // Never Used
  77. public const uint DisableCollection = 7; // Never Used
  78. public const uint RegInfo = 8; // Registration Information
  79. public const uint ExecuteMethod = 9; // Never Used
  80. }
  81. //
  82. // Flags used by ETW Trace Message
  83. // Note that the order or value of these flags should NOT be changed as they are processed
  84. // in this order.
  85. //
  86. public sealed class TraceMessageCodes
  87. {
  88. // Ensure class cannot be instantiated
  89. private TraceMessageCodes() {}
  90. public const uint TRACE_MESSAGE_SEQUENCE = 1; // Message should include a sequence number
  91. public const uint TRACE_MESSAGE_GUID = 2; // Message includes a GUID
  92. public const uint TRACE_MESSAGE_COMPONENTID = 4; // Message has no GUID, Component ID instead
  93. public const uint TRACE_MESSAGE_TIMESTAMP = 8; // Message includes a timestamp
  94. public const uint TRACE_MESSAGE_PERFORMANCE_TIMESTAMP = 16; // Timestamp is the Performance Counter not the system clock
  95. public const uint TRACE_MESSAGE_SYSTEMINFO = 32; // Message includes system information TID,PID
  96. public const uint TRACE_MESSAGE_FLAG_MASK = 0xFFFF; // Only the lower 16 bits of flags are placed in the message
  97. // those above 16 bits are reserved for local processing
  98. public const uint TRACE_MESSAGE_MAXIMUM_SIZE = 8*1024; // the maximum size allowed for a single trace message
  99. // longer messages will return ERROR_BUFFER_OVERFLOW
  100. }
  101. // Structures
  102. [StructLayout(LayoutKind.Sequential)]
  103. public struct CSTRACE_GUID_REGISTRATION
  104. {
  105. public unsafe System.Guid *Guid;
  106. public uint RegHandle;
  107. }
  108. // Function Signatures
  109. public unsafe delegate uint EtwProc(uint requestCode, System.IntPtr requestContext, System.IntPtr bufferSize, byte* buffer);
  110. [DllImport("advapi32", ExactSpelling=true, EntryPoint="GetTraceEnableFlags", CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
  111. internal static extern int GetTraceEnableFlags(ulong traceHandle);
  112. [DllImport("advapi32", ExactSpelling=true, EntryPoint="GetTraceEnableLevel", CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
  113. internal static extern char GetTraceEnableLevel(ulong traceHandle);
  114. [DllImport("advapi32", ExactSpelling=true, EntryPoint="RegisterTraceGuidsW", CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
  115. internal static extern unsafe uint RegisterTraceGuids([In]EtwProc cbFunc, [In]void* context, [In] ref System.Guid controlGuid, [In] uint guidCount, ref TraceGuidRegistration guidReg, [In]string mofImagePath, [In] string mofResourceName, [Out] out ulong regHandle);
  116. [DllImport("advapi32", ExactSpelling=true, EntryPoint="UnregisterTraceGuids", CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
  117. internal static extern int UnregisterTraceGuids(ulong regHandle);
  118. [DllImport("advapi32", ExactSpelling=true, EntryPoint="TraceEvent", CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
  119. internal static extern unsafe uint TraceEvent(ulong traceHandle, char *header);
  120. }
  121. }