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