安装MiniProfiler

在MVC + EF + Bootstrap 2 权限管理系统入门级(附源码)文章中下载了它的源码,调试模式下打开一个页面都要再2.5秒以上,所以使用MiniProfiler、MiniProfiler.MVC4 、MiniProfiler.EF6组件进行了分析。

首先,依次序安装组件。然后,修改Global.aspx.cs 文件:

 protected void Application_Start(){AreaRegistration.RegisterAllAreas();WebApiConfig.Register(GlobalConfiguration.Configuration);FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);RouteConfig.RegisterRoutes(RouteTable.Routes);BundleConfig.RegisterBundles(BundleTable.Bundles);//自定义View
            ViewEngines.Engines.Clear();ExtendedRazorViewEngine engine = new ExtendedRazorViewEngine();engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.cshtml");engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.vbhtml");ViewEngines.Engines.Add(engine);//Model去除前后空格ModelBinders.Binders.DefaultBinder = new TrimModelBinder();//设置MEF依赖注入容器
            MefConfig.RegisterMef();//初始化EF6的性能监控
            MiniProfilerEF6.Initialize();//初始化DB
            DatabaseInitializer.Initialize();}protected void Application_BeginRequest(){StackExchange.Profiling.MiniProfiler.Start();}protected void Application_EndRequest(){StackExchange.Profiling.MiniProfiler.Stop();}

MiniProfilerEF6.Initialize(); 一定要放在 DatabaseInitializer.Initialize(); 之前,否则会报如下错误:

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code. Additional information: The Entity Framework was already using a DbConfiguration instance before an attempt was made to add an 'Loaded' event handler. 'Loaded' event handlers can only be added as part of application start up before the Entity Framework is used."

运行站点有可能还会遇到这个错误:

An exception of type 'System.Data.SqlClient.SqlException' occurred in MiniProfiler.dll but was not handled in user code

Additional information: Invalid column name 'CreatedOn'.

解决方法是:

1.禁用这种类型的异常断点(不可取)

2.删除packages\MiniProfiler.3.2.0.157\lib\net40 下的MiniProfiler.PDB文件(我是这么做的)

3.禁用EF的数据库变化跟踪(未验证,应该管用)

Found an answer for my question. Thanks all for replies.Database.SetInitializer<MyContext<Label>>(null);
This fixes the problem and disables DB changes tracking in EF.

运行站点打开登陆页

Sql占了47.7%,点开可以查看执行了哪些sql语句。

分析页面耗时

首先,调试模式下运行Debug和Release代码,耗时差不多都很长,截图如下:

    

   

然后,非调试模式(Ctrl+F5)运行,截图如下:

非调试模式(Ctrl+F5)的效率还是挺不错的,没想到和调试模式(F5)差别会这么大。使用必应搜了一下找到一个帖子 :Visual C++: Difference between Start with/without debugging in Release mode

里面的解释是

The problem is that Windows drops in a special Debug Heap, if it detects that your program is running under a Debugger. This appears to happen at the OS level, and is independent of any Debug/Release mode settings for your compilation.

You can work around this 'feature' by setting an environment variable: _NO_DEBUG_HEAP=1

This same issue has been driving me nuts for a while; today I found the following, from whence this post is derived: http://blogs.msdn.com/b/larryosterman/archive/2008/09/03/anatomy-of-a-heisenbug.aspx

另外为了更细化的跟踪某个方法的耗时可以在代码中这么写:

    public AdminLayoutAttribute(){//TODO: Test//var userRole = new List<UserRole> { new UserRole { Id = 1, UserId = 1, RoleId = 1 } };//var user = new User { Id = 1, LoginName = "admin", LoginPwd = "8wdJLK8mokI=", UserRole = userRole };//SessionHelper.SetSession("CurrentUser", user);var user = SessionHelper.GetSession("CurrentUser") as User;if (user != null){//  using (StackExchange.Profiling.MiniProfiler.StepStatic("AdminLayout")) using (MiniProfiler.Current.Step("AdminLayout")){// Enqueue a jobvar container = System.Web.HttpContext.Current.Application["Container"] as CompositionContainer;UserService = container.GetExportedValueOrDefault<IUserService>();RoleService = container.GetExportedValueOrDefault<IRoleService>();RoleModulePermissionService = container.GetExportedValueOrDefault<IRoleModulePermissionService>();ModuleService = container.GetExportedValueOrDefault<IModuleService>();ModulePermissionService = container.GetExportedValueOrDefault<IModulePermissionService>();PermissionService = container.GetExportedValueOrDefault<IPermissionService>();}}}

再次访问模块管理时就可以看到AdminLayout的耗时了,好像耗时特别小时这里就不记录

总之有这么一个组件确实可以量化执行过程的耗时。对方法调用次数执行分析更强大的工具还是DotTrace,如图:

参考链接:

MiniProfiler(MiniProfiler.EF6监控调试MVC5和EF6的性能)

解决:MiniProfiler.EF出现System.InvalidOperationException”类型的异常在 EntityFramework.dll 中发生

Entity Framework 4.3. Invalid column name 'CreatedOn'

Miniprofiler breaks on missing CreatedOn column

转载于:https://www.cnblogs.com/zeroes/p/miniProfiler.html

使用MiniProfiler跟踪MVC + EF + Bootstrap 2 权限管理系统的性能消耗相关推荐

  1. ABP+AdminLTE+Bootstrap Table权限管理系统第八节--ABP错误机制及AbpSession相关

      返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 上一节我们讲到登录逻辑,我做的登录逻辑很简单的,我们来看一下abp module-zero里面的登录代码. # ...

  2. ABP+AdminLTE+Bootstrap Table权限管理系统第五节--WBEAPI及SwaggerUI

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 一,Web API ABP的动态WebApi实现了直接对服务层的调用(其实病没有跨过ApiController,只 ...

  3. ABP+AdminLTE+Bootstrap Table权限管理系统第九节--AdminLTE引入及模板页和布局和菜单...

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 AdminLTE AdminLTE 官网地址:https://adminlte.io/themes/AdminLT ...

  4. ABP+AdminLTE+Bootstrap Table权限管理系统一期

      初衷    学而时习之,不亦说乎,温顾温知新,可以为师矣.           看懂远不如动手去做,动手做才能发现很多自己不懂的问题,不断的反思和总结,"乐于分享是一种境界的突破&quo ...

  5. ABP+AdminLTE+Bootstrap Table权限管理系统第四节--仓储,服务,服务接口及依赖注入

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 AbpModule 在ABP框架中,仓储,服务,这块算是最为重要一块之一了.ABP框架提供了创建和组装模块的基础, ...

  6. ABP+AdminLTE+Bootstrap Table权限管理系统第二节--在ABP的基础做数据库脚本处理

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 第一点,上一篇文章中我们讲到codefirst中一些问题包括如图,codefirst在每次执行命令的时候会生成新的 ...

  7. ABP+AdminLTE+Bootstrap Table权限管理系统第十一节--bootstrap table之用户管理列表

    ABP+AdminLTE+Bootstrap Table权限管理系统一期 Github:https://github.com/Jimmey-Jiang/ABP-ASP.NET-Boilerplate- ...

  8. ABP module-zero +AdminLTE+Bootstrap Table+jQuery权限管理系统第十三节--RBAC模式及ABP权限管理(附赠福利)

    ABP+AdminLTE+Bootstrap Table权限管理系统一期 Github:https://github.com/Jimmey-Jiang/ABP-ASP.NET-Boilerplate- ...

  9. ABP module-zero +AdminLTE+Bootstrap Table+jQuery权限管理系统第十四节--后台工作者HangFire与ABP框架Abp.Hangfire及扩展...

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 HangFire与Quartz.NET相比主要是HangFire的内置提供集成化的控制台,方便后台查看及监控,对于 ...

最新文章

  1. springboot过滤器排除掉一些url_理解这9大内置过滤器,才算是精通Shiro
  2. UVA11624 Fire!(bfs)
  3. IOS开发 ARC forbids explicit message send of 'autorelease'错误解决办法
  4. div 居中,浏览器兼容性
  5. TCP连接过程:三次握手与四次握手—Vecloud微云
  6. 虚拟机中web服务器的搭建,虚拟机下搭建web服务器
  7. PHP获取当前页面的URL
  8. java获取spring注解的实体_Spring 注解实体类中非数据库字段属性
  9. python时间序列异常值查找_(No.38)时间序列异常点检测算法
  10. proc wifi 开启_49.Linux-wpa_cli使用之WIFI开启,扫描热点,连接热点,断开热点,WIFI关闭(49)...
  11. Android 代码中执行adb shell命令
  12. GaussDB Hash表分布列选择原则及数据倾斜检测
  13. 旅游系统(SSM框架 结构+效果图)
  14. 计算机学win7画图,win7自带画图工具(mspaint.exe)
  15. Python 获取Windows关机消息
  16. Java面试题-day25 数据库之事务
  17. 随机手机号码_微信绑定了手机号码怎么解绑
  18. 合成资产赛道风云突变,Linear Finance有望成为最具潜力的黑马
  19. Bootstrap.yml 和 application.yml
  20. 根据时间戳获取相应的日期和时间

热门文章

  1. 浅谈程序的核心--复杂度
  2. python 中 pynlpir错误 Cannot Open Configure file pynlpir解决
  3. mysql thread入门分析
  4. Oracle 服务器 进程中的 LOCAL=NO 和 LOCAL=YES
  5. git clone 仓库的部分代码
  6. thinkphp模版常量替换机制
  7. Mysql 中如何创建触发器
  8. Fragment 生命周期:
  9. 解决 Ubuntu Software (Software Center) Crash 问题
  10. 谈一下JavaScript的语法