Skip to content
JaCraig edited this page Dec 16, 2014 · 1 revision

Another system built in to the library is the profiler. By default a simple profiler is provided but other libraries can be substituted such as MiniProfiler. Using the profiler is rather simple:

using(Utilities.Profiler.Profiler ExampleObject=new Utilities.Profiler.Profiler("Descriptive name of the code section profiling"))
{
    //Code you want to profile
}

Nesting profilers will correctly place information within the parent profiler. So for instance:

using(Utilities.Profiler.Profiler ExampleObject=new Utilities.Profiler.Profiler("Parent"))
{
    using(Utilities.Profiler.Profiler ExampleObject=new Utilities.Profiler.Profiler("Child 1"))
    {
        //Code you want to profile
    }
    using(Utilities.Profiler.Profiler ExampleObject=new Utilities.Profiler.Profiler("Child 2"))
    {
        //Code you want to profile
    }
}

This will have Child 1 and Child 2 as children to Parent. At the same time Child 1 and Child 2 will be kept as siblings in the profiler hierarchy. Also if the profiler item is called multiple times, it will keep the data as a single object:

for(int x=0;x<10;++x)
{
    using(Utilities.Profiler.Profiler ExampleObject=new Utilities.Profiler.Profiler("My Profiler"))
    {
        //Code you want to profile
    }
}

The code above will average the ten runs of the "My Profiler" object and hold that information as a single object in the system. In order to get the profiler information so that you can read it, you simply call ToString() on the Manager class which is found at Utilities.Profiler.Manager.Manager. More complicated profilers can be plugged in to the system by implementing the IProfiler interface. Lastly there are a few extension methods in the Utilities.Profiler namespace for Func<> and Action<> objects called Time. These extension methods will automatically run the Func/Action in question using the variables supplied and return the result while capturing the profiler information.

Clone this wiki locally