How to: Debugging custom code with the Developer Dashboard

best practiceAs already mentioned, the developer dashboard is an invaluable tool for the developer who wishes to display information and debug SharePoint code. It is quite extensive too, as it displays information about all the aspects that a developer would wish to track, including SQL calls that are also linked to the entire command line (the one that ran when the call was made). Unfortunately, by default, the Developer Dashboard will not display extensive information about custom code, albeit calls made from within the custom code will be tracked. However, extensive tracking of custom code can be implemented.

The developer can include monitored sections of their custom code to the Developer Dashboard, by implemented the SPMonitoredScope. As best practice, the developer should always wrap any code that executes on SharePoint, within an SPMonitoredScope class. The SPMonitoredScope class is part of the Microsoft.SharePoint.Utilities namespace, so the respective “using” will have to be in place.

The SPMonitoredScope comes with two constructors. The first one, accepts one string that is the name of the new scope. The second one, accepts a string, that is the name of the new scope, an integer that is the maximum time in miliseconds for the execution of the monitored scope and an array of objects that implement the ISPScopedPerformanceMonitor interface. The funny thing is that the SPMonitorScope is said to be unavailable in sandboxed solutions but, according to MSDN, the ISPScopedPerformanceMonitor interface is available in sandboxed solutions (okay, why?). When the maximum time, the integer provided within the constructor, is passed, the frame around the Developer Dashboard turns red and the trace level for the code is increased.

The following table, taken from the invaluable Professional SharePoint 2010 Development by Wrox, displays the classes that implement the ISPScopedPerformanceMonitor interface.

classes that implement the ISPScopedPerformanceMonitor interface.png

Powered by Zoundry Raven

Technorati : , ,
Del.icio.us : , ,
Zooomr : , ,
Flickr : , ,

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.