-
使用nuget添加MiniProfiler.EF组件
-
在Global文件中配置MiniProfiler
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //初始化miniProfiler StackExchange.Profiling.EntityFramework6.MiniProfilerEF6.Initialize(); } protected void Application_BeginRequest() { MiniProfiler.Start(); } protected void Application_EndRequest() { MiniProfiler.Stop(); }
-
在_Layout文件中添加
@StackExchange.Profiling.MiniProfiler.RenderIncludes()
-
在webconfig文件中添加
<system.webServer> <handlers> <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" /> </handlers> </system.webServer>
-
查看运行结果
6.细微监控,在Action如下添加:
var profiler = MiniProfiler.Current;
List<PictureCategory> cates;
using (profiler.Step("获取PictureCategory列表"))
{
cates = db.PictureCategories.ToList();
}
关于如何使用MiniProfiler更好的文章MiniProfiler.EF6监控调试MVC5和EF6的性能