-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracePeekEvent.cs
More file actions
70 lines (65 loc) · 3 KB
/
TracePeekEvent.cs
File metadata and controls
70 lines (65 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using Microsoft.Diagnostics.Tracing;
using System.Management.Automation;
namespace TracePeek
{
public class TracePeekEvent
{
private TracePeekEvent(TraceEvent traceEvent)
{
ProviderGuid = traceEvent.ProviderGuid;
ProviderName = traceEvent.ProviderName;
Levels = (ushort)traceEvent.Level;
Keywords = (ulong)traceEvent.Keywords;
ProcessId = traceEvent.ProcessID;
ProcessName = traceEvent.ProcessName;
Name = traceEvent.EventName;
Version = traceEvent.Version;
Message = traceEvent.FormattedMessage;
}
public readonly string ProviderName;
public readonly Guid ProviderGuid;
public readonly ushort Levels;
public readonly UInt64 Keywords;
public readonly string RelativeId;
public readonly string ProcessName;
public readonly Int32 ProcessId;
public readonly int Version;
public readonly string Message;
public readonly string Name;
public static TracePeekEvent CreateWithoutPayloadProperties(TraceEvent traceEvent) => new TracePeekEvent(traceEvent);
public static PSObject CreateWithNamedPayloadProperties(TraceEvent traceEvent)
{
var eventProjection = new PSObject(new TracePeekEvent(traceEvent));
for(var i=0; i < traceEvent.PayloadNames.Length; i++)
{
var psProperty = new PSNoteProperty(traceEvent.PayloadNames[i], traceEvent.PayloadValue(i));
eventProjection.Properties.Add(psProperty);
}
return eventProjection;
}
public static PSObject CreateWithNumberedPayloadProperties(TraceEvent traceEvent, int maxFieldCount = 10)
{
var eventProjection = new PSObject(new TracePeekEvent(traceEvent));
for(var i=0; i < maxFieldCount; i++)
{
var name = i < traceEvent.PayloadNames.Length ? traceEvent.PayloadNames[i] : String.Empty;
var value = i < traceEvent.PayloadNames.Length ? traceEvent.PayloadString(i) : String.Empty;
eventProjection.Properties.Add(new PSNoteProperty($"Field{i}Name", name));
eventProjection.Properties.Add(new PSNoteProperty($"Field{i}Value", value));
}
return eventProjection;
}
public static PSObject CreateWithNumberedNestedPayloadProperties(TraceEvent traceEvent, int maxFieldCount = 10)
{
var eventProjection = new PSObject(new TracePeekEvent(traceEvent));
for(var i=0; i < maxFieldCount; i++)
{
var name = i < traceEvent.PayloadNames.Length ? traceEvent.PayloadNames[i] : String.Empty;
var value = i < traceEvent.PayloadNames.Length ? traceEvent.PayloadString(i) : String.Empty;
eventProjection.Properties.Add(new PSNoteProperty($"Field{i}", $"{name} : {value}"));
}
return eventProjection;
}
}
}