Skip to content

Commit

Permalink
Change members to properties for XAML binding. Fix a few parser bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lilhoser committed Jul 2, 2024
1 parent e698bb4 commit b382de2
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 97 deletions.
30 changes: 16 additions & 14 deletions EnabledProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ namespace etwlib
{
public class EnabledProvider : IEquatable<EnabledProvider>, IComparable<EnabledProvider>, IDisposable
{
public Guid Id;
public EventTraceLevel Level;
public ulong AllKeywords;
public ulong AnyKeywords;
private List<EVENT_FILTER_DESCRIPTOR> m_FilterDescriptors;
private nint m_AggregatedPayloadFilters;
private bool m_Disposed;
private nint m_ParametersBuffer;
private nint m_FiltersBuffer;

public EnabledProvider(Guid Id, EventTraceLevel Level, ulong AllKeywords, ulong AnyKeywords)
public Guid Id { get; set; }
public string? Name { get; set; }
public byte Level { get; set; }
public ulong AllKeywords { get; set; }
public ulong AnyKeywords { get; set; }
private List<EVENT_FILTER_DESCRIPTOR> m_FilterDescriptors { get; set; }
private nint m_AggregatedPayloadFilters { get; set; }
private bool m_Disposed { get; set; }
private nint m_ParametersBuffer { get; set; }
private nint m_FiltersBuffer { get; set; }

public EnabledProvider(Guid Id, string Name, byte Level, ulong AllKeywords, ulong AnyKeywords)
{
this.Id = Id;
this.Name = Name;
this.Level = Level;
this.AllKeywords = AllKeywords;
this.AnyKeywords = AnyKeywords;
Expand Down Expand Up @@ -162,7 +164,7 @@ public override string ToString()
public uint Disable(long SessionHandle)
{
return EnableTraceEx2(SessionHandle,
ref Id,
Id,
EventControlCode.DisableProvider,
Level,
0, 0, 0,
Expand All @@ -174,7 +176,7 @@ public uint Enable(long SessionHandle)
GenerateTraceParameters();
return EnableTraceEx2(
SessionHandle,
ref Id,
Id,
EventControlCode.EnableProvider,
Level,
AnyKeywords,
Expand Down Expand Up @@ -417,7 +419,7 @@ public void SetStackwalkLevelKw(EventTraceLevel Level, ulong MatchAnyKeyword, ul
}

var filter = new EVENT_FILTER_LEVEL_KW();
filter.Level = Level;
filter.Level = (byte)Level;
filter.MatchAllKeyword = MatchAllKeyword;
filter.MatchAnyKeyword = MatchAnyKeyword;
filter.FilterIn = FilterIn;
Expand Down
12 changes: 6 additions & 6 deletions NativeDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public struct EVENT_FILTER_LEVEL_KW
{
public ulong MatchAnyKeyword;
public ulong MatchAllKeyword;
public EventTraceLevel Level;
public byte Level;
[MarshalAs(UnmanagedType.U1)]
public bool FilterIn;
}
Expand Down Expand Up @@ -385,7 +385,7 @@ public struct TRACE_PROVIDER_INSTANCE_INFO
public struct TRACE_ENABLE_INFO
{
public uint IsEnabled;
public EventTraceLevel Level;
public byte Level;
public byte Reserved1;
public ushort LoggerId;
public EnableTraceProperties EnableProperty;
Expand Down Expand Up @@ -432,9 +432,9 @@ public static extern uint ProcessTrace(
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint EnableTraceEx2(
[In] long SessionHandle,
[In] ref Guid ProviderId,
[In] Guid ProviderId,
[In] EventControlCode ControlCode,
[In] EventTraceLevel Level,
[In] byte Level,
[In] ulong MatchAnyKeyword,
[In] ulong MatchAllKeyword,
[In] uint Timeout,
Expand Down Expand Up @@ -649,7 +649,7 @@ public struct EVENT_DESCRIPTOR
public ushort Id;
public byte Version;
public byte Channel;
public NativeTraceControl.EventTraceLevel Level;
public byte Level;
public byte Opcode;
public ushort Task;
public ulong Keyword;
Expand All @@ -671,7 +671,7 @@ public struct EVENT_TRACE_HEADER
public ushort Size;
public ushort FieldTypeFlags;
public byte Type;
public NativeTraceControl.EventTraceLevel Level;
public byte Level;
public ushort Version;
public uint ThreadId;
public uint ProcessId;
Expand Down
16 changes: 8 additions & 8 deletions ParsedEtwManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ namespace etwlib
{
public class ParsedEtwManifest
{
public ParsedEtwProvider Provider;
public List<ParsedEtwManifestEvent> Events;
public List<ParsedEtwManifestField> Channels;
public List<ParsedEtwManifestField> Keywords;
public Dictionary<ParsedEtwManifestField, List<ParsedEtwManifestField>> Tasks;
public List<ParsedEtwManifestField> GlobalOpcodes;
public Dictionary<string, List<ParsedEtwTemplateItem>> Templates;
public List<string> StringTable;
public ParsedEtwProvider Provider { get; set; }
public List<ParsedEtwManifestEvent> Events { get; set; }
public List<ParsedEtwManifestField> Channels { get; set; }
public List<ParsedEtwManifestField> Keywords { get; set; }
public Dictionary<ParsedEtwManifestField, List<ParsedEtwManifestField>> Tasks { get; set; }
public List<ParsedEtwManifestField> GlobalOpcodes { get; set; }
public Dictionary<string, List<ParsedEtwTemplateItem>> Templates { get; set; }
public List<string> StringTable { get; set; }

public ParsedEtwManifest()
{
Expand Down
18 changes: 10 additions & 8 deletions ParsedEtwManifestEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ namespace etwlib
{
public class ParsedEtwManifestEvent : IEquatable<ParsedEtwManifestEvent>, IComparable<ParsedEtwManifestEvent>
{
public string Id;
public string Version;
public string? Opcode;
public string? Channel;
public string Level;
public string? Keywords;
public string Task;
public string? Template;
public string Id { get; set; }
public string Version { get; set; }
public string? Opcode { get; set; }
public string? Channel { get; set; }
public string Level { get; set; }
public string? Keywords { get; set; }
public string Task { get; set; }
public string? Template { get; set; }

private ParsedEtwManifestEvent() { } // For XML serialization

Check warning on line 33 in ParsedEtwManifestEvent.cs

View workflow job for this annotation

GitHub Actions / etwlib_Unit_Tests

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 33 in ParsedEtwManifestEvent.cs

View workflow job for this annotation

GitHub Actions / etwlib_Unit_Tests

Non-nullable property 'Version' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 33 in ParsedEtwManifestEvent.cs

View workflow job for this annotation

GitHub Actions / etwlib_Unit_Tests

Non-nullable property 'Level' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 33 in ParsedEtwManifestEvent.cs

View workflow job for this annotation

GitHub Actions / etwlib_Unit_Tests

Non-nullable property 'Task' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public ParsedEtwManifestEvent(
string id,
Expand Down
8 changes: 5 additions & 3 deletions ParsedEtwManifestField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ namespace etwlib
{
public class ParsedEtwManifestField : IEquatable<ParsedEtwManifestField>, IComparable<ParsedEtwManifestField>
{
public string Name;
public string Description;
public ulong Value;
public string Name { get; set; }
public string Description { get; set; }
public ulong Value { get; set; }

private ParsedEtwManifestField() { } // For XML serialization

Check warning on line 28 in ParsedEtwManifestField.cs

View workflow job for this annotation

GitHub Actions / etwlib_Unit_Tests

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 28 in ParsedEtwManifestField.cs

View workflow job for this annotation

GitHub Actions / etwlib_Unit_Tests

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public ParsedEtwManifestField(string name, string description, ulong value)
{
Expand Down
11 changes: 7 additions & 4 deletions ParsedEtwProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ namespace etwlib
{
public class ParsedEtwProvider : IEquatable<ParsedEtwProvider>, IComparable<ParsedEtwProvider>
{
public Guid Id;
public string? Name;
public string? Source;
public Guid Id { get; set; }
public string? Name { get; set; }
public string? Source { get; set; }
public bool HasManifest { get; set; }

public ParsedEtwProvider() { } // For XML serialization

public override bool Equals(object? Other)
{
Expand Down Expand Up @@ -79,7 +82,7 @@ public int CompareTo(ParsedEtwProvider? Other)
public override string ToString()
{
var name = string.IsNullOrEmpty(Name) ? Id.ToString() : Name;
return $"{name} : ({Id}/{Source})";
return $"{name} : ({Id}/{Source}/Manifest={(HasManifest? "yes" : "no")})";
}
}
}
27 changes: 17 additions & 10 deletions ParsedEtwSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ namespace etwlib

public class SessionEnabledProvider
{
public Guid ProviderId;
public uint ProcessId;
public TRACE_PROVIDER_INSTANCE_FLAGS InstanceFlags;
public EventTraceLevel Level;
public EnableTraceProperties EnableProperty;
public ulong MatchAnyKeyword;
public ulong MatchAllKeyword;
public Guid ProviderId { get; set; }
public uint ProcessId { get; set; }
public TRACE_PROVIDER_INSTANCE_FLAGS InstanceFlags { get; set; }
public byte Level { get; set; }
public EnableTraceProperties EnableProperty { get; set; }
public ulong MatchAnyKeyword { get; set; }
public ulong MatchAllKeyword { get; set; }

private SessionEnabledProvider() { } // For XML serialization
public SessionEnabledProvider(
Guid providerId,
uint processId,
TRACE_PROVIDER_INSTANCE_FLAGS instanceFlags,
EventTraceLevel level,
byte level,
EnableTraceProperties enableProperty,
ulong matchAnyKeyword,
ulong matchAllKeyword)
Expand Down Expand Up @@ -65,8 +66,14 @@ public override string ToString()

public class ParsedEtwSession : IEquatable<ParsedEtwSession>, IComparable<ParsedEtwSession>
{
public ushort LoggerId;
public List<SessionEnabledProvider> EnabledProviders;
public ushort LoggerId { get; set; }
public List<SessionEnabledProvider> EnabledProviders { get; set; }

private ParsedEtwSession() // For xml serialization
{
LoggerId = 0;
EnabledProviders = new List<SessionEnabledProvider>();
}

public ParsedEtwSession(ushort Id)
{
Expand Down
6 changes: 4 additions & 2 deletions ParsedEtwString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ namespace etwlib
{
public class ParsedEtwString : IEquatable<ParsedEtwString>, IComparable<ParsedEtwString>
{
public string Name;
public ulong Value;
public string Name { get; set; }
public ulong Value { get; set; }

private ParsedEtwString() { } // For XML serialization

public ParsedEtwString(string name, ulong value)
{
Expand Down
22 changes: 12 additions & 10 deletions ParsedEtwTemplateItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ public Backreference(int Index, bool IsCounted)
FieldIndex = Index;
IsCountedField = IsCounted;
}
public string? FieldName; // must be resolved
public int FieldIndex; // match to ParsedEtwTemplateItem.Index
public bool IsCountedField; // if false, size field
public string? FieldName { get; set; } // must be resolved
public int FieldIndex { get; set; } // match to ParsedEtwTemplateItem.Index
public bool IsCountedField { get; set; } // if false, size field
}

public string Name;
public TdhInputType InType;
public TdhOutputType OutType;
public int Length;
public string Value;
public Backreference? FieldBackreference;
public int Index; // the index when it was parsed
public string Name { get; set; }
public TdhInputType InType { get; set; }
public TdhOutputType OutType { get; set; }
public int Length { get; set; }
public string Value { get; set; }
public Backreference? FieldBackreference { get; set; }
public int Index { get; set; } // the index when it was parsed

private ParsedEtwTemplateItem() { } // For XML serialization

public ParsedEtwTemplateItem(
string name,
Expand Down
1 change: 1 addition & 0 deletions ProviderParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static class ProviderParser
//
provider.Source = providerInfo.SchemaSource == 0 ? "xml" : "MOF";
provider.Name = "(unnamed)";
provider.HasManifest = IsManifestKnown(provider.Id);

if (providerInfo.ProviderNameOffset != 0)
{
Expand Down
13 changes: 12 additions & 1 deletion SessionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public static class SessionParser
pointer, typeof(TRACE_PROVIDER_INSTANCE_INFO))!;
if (instance.EnableCount > 0)
{
var sessionPointer = pointer;
var sessionPointer = nint.Add(pointer, Marshal.SizeOf(
typeof(TRACE_PROVIDER_INSTANCE_INFO)));
for (int j = 0; j < instance.EnableCount; j++)
{
var sessionInfo = (TRACE_ENABLE_INFO)Marshal.PtrToStructure(
Expand All @@ -226,6 +227,16 @@ public static class SessionParser
Marshal.SizeOf(typeof(TRACE_ENABLE_INFO)));
}
}
if (instance.NextOffset == 0)
{
//
// The docs aren't clear. They state that if this value is 0,
// there are no more instances, but logically that should not
// ever be the case, as we're guided by the parent struct's
// InstanceCount which should always be accurate..
//
break;
}
pointer = nint.Add(pointer, (int)instance.NextOffset);
}
return sessions;
Expand Down
11 changes: 9 additions & 2 deletions TraceSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ public virtual void Dispose()
GC.SuppressFinalize(this);
}

public EnabledProvider AddProvider(Guid Id, EventTraceLevel traceLevel, ulong matchAnyKeyword, ulong matchAllKeyword)
public EnabledProvider AddProvider(Guid Id, string Name, byte traceLevel, ulong matchAnyKeyword, ulong matchAllKeyword)
{
var provider = new EnabledProvider(Id, traceLevel, matchAllKeyword, matchAnyKeyword);
var provider = new EnabledProvider(Id, Name, traceLevel, matchAllKeyword, matchAnyKeyword);
m_EnabledProviders.Add(provider);
return provider;
}

public EnabledProvider AddProvider(Guid Id, string Name, EventTraceLevel traceLevel, ulong matchAnyKeyword, ulong matchAllKeyword)
{
var provider = new EnabledProvider(Id, Name, (byte)traceLevel, matchAllKeyword, matchAnyKeyword);
m_EnabledProviders.Add(provider);
return provider;
}
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/FilterByEventIdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Basic(bool Enable, bool Stackwalk)
try
{
var provider = trace.AddProvider(
s_RpcEtwGuid, EventTraceLevel.Information, 0xFFFFFFFFFFFFFFFF, 0);
s_RpcEtwGuid, "RPC", EventTraceLevel.Information, 0xFFFFFFFFFFFFFFFF, 0);

//
// We'll use RpcClientCallStart_V1 and RpcClientCallStop7_V1
Expand Down Expand Up @@ -182,9 +182,9 @@ public void Basic(bool Enable, bool Stackwalk)
return 1;
}));
}
catch (AssertFailedException ex)
catch (AssertFailedException)
{
throw ex;
throw;
}
catch (Exception ex)
{
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/FilterByExeNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Basic(string ExeName)
try
{
var provider = trace.AddProvider(
s_RpcEtwGuid, EventTraceLevel.Information, 0xFFFFFFFFFFFFFFFF, 0);
s_RpcEtwGuid, "RPC", EventTraceLevel.Information, 0xFFFFFFFFFFFFFFFF, 0);
provider.SetFilteredExeName(ExeName);
trace.Start();

Expand Down Expand Up @@ -139,9 +139,9 @@ public void Basic(string ExeName)
return 1;
}));
}
catch (AssertFailedException ex)
catch (AssertFailedException)
{
throw ex;
throw;
}
catch (Exception ex)
{
Expand Down
Loading

0 comments on commit b382de2

Please sign in to comment.