Search code examples
c#.net-2.0wmi

library/API recommendation for adding instrumentation in code


If I want to add some instrumentation in my code for getting metrics like how long a particular method took to execute, anyone has recommendation for either windows build-in or any 3rd party library?


Solution

  • I've seen this done with PostSharp AOP framework, hooked into Windows Performance Counters (System.Diagnostics.PerformanceCounter). One of their introductory pieces of sample code shows how to do this:

    http://www.sharpcrafters.com/solutions/performance

    This might be a good option if you want to deploy these measurements to production and measure performance in a live manner (to do diagnosis of a running system).

    If you just want to locate bottlenecks in your code, and don't need to do live diagnosis, I suggest you simply use a profiler, such as the one built into VS or Ants Profiler (as Chris already suggested). Then run a redacted copy of your production data against your code so your performance measurements match production.