Nop-Profiler的改进方向,通过Miniprofiler设置仅对某些条件下的访问开放profiler trace<七>
2012-02-23 17:29
351 查看
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问题,相反:.适用与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功能的关闭:
protectedvoidApplication_EndRequest(objectsender,EventArgse)
{
if(DataSettingsHelper.DatabaseIsInstalled()&&
EngineContext.Current.Resolve<StoreInformationSettings>().DisplayMiniProfilerInPublicStore)
{
//stopasearlyasyoucan,evenearlierwithMvcMiniProfiler.MiniProfiler.Stop(discardResults:true);
MiniProfiler.Stop();
}
}
[/code]
使用步骤:
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<七>
- Nop-通过IStartupTask实现代码执行<六>
- <input type="text"/>可通过width="" height=""设置宽度高度
- angularjs 中通过ui-router设置不同网页不同<title>内容
- 标题:深度分销的方向和尺度 内容:<P> 深度分销的方向和尺度<BR> 所谓深度分销,有人也称之为通路精耕细作,是通过减少原有渠道层次,并增强中间商分销能力或通过企
- Nop-通过IStartupTask实现代码执行<六>
- Apache服务器虚拟主机设置问题-如何使通过IP访问为默认的apache页面 <转载>
- <深入理解计算机系统> 通过程序的机器级表示来理解函数栈
- Android ListView中设置的字体颜色显示错乱问题 && SparseArray<E>的使用
- <input type="file">中怎设置按钮的样式
- <img>设置background有白色边框
- Spring零配置通过注解实现Bean依赖注入总结<转>
- ios错误<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set
- Subversion之路—–实现精细的目录访问权限控制<转>
- 左右方向滚动的图片代码和<marquee>效果有点不同
- 【Qt编程】基于Qt的词典开发系列<七>--调用网络API
- Java中使用SQL标签库<sql:setDataSource />设置数据源
- MFC 学习之 颜色设置<1>
- HTML学习记录<七> :表单
- android-改进<<仿QQ>>框架源代码