SPMonitoredScope – Developer Dashboard

As SharePoint developers we aren’t only responsible for creating the functionality business requires, but we are also responsible for the overall quality of the solution we build.

This means an ergonomic fluent user interface, code that is suitable for changes and in my opinion one of the most important aspects, a good performance.
Most of these topics are described in white papers, best practices and millions of books and blog posts… but wouldn’t it be a pleasure if it was already in the platform?

Yes, indeed! That is why the SharePoint team provided us with the developer dashboard and the SPMonitoredScope class!

How to activate the developer dashboard?
There are several different ways to activate and deactivate the toolbar; it is up to your greater judgment to decide which one seems the most suitable for your situation. By default it is deactivated, so the first step would be the activation. You can do this by using STSADM, PowerShell or C#

STSADM

stsadm -o setproperty -pn developer-dashboard -pv onstsadm -o setproperty -pn developer-dashboard -pv offstsadm -o setproperty -pn developer-dashboard -pv OnDemand

PowerShell

Add-PSSnapin Microsoft.SharePoint.Powershell$dash =[Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
$dash.DisplayLevel = 'OnDemand';
$dash.TraceEnabled = $true;
$dash.Update()

PowerShell function
How to provide custom traces in developer dashboard?
SPMonitoredScope implements from IDisposable, so it is better to use it in combination with a using statement.

public class SPMonitoredScope : IDisposable

If you specify the onDemand setting, you receive a link button which displays a button which you can use to toggle the dashboard.

In order to demonstrate how easy it is,

  • I created a new visual web part project and added this code in the page_load method.
  • The code does nothing special, a single thread.sleep to simulate a long running operation and the monitoredscope scope around it.
  • If we add the web part to the page and open the developer dashboard by using the new icon that appears next to your username, you can see that there is a new message in the dashboard and ULS view:


How to provide the developer dashboard on a custom master page?
In order to provide this functionality on your own master page or custom page, you need 2 components.

  • The first component (SharePoint:DeveloperDashboardLauncher) is the link button that allows you to enable/disable the dashboard.
  • The second component is the dashboard (SharePoint:DeveloperDashboard)control itself.

When should I use it?
I would recommend using the SPMonitoredScope as a best practice around each major code block in your public methods. And while testing your web part you can review (and maybe improve) the performance of your code in detail.

What about sandboxed solutions?
You cannot use SPMonitoredScope in Sandboxed Solutions.

Happy SPCoding !!

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Webservice Xslt Transformer WebPart for SharePoint 2010 (Extended XML Viewer Webpart)

I’m happy to announce a new webpart that extends the powerfull XML Viewer webpart. This new web part is 100% available at codeplex.

It allows you to provide the URL of a web service, a SOAP Envelope, a SOAP Action and an XSLT definition.

When the webpart is added to a page, it wil automatically access the predefinied web service with the provide soap envelope. The XML that is returned by the web service is transformed by using the user definied XSLT.

This approach allows you to quickly provide show data from an external system in a no-code-solution.

Download the wsp and/or code from codeplex.com

I hope it can help you!

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

SharePoint 2010 – The Performance Guide – Part 3 – Track bottlenecks while using the SharePoint Developer Dashboard

Track bottlenecks while using the SharePoint Developer Dashboard ?

As SharePoint developers we aren’t only responsible for creating the functionality that is required, but we are also responsible for the overall quality of the solution we build. This means an ergonomic fluent user interface, code that is suitable for changes and in my opinion one of the most important aspects, a good performance. Most of these topics are described in white papers, best practices and millions of books and blog posts… but wouldn’t it be a pleasure if it was already in the platform? Yes, indeed!

SPMonitoredScope

That is why the SharePoint team provided us with the developer dashboard and the SPMonitoredScope class! I’ve already written a blog post concerning the how and the what of the developer dashboard here: http://bit.ly/yKmBSR

Custom master page

When you are using a custom master page and not the out-of-the-box v4 master page the controls that are rendering the dashboard aren’t available. But it is allowed to provide these controls in your custom master page in order to benefit from the functionality it contains.

First of all you need to provide the correct assemblies in your master page.
Using the Developer Dashboard: http://msdn.microsoft.com/en-us/library/ff512745.aspx

Anonymous access

Waldek Mastykarz has written an excellent blogpost about this:
http://blog.mastykarz.nl/enable-developer-dashboard-anonymous-users/

Hope it helps
Tom

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)