承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

Developer Dashboard 排忧解难!!!

描述:

 

   今天在客户现场遇到一个怪异的问题,SharePoint 2010 首页突然访问奇慢无比呀(其他站点正常),可是昨天晚上还是好好的嘛,今天又要给领导汇报,给我急得啊,愁死我了。。

感觉是那个webpart 出问题了,可是以前都是好好的呀,初步排查应该是首页那个webpart的访问数据有问题,导致的情况,

首页无非是,内容查询 ,内容编辑 EXCEL相关webpart 为了搞清楚 具体是那个webpart 导致我的首页奇慢无比嘛~~~

百思不得其解中,突然想起来SharePoint2010 自带了 Developer 仪表盘 来分析网站的执行情况。(开启服务后,豁然开朗。。。。)

2种方法:

Code:

SPPerformanceMonitor perfmon = SPFarm.Local.PerformanceMonitor;

perfmon.DeveloperDashboardLevel = SPPerformanceMonitoringLevel.On;

perfmon.Update();

 

cmd:

 

STSADM –o setproperty –pn developer-dashboard –pv on(or "on" or "off")

 

使用 SPMonitoredScope  监控你的代码 具体情况

使用SPMonitoredScope可以很方便的将某段代码的相关性能信息输出到Developer Dashboard中。使用SPMonitoredScope很简单,首先声明一个SPMonitoredScope的实例并赋予一个可以追踪的名字,将需要Track的代码写入即可。例如,下边的代码演示了插入一个列表项:

using (SPMonitoredScope monitoredScope = new SPMonitoredScope("My Monitored Scope"))

{

    // put code to monitor performance on here

    SPList testList = site.Lists.TryGetList("Test List");

    if (testList != null)

    {

        SPListItem listItem = testList.Items.Add();

        listItem["Title"] = string.Format("Test Item {0}", Guid.NewGuid().ToString());

        listItem["City"] = "Somewhere";

        listItem["Quantity"] = 3;

        listItem.Update();

    }

}
 

 

在SPMonitoredScope中你还可以嵌套使用SPMonitoredScope对象以更详细的监控尽可能小的代码段来分析器性能。

using (SPMonitoredScope monitoredScope = new SPMonitoredScope("My Monitored Scope"))

{

    SPList testList;

 

    using (SPMonitoredScope getListMonitor = new SPMonitoredScope("Get List"))

    {

        testList = site.Lists.TryGetList("Test List");

    }

 

    using (SPMonitoredScope addListItemMonitor = new SPMonitoredScope("Add List Item"))

    {

        if (testList != null)

        {

            SPListItem listItem = testList.Items.Add();

            listItem["Title"] = string.Format("Test Item {0}", Guid.NewGuid().ToString());

            listItem["City"] = "Somewhere";

            listItem["Quantity"] = 3;

            listItem.Update();

        }

    }

}
 

正如期望的,我们在My Monitored Scope中看到了更为详细的监控段Get List和Add List Item。这样就能很清楚的看到每个代码段的性能情况。

 

 

 

 

posted on 2010-11-30 21:21  A A  阅读(708)  评论(0编辑  收藏  举报