使用MiniProfiler检测页面性能

1.引入nuget包

PM> Install-Package MiniProfiler

2.配置界面

@using StackExchange.Profiling;
<head>
..
</head>
<body>
...
@MiniProfiler.RenderIncludes()
</body>

3.配置Global.asax.cs

using StackExchange.Profiling;
...
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
} protected void Application_Start()
{
//EF监控配置
MiniProfilerEF6.Initialize();
}

4.监控具体代码

using StackExchange.Profiling;
...
var profiler = MiniProfiler.Current; // it's ok if this is null
using (profiler.Step("Set page title"))
{
ViewBag.Title = "Home Page";
}
using (profiler.Step("Doing complex stuff"))
{
using (profiler.Step("Step A"))
{ // something more interesting here
Thread.Sleep(100);
}
using (profiler.Step("Step B"))
{ // and here
Thread.Sleep(250);
}
}

5.视图不现实监控结果

<system.webServer>
...
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>

  

官网介绍:http://miniprofiler.com/

上一篇:JavaScript之能力与硬件检测[小结]


下一篇:【转】shell脚本中echo显示内容带颜色