The Developer Dashboard is a great way in SharePoint 2010 to see what's going on behind the scenes when a page is loading in SharePoint. It breaks down the components of the page and how long they took. It also lists out information like how many SQL queries have been run, critical events, the correlation ID, and other important information. The Developer Dashboard can be set to on, off, or ondemand at will for your farm. Some folks will do it with STSADM using the command "stsadm –o setproperty –pn developer-dashboard –pv [on|off|ondemand]" choosing the level they want the developer dashboard to be at. We will mock those people and call them bad names. We know by now that the cool kids all use Windows PowerShell to manage SharePoint 2010. How does one do that? Unfortunately it is a little more difficult in PowerShell, but we'll fix that later. First, the ugly details. Here is the PowerShell code you would use to configure the developer dashboard:
$dash =
[Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
$dash.DisplayLevel = 'OnDemand';
$dash.TraceEnabled = $true;
$dash.Update()
This sets the developer dashboard to "ondemand." You can also set it to On or Off. You'll notice we do have an additional setting we can set with PowerShell, TraceEnabled. We'll cover that later. If we turn the Developer Dashboard on we'll get the following dashboard at the bottom of our web pages:
If we choose ondemand the dashboard won't show on page load, but we'll get an icon up by our name to enable it. Also notice at the lower left corner of the page there is a link to enable the tracing information. That's where it gets really deep and technical. Show that to your STSADM using friends.
I mentioned earlier that the PowerShell code above is kind of ugly, and you likely won't memorize it. To help all my faithful readers out, I've written a couple of PowerShell functions to help you out. Here's what they look like when they're used:
First you need to run the PS1 file to add the functions to PowerShell. That's the . .\devdashboardfunction.ps1 part.
Now you can use the two functions I wrote, Get-SPDeveloperDashboard and Set-SPDeveloperDashboard to get your current settings and set new settings. When you set new settings, the new settings will be displayed for you. What does the code look like? Well, it's pretty simple, or else I wouldn't be able to do it.
# PowerShell functions to deal with the Developer Dashboard
# Author: Todd Klindt
# Contact: http://www.toddklindt.com/blog
# Version 1.0 March 28th, 2010
function Get-SPDeveloperDashboard
{
$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
Write-Host "DisplayLevel = " $dash.DisplayLevel;
Write-Host "TraceEnabled = " $dash.TraceEnabled;
}
function Set-SPDeveloperDashboard
{param ($DisplayLevel, $TraceEnabled)
switch($displaylevel)
{
on {$level = "on"; break}
off {$level = "off"; break }
ondemand {$level = "ondemand"; break}
default {"Please enter On, Off, or Ondemand for the DisplayLevel";break}
} # end of switch
switch($traceEnabled)
{
$null {break}
on {$tracelevel = $true;break}
off {$tracelevel = $false;break}
true {$tracelevel = $true;break}
false {$tracelevel = $false;break}
default {"Please enter On or Off for TraceEnabled";break}
} # end of switch
if ($level -ne $null) {
$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
$dash.DisplayLevel = $level;
if ($tracelevel -ne $null) {
$dash.TraceEnabled = $tracelevel;
}
$dash.Update()
Get-SPDeveloperDashboard
} # end if
} # end of Set-DeveloperDashboard
You can download the file devdashboardfunction.ps1 from here. Let me be very clear. You should NEVER download and execute PowerShell code you find on the Internet, ESPECIALLY if it's something I've written. I'm an idiot and honestly I'm surprised that works, let alone works well. For all I know that code my delete your SharePoint farm, format your server, and let the air out of your tires. Whenever you grab a PowerShell script from the Internet read it over and understand what it does before you use it. And don't come crying to me if your cat ends up getting shaved after your run this. Consider yourself warned.
This code adds the two functions I wrote to PowerShell. Once they are there you can use tab complete on the function names, and their parameters. The functions are essentially what we looked at above, along with some very, very basic error checking. If any developers read my blog I'm sure milk just shot out their nose when they read my code. It's a good thing, you don't have to worry about me stealing your jobs or anything. J
Hope that helps some folks. If you want more information on the Developer Dashboard, let me know. I'll write up more about it.
tk