Search This Blog

Wednesday, March 31, 2010

Track time spent for your custom code

SharePoint 2010 has built in monitoring for tracking time taken for code operations.
We can use that in our custom code also: SPMonitoredScope
Since this uses IDisposable interface we will put in a using clause:

using (SPMonitoredScope monitorScope = new SPMonitoredScope("My Query Time Test"))
{
     myFunction();
}
....
void myFunction()
{
// Function logic here



}

How to use the above:
Once we have the code compiled and deployed - and the developer dashboard is enabled (please see another post in this blog on how to enable developer dashboard) this will show us the length of time spent on executing myFunction. Neat ... Is'nt it?

No comments: