eventdescriptor.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //go:build windows
  2. package etw
  3. // Channel represents the ETW logging channel that is used. It can be used by
  4. // event consumers to give an event special treatment.
  5. type Channel uint8
  6. const (
  7. // ChannelTraceLogging is the default channel for TraceLogging events. It is
  8. // not required to be used for TraceLogging, but will prevent decoding
  9. // issues for these events on older operating systems.
  10. ChannelTraceLogging Channel = 11
  11. )
  12. // Level represents the ETW logging level. There are several predefined levels
  13. // that are commonly used, but technically anything from 0-255 is allowed.
  14. // Lower levels indicate more important events, and 0 indicates an event that
  15. // will always be collected.
  16. type Level uint8
  17. // Predefined ETW log levels from winmeta.xml in the Windows SDK.
  18. const (
  19. LevelAlways Level = iota
  20. LevelCritical
  21. LevelError
  22. LevelWarning
  23. LevelInfo
  24. LevelVerbose
  25. )
  26. // Opcode represents the operation that the event indicates is being performed.
  27. type Opcode uint8
  28. // Predefined ETW opcodes from winmeta.xml in the Windows SDK.
  29. const (
  30. // OpcodeInfo indicates an informational event.
  31. OpcodeInfo Opcode = iota
  32. // OpcodeStart indicates the start of an operation.
  33. OpcodeStart
  34. // OpcodeStop indicates the end of an operation.
  35. OpcodeStop
  36. // OpcodeDCStart indicates the start of a provider capture state operation.
  37. OpcodeDCStart
  38. // OpcodeDCStop indicates the end of a provider capture state operation.
  39. OpcodeDCStop
  40. )
  41. // EventDescriptor represents various metadata for an ETW event.
  42. type eventDescriptor struct {
  43. id uint16
  44. version uint8
  45. channel Channel
  46. level Level
  47. opcode Opcode
  48. task uint16
  49. keyword uint64
  50. }
  51. // NewEventDescriptor returns an EventDescriptor initialized for use with
  52. // TraceLogging.
  53. func newEventDescriptor() *eventDescriptor {
  54. // Standard TraceLogging events default to the TraceLogging channel, and
  55. // verbose level.
  56. return &eventDescriptor{
  57. channel: ChannelTraceLogging,
  58. level: LevelVerbose,
  59. }
  60. }
  61. // Identity returns the identity of the event. If the identity is not 0, it
  62. // should uniquely identify the other event metadata (contained in
  63. // EventDescriptor, and field metadata). Only the lower 24 bits of this value
  64. // are relevant.
  65. //
  66. //nolint:unused // keep for future use
  67. func (ed *eventDescriptor) identity() uint32 {
  68. return (uint32(ed.version) << 16) | uint32(ed.id)
  69. }
  70. // SetIdentity sets the identity of the event. If the identity is not 0, it
  71. // should uniquely identify the other event metadata (contained in
  72. // EventDescriptor, and field metadata). Only the lower 24 bits of this value
  73. // are relevant.
  74. //
  75. //nolint:unused // keep for future use
  76. func (ed *eventDescriptor) setIdentity(identity uint32) {
  77. ed.id = uint16(identity)
  78. ed.version = uint8(identity >> 16)
  79. }