Nop-Profiler的改进方向,通过Miniprofiler设置仅对某些条件下的访问开放profiler trace<七>
2012-03-06 11:09
543 查看
Nop-Profiler的改进方向,通过Miniprofiler设置仅对某些条件下的访问开放profilertrace<七>
分类:17:299人阅读
[csharp]view
plaincopy
EngineContext.Current.Resolve<IConfigurationProvider<StoreInformationSettings>>()
.SaveSettings(newStoreInformationSettings()
{
StoreName="Yourstorename",
StoreUrl="http://www.yourStore.com/",
StoreClosed=false,
StoreClosedAllowForAdmins=false,
DefaultStoreTheme="DarkOrange",
AllowCustomerToSelectTheme=false,
DisplayMiniProfilerInPublicStore=false,
});
关于Mvc-Mini-Profiler
Mini-Profile的本意是用于Asp.NETMVC和Asp.nET程序Profile的简单工具,它本身不Hook到每一个线程,并不注重解决重要的Performance问题,相反:EngineContext.Current.Resolve<IConfigurationProvider<StoreInformationSettings>>()
.SaveSettings(newStoreInformationSettings()
{
StoreName="Yourstorename",
StoreUrl="http://www.yourStore.com/",
StoreClosed=false,
StoreClosedAllowForAdmins=false,
DefaultStoreTheme="DarkOrange",
AllowCustomerToSelectTheme=false,
DisplayMiniProfilerInPublicStore=false,
});
关于Mvc-Mini-Profiler
.适用与ADO.NET,LINQtoSQL.EF甚至EF-codefirst的性能监测
.通过代码来Profile指定代码段的性能
我们来看一下Nop是怎么使用到Profiler的:
在Frontweb的_root.cshtml中
vardisplayMiniProfiler=EngineContext.Current.Resolve<Nop.Core.Domain.StoreInformationSettings>().DisplayMiniProfilerInPublicStore;}
理论上,后台应该在商店信息部分设置是否要显示性能分析数据(这个对于分析网站的性能是有帮助的,但如何仅针对管理员还需要进一步讨论,例如写数据到Log,或者Table,而不是显示在Page上):
publicclassStoreInformationSettings:ISettings{publicstringStoreName{get;set;}publicstringStoreUrl{get;set;}publicboolStoreClosed{get;set;}publicboolStoreClosedAllowForAdmins{get;set;}publicstringDefaultStoreTheme{get;set;}publicboolAllowCustomerToSelectTheme{get;set;}publicboolDisplayMiniProfilerInPublicStore{get;set;}}
在InstallationService当中,我们DisplayMiniProfilerInPublicStore=false,
<head>中注入Miniprofile的脚本以及输出内容的CSS
@if(displayMiniProfiler){@MvcMiniProfiler.MiniProfiler.RenderIncludes();}
在Global.asax.cs
AreaRegistration.RegisterAllAreas();if(DataSettingsHelper.DatabaseIsInstalled()&&EngineContext.Current.Resolve<StoreInformationSettings>().DisplayMiniProfilerInPublicStore){GlobalFilters.Filters.Add(newProfilingActionFilter());}
在Global.asax中,Web程序EndRequest中,Profile功能的关闭:
[csharp]viewplain copyprotectedvoidApplication_EndRequest(objectsender,EventArgse)
{
if(DataSettingsHelper.DatabaseIsInstalled()&&
EngineContext.Current.Resolve<StoreInformationSettings>().DisplayMiniProfilerInPublicStore)
{
//stopasearlyasyoucan,evenearlierwithMvcMiniProfiler.MiniProfiler.Stop(discardResults:true);
MiniProfiler.Stop();
}
}
使用步骤:
1.下载MVCMiniprofiler,添加引用
2.一般而言,选择在Layoutroot文件中Head增加
@MvcMiniProfiler.MiniProfiler.RenderIncludes()</head>
3.在Global.asax.csApplication_BeginRequest:
其实在这里可以增加逻辑判断,例如仅本地登陆启动Profile;特定用户Profile,NopCommerce在这个方面可以改进一下:
if(Request.IsLocal)MvcMiniProfiler.MiniProfiler.Start();
。。。。。。。。
protectedvoidApplication_End(){MvcMiniProfiler.MiniProfiler.Stop();}
在后台某个View-Controller中:
usingMvcMiniProfiler;
...
varprofiler=MiniProfiler.Current;//it'sokifthisisnull
using(profiler.Step("Setpagetitle"))
{
ViewBag.Title="HomePage";
}
using(profiler.Step("Doingcomplexstuff"))
{
using(profiler.Step("StepA"))
{//somethingmoreinterestinghere
Thread.Sleep(100);
}
using(profiler.Step("StepB"))
{//andhere
Thread.Sleep(250);
}
}
更多信息,请参考:
相关文章推荐
- Nop-Profiler的改进方向,通过Miniprofiler设置仅对某些条件下的访问开放profiler trace<七>
- 标题:深度分销的方向和尺度 内容:<P> 深度分销的方向和尺度<BR> 所谓深度分销,有人也称之为通路精耕细作,是通过减少原有渠道层次,并增强中间商分销能力或通过企
- Apache服务器虚拟主机设置问题-如何使通过IP访问为默认的apache页面 <转载>
- Nop-通过IStartupTask实现代码执行<六>
- Nop-通过IStartupTask实现代码执行<六>
- <input type="text"/>可通过width="" height=""设置宽度高度
- angularjs 中通过ui-router设置不同网页不同<title>内容
- UML参考手册 第三部分 参 考 资 料 第13章 术 语 大 全 <七>
- 【script代码段】通过<script src="http://xxx.com/index.php"></script>中的src属性将服务器断数据传到客户端
- <cocos2dx 随记一> 在windows上设置分辨率上的一些坑
- Android实战简易教程<三十八>(模仿腾讯QQ的网络状态提示和设置功能实现)
- JPA开发总结<七>--Bug总结
- <excel>条件求和方法
- 软件工程基础<七>
- # include <errno.h >查看错误代码errno是调试程序的一个重要方法。当Linux C API函数发生异常时,一般会将errno变量赋值一个整数,不同的值表示不同的含义,可以通过查看
- struts2通过<s:tree>或者dtree插件 建立树形结构
- 在Jsp中使用<s:if test="">,条件的值是action中设置的session的值
- 条件注释判断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]>
- C#制作QQ截图的自动框选功能的个人思路(二)<设置Hook>
- 实时开发框架Meteor API解读系列<七> Collection --01