Sharepoint学习笔记—Debug&TroubleShooting--Developer Dashboard的使用(1.开启 Developer Dashboard)
Developer Dashboard是从Sharepoint2010开始新提供的一项亲特性,它是一个位于页面下方的信息面板,它能直接显示出当前页面上的各个组件的运行时间、当前页面的运行会产生哪些数据库调用、每个数据库调用等等信息,对于Sharepoint网站的开发,维护和调试很有帮助。
Developer Dashboard在默认情况下是关闭的,你需要自己去开启这项功能,但是在Sharepoint的用户界面中没有开箱即用的功能让你来开启它,通常有三种方式来启用它,而且一旦启用,它就在整个Farm中都有效。
1、使用STSADM命令
此命令就是给developer-dashboard属性设置相关值,三种可选值
off:关闭
on :始终打开
onDemand :网站管理员可以选择打开或者关闭。这样网站管理员可以选择打开或关闭特定网站集的监控输出,这将作为故障排除工具之针对特定的人群。
Stsadm –o setproperty –pn developer-dashboard –pv on
Stsadm –o setproperty –pn developer-dashboard –pv ondemand
2、使用PowerShell命令
使用txt编辑器创建一个PowerShell的psl文件,命名为DeveDashboard.psl,并保存到C:\下,DeveDashboard代码如下:
write-host "Loading PowerShell environment for SharePoint" -foregroundcolor Green
write-host
# unload & load the sharepoint powershell snapin
$snapin = Get-PSSnapin | where-object { $_.Name -eq
'Microsoft.SharePoint.PowerShell' }
if ($snapin -ne $null){
write-host "Unloading SharePoint PowerShell Snapin..." -foregroundcolor Blue
remove-pssnapin "Microsoft.SharePoint.PowerShell"
write-host "SharePoint PowerShell Snapin unloaded." -foregroundcolor Green
}
$snapin = Get-PSSnapin | where-object { $_.Name -eq
'Microsoft.SharePoint.PowerShell' }
if ($snapin -eq $null){
write-host "Loading SharePoint PowerShell Snapin..." -foregroundcolor Blue
add-pssnapin "Microsoft.SharePoint.PowerShell"
write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
}
write-host "Enabling the developer dashboard..." -foregroundcolor Blue
$contentService =
[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dashboardSetting = $contentService.DeveloperDashboardSettings
$dashboardSetting.DisplayLevel =
[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$dashboardSetting.Update()
write-host "Developer dashboard enabled." -foregroundcolor Green
然后以Administrator方式打开Powershell,运行它,执行效果如下:
3、使用Code
3.1创建一个Webpart,让此Webpart执行下面的代码,并部署到Central Administration site上(因为developer dashboard是一个在Farm层次上的设置)
你需要引入Microsoft.SharePoint.Administration命名空间
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace EnableDeveloperDashboard
{
class Program
{
static void Main()
{
SPDeveloperDashboardSettings settings =SPWebService.ContentService.DeveloperDashboardSettings;
settings.DisplayLevel = SPDeveloperDashboardLevel.On;
settings.Update();
}
}
}
3.2创建一个基于.NET Framework 3.5的控制台程序,并将build设置为Any CPU(因为SharePoint是x64的)。在此控制台程序中执行下面代码
perfmon.DeveloperDashboardLevel = SPPerformanceMonitoringLevel.On;
perfmon.Update();
当以OnMand方式打开时,你可以在网站的右上角看到一个Icon,你可以使用此Icon来控制Developer Dashboard的开启与关闭
4、下载现成的Feature来控制Developer-DashBoard
网上有人开发了现成的Feature,请从(这里)下载,你可以把它部署到Administrator Centrel上,如下图
点击后进入设置界面如下: