BT

Better Tracing And Instrumentation For .NET Apps

by Roopesh Shenoy on Jul 16, 2012 |

EventSource and EventListener, introduced in .NET 4.5, provide a simple mechanism for applications to trace their events in Event Tracing for Windows (ETW). Combined with a analysis tool such as PerfView, this allows for better tracing of .NET apps.

.NET 4.5 introduces the EventSource class which provides a base class for developers to inherit and write their own Event Sources. Developers can then add a new method for every different type of event they want to log - these methods can be called from the application at the appropriate locations. Internally, these methods will call the base method WriteEvent() which in-turn sends the events to EventListeners that have subscribed, including the built-in listener that sends its logging messages to the ETW. Vance Morrison describes this in detail. 

As mentioned in a reference guide “Strongly Typed Events (EasyETW)” posted by Vance -

ETW is a high performance eventing system for windows which is used extensively in both the windows kernel as well as many windows subsystems. These built-in ETW sources provide wonderful ‘low level’ value (indicating where CPU, Disk, and network activities occur), and EventSource builds on this by allowing programmers to mark ‘high level’ semantic actions (like a user command, or a high level event), and thus assign resource consumption to high level tasks.

You can also implement custom EventListeners which can do things other than sending info to the ETW – for example, if for silverlight apps, you want to send the trace data over the network to the host machine.

PerfView is a performance analysis tool from Microsoft. Deployed as a single exe, it supports both CPU and Memory investigations of any application, but it also has some useful features especially for profiling managed code. Learn more about how to use this tool through these videos posted by Vance. 

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT