9

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?

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41

1 Answers1

0

If you look at the ClrTraceEventParser.Keywords in TraceEvent (you will find the GCHeapAndTypeNames bit). When you turn this on as well as the AllocationHigh bit, every time a new type is noticed for the first time it should send along a BulkType event.

  • If you'll look at the code, I'm actually sending _all_ flags (in this test case, obviously). My issues is that my code is trying to check a long running server, so all the types that we are talking about have already been loaded. Is there a way to induce it to send them again? Or some other way to get the mapping between TypeId and the actual name? – Ayende Rahien Aug 25 '15 at 21:11