Question

I'm experimenting with using XPerf to instrument an application for performance analysis. My goal is to log start/stop events within my C# application and analyse certain kernel metrics between these events.

I am creating a TraceListener and TraceSource within my application and logging events to the source. Then I use logman to start two sessions: one to capture events from my provider, and another to capture kernel events (xperf -on DiagEasy). At the end of my session, I then use XPerf to merge these files together and view/overlay graphs. All of this works well.

My application's events show up in the 'Generic Events' chart, however the events have no identifying information (no name, no event data), so it's difficult to tell which event is which. I know my event data is captured because it appears in 'dumpfile.xml' when I run tracerpt on the trace output. Is there any way to attach event names or the event data to 'Generic Events' within XPerf? Is my approach to using XPerf wrong?

Here is some sample code demonstrating how I'm using ETW:

static Guid providerId = new Guid("{4A9FD4F3-032B-4733-8455-03BC71ECEFB0}");
static void Main(string[] args)
{
    EventProviderTraceListener listener =
        new EventProviderTraceListener(providerId.ToString());
    TraceSource source = new TraceSource("ProductRepository", SourceLevels.All);
    source.Listeners.Add(listener);

    int id = 12;
    source.TraceData(TraceEventType.Warning, 12, "Some sample data");
    source.TraceEvent(TraceEventType.Start, 1, "TraceEvent.Start({0})", id);
    source.TraceEvent(TraceEventType.Stop, 1, "TraceEvent.Stop({0})", id);
    source.TraceInformation("TraceInformation");
}
Was it helpful?

Solution

Use the new System.Diagnostics.Tracing.EventSource class from .net 4.5. Vance created a demo how to use it:

Introduction Tutorial: Logging ETW events in C#: System.Diagnostics.Tracing.EventSource http://blogs.msdn.com/b/vancem/archive/2012/07/09/logging-your-own-etw-events-in-c-system-diagnostics-tracing-eventsource.aspx

OTHER TIPS

As user31273 mentions the key for XPerf to understand the payload of your event is to register the manifest of your provider. I didn't see the video linked by magicandre1981 but I bet that Vance mentions how to register your C# provider. Remember of specifying the proper opcodes (start/stop) to get what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top