I have code that uses the Microsoft.Diagnostics.Tracing.TraceEvent
NuGet package, and I wrote the following code:
using (var session = new TraceEventSession("mine"))
{
session.StopOnDispose = true;
session.EnableProvider(ClrTraceEventParser.ProviderGuid, TraceEventLevel.Verbose,
(ulong)ulong.MaxValue,//,ClrTraceEventParser.Keywords.GCSampledObjectAllocationHigh,
new TraceEventProviderOptions
{
StacksEnabled = true,
});
using (TraceLogEventSource traceLogSource = TraceLog.CreateFromTraceEventSession(session))
{
traceLogSource.Clr.GCSampledObjectAllocation += data =>
{
Console.WriteLine(data);
};
traceLogSource.Process();
}
}
This gives me output that looks somewhat like this:
<Event
MSec="10355.9688"
PID="7056"
PName=""
TID="11468"
EventName="GC/SampledObjectAllocation"
Address="0x000000C780036870"
TypeID="0x00007FFF1EC60BD8"
ObjectCountForTypeSample="1"
TotalSizeForTypeSample="28"
ClrInstanceID="9" />
Which is clear enough, there is one object allocated, and its size is 28 bytes. However, I don't know how to map the TypeID into a type name.
It seems like this would do what I want:
traceLogSource.Clr.TypeBulkType += data =>
{
for (int i = 0; i < data.Count; i++)
{
var e = data.Values(i);
Console.WriteLine("{0} -> {1}", e.TypeID, e.TypeName);
}
};
But I don't know how to trigger its sending from the process that I'm checking (which can be a very long running one). The bulk type seems to be sent only at process start (observation only), and I can't find any docs on them.
Any ideas how to do that?