Profiling

Profiling is a small library for (manually) instrumented profiling (measurement of execution time & hitcount). The profiling class is implemented as an IDisposable making it easy to measure execution time. The class maintains an internal static collection of named ProfilingData objects that contain the actual execution measurements and hit counts.
  • Example:
using (Profiling pf as new Profiling("block1") { 
  Mark()
  ...
  Add() //Time Between Mark & Add is Added to the Total and Hits is Incremented by one.
}
Measures the execution time of the using a (manually) named profling object called 'block1'.
  • Example:
  Profiling.Hit("block1").
Manually increments the hitcounter of the ProfileData object called "block1" by 1.
  • Example:
using (new Profiling("aname") { 
  ...
}
Usage without an accessible instance of the Profiling Class. Generates an manually named ProfileData Object that generates output to the Debug Window when Disposed. Add, Hit and Mark are automatically called at creation and disposal.
  • Example:
using (new Profiling(this) { 
  ...
}
Generated an automatically named Profiling Object that generates output to the Debug Window when Disposed. The name is based on the callers class and methodname. Add, Hit and Mark are automatically called at creation and disposal.
  • Example:
using (Profiling p = new Profiling())
{
  foreach (String name in p)
  {
    Console.WriteLine(p[name]);
    //or
    //Console.WriteLine(Profiling.ToString(name));
  }
}
Dumps all ProfileData Objects to the Console Window.

Note: You can also add for example 'Profiling("block1")' to the watches in VS2k8 and the timing will be displayed as the watch value.

Last edited Feb 8, 2010 at 3:24 PM by wvd_vegt, version 4

Comments

No comments yet.