Tuesday, June 5, 2012

Developer Dash board in SharePoint 2010 – Part 2


If you have not gone through Part-1 of this series, I would recommend you reading Part-1 and then continue reading from here on.

Okay, so now we have turned our developer dashboard to OnDemand. So let’s open up our site.

And observe one icon on the top right.



This is the icon for developer dashboard. When you click on it you can see at the bottom of the page which displayed the rendering time taken by each method and time taken by database calls. What all methods have been called, Service queries, web part events etc.



Click on the icon again to hide it.

When you move to any other page, dashboard again goes off. You again need to click on icon to get it back.

If you always want it to be there then you have to set in settings of developer dashboard as on rather than ondemand.

Let’s say we have developed our custom web part and we have placed that web part on a page. So navigate to a page where you have kept the web part and click on developer dashboard.



And here you get in developer dashboard

As you can see it was visual web part and we can see how much time taken by that visual web part to load.

This gives us little information. But what If you actually want to know how much time code written on button click takes. Generally if you want to know time taken to perform action or load some events and we want to include that time as a part of developer dashboard, then we need to use SPMonitoredScore class.

Let’s dive into SPMonitoredScopre class.

Overall idea is we need to wrap up our code inside SPmonitored scope and the way we should do it is ;

using (new SPMonitoredScope(“Name of the scope”))
{
   doSomeWork();
}

When we do this, the code written in doSomeWork method captured by the developer dashboard and you can track down more details on code tracing.

Let’s add some examples to a web part that I showed you earlier on a page.
I have added a code in one of the button click event.



Now redeploy the solution and let’s see what happens when we click on that button.
If you now observe you get to see on left pane your own custom scope.



This also adds an entry to Log file on the server. If you open the latest log file and search for scope name, you get this



In this way, you can trace time taken by each method. Do not use this class everywhere. Use it with caution as if you unexpectedly use this class to trace a long running method then it may add few extra burden on page and increase its size for adding to the developer dashboard.

We can also add developer dashboard icon when you are developing your custom master page. 

This is very important to have. All we need is just use developer dashboard SharePoint control in master page. Just to demonstrate I have added in web part.



And here is what you get



Couple of important notes that you should know is that

  1)     SPMonitoredScope class can only be used if your custom development is going to be deployed as farm solution and not as sandbox solution. Sandbox solution runs in different process than farm solution as it is not captured in w3wp process.

2)    Use another class called SPDiagnosticsService to log tracing and performance timing for custom solutions in LOG folder of server that do not run under HTTP like SharePoint timer service.

I hope this must have given some basic idea as how to use developer dash board and its use in SharePoint.

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com