Created
January 28, 2022 13:05
-
-
Save Alois-xx/92c1076055f2218b1b29a0856b07dd98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
processor.Use(ProcessRawEvents); | |
... | |
List<StackEvent> StackEvents = new List<StackEvent>(); | |
class StackEvent | |
{ | |
public TraceTimestamp TimeStamp; | |
public IReadOnlyList<Address> Stack; | |
} | |
bool myNeedsStack = false; | |
void ProcessRawEvents(EventContext eventContext) | |
{ | |
TraceEvent ev = eventContext.Event; | |
if (ev.ProviderId == Constants.DotNetRuntimeGuid) | |
{ | |
if (ev.Id == Constants.ExceptionEventId) | |
{ | |
myNeedsStack = true; | |
} | |
// potentially every exception event is followed by a stackwalk event | |
if (myNeedsStack && ev.Id == Constants.ClrStackWalkEventId) | |
{ | |
myNeedsStack = false; | |
StackEvent stackEv = new StackEvent() | |
{ | |
TimeStamp = ev.Timestamp, | |
}; | |
ReadOnlySpan<byte> frameData = ev.Data.Slice(8); | |
List<Address> addresses = new List<Address>(); | |
stackEv.Stack = addresses; | |
if (ev.Is32Bit) | |
{ | |
ReadOnlySpan<int> ints = MemoryMarshal.Cast<byte, int>(frameData); | |
foreach(var intAdr in ints) | |
{ | |
addresses.Add(new Address(intAdr)); | |
} | |
} | |
else | |
{ | |
ReadOnlySpan<long> longs = MemoryMarshal.Cast<byte, long>(frameData); | |
foreach(var longAdr in longs) | |
{ | |
addresses.Add(new Address(longAdr)); | |
} | |
} | |
StackEvents.Add(stackEv); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment