Miniprofiler Official website: http://miniprofiler.com/
A particularly useful feature of Miniprofiler is its integration with the database framework. Apart from. NET native DbConnection class, Miniprofiler also has built-in support for the Entity Framework and LINQ to SQL, Ravendb, and MongoDB. Any step that executes will include the number of queries and the time spent. To detect common errors, such as the n+1 anti-pattern, Profiler detects multiple queries with only a difference in parameter values.
With blue Fox learn MVC tutorial--MINIPROFILER.EF6 monitor debug MVC5 and EF6 performance
Previously developed WebForm can open trace to track the page events, which for the performance of the diagnostic program is a great help, play a multiplier effect, today I will talk about using MVC development project debugging and performance monitoring. The EF framework automatically generates SQL statements for me, and when our program encounters performance problems we can use MINIPROFILER.EF to monitor the performance of MVC and EF, see the generated SQL statements, what SQL is running, and how long it takes. Miniprofiler.ef, a lightweight, open-source MVC performance Debug, monitoring component Miniprofiler a custom-built version for EF. Here's a specific example of how to debug MVC and EF Performance with MINIPROFILER.EF6 monitoring in our project. The following project is based on one of my previous articles, MVC5 and EF6 Code First complete Example tutorial
1, installation Miniprofiler.ef6
Enter Miniprofiler in the NuGet search box and the following results will appear:
Click Install to add MINIPROFILER.EF6 related DLLs to the project. 2, add Miniprofiler.ef related code to the project inside
1, in Global.asax to join the Miniprofiler related monitoring code
The complete content after the modification is:
usingSYSTEM.WEB.MVC;usingSystem.Web.Optimization;usingSystem.Web.Routing;usingstackexchange.profiling;usingStackExchange.Profiling.EntityFramework6;namespaceminiprofilerdemo{ Public classMvcApplication:System.Web.HttpApplication {protected voidApplication_Start () {arearegistration.registerallareas (); Filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); Bundleconfig.registerbundles (Bundletable.bundles); Miniprofileref6.initialize (); } protected voidApplication_BeginRequest () {Miniprofiler.start (); } protected voidapplication_endrequest () {miniprofiler.stop (); } }}
Among them is the addition of miniprofileref6.initialize () in Application_Start and the addition of Application_BeginRequest, Application_ BeginRequest two application event functions, the function of which is to initialize MiniProfilerEF6 and start, end miniprofiler monitoring.
2. Modify the _layout.cshtml view file
Add a piece of code to the body of the views\shared\_layout.cshtml file to let the monitor appear on the page.
@StackExchange. Profiling.MiniProfiler.RenderIncludes ()
Such as:
3. Add code to Web. config
<system.webserver> <handlers> <Addname= "Miniprofiler"Path= "mini-profiler-resources/*"verb="*"type= "System.Web.Routing.UrlRoutingModule"ResourceType= "Unspecified"Precondition= "Integratedmode" /> </handlers></system.webserver>
In order to show the debug trace time of MVC and EF on the page you have to add the above code. Such as:
In the Handlers node under the System.webserver configuration node, a handler named Miniprofiler is added.
3, view the running results run the program, view the page such as:
Can see the left corner more than a number of chunks, indicating the number of milliseconds spent on this page, click on the number above to pop up detailed time tracking information, such as:
You can see that this page runs three SQL statements, and SQL takes you 673.4 milliseconds and takes up 12.5% of the time. You can also click this SQL time to show which SQL is running, such as:
4, micro-monitoring method internal time
Now we add monitoring to Productcontroller, which monitors the time it takes to get the product records from the database. We changed the Productcontroller to:
usingMiniprofilerdemo.dal;usingSystem.Linq;usingSYSTEM.WEB.MVC;usingstackexchange.profiling;usingSystem.Collections.Generic;usingMiniprofilerdemo.models;namespaceminiprofilerdemo.controllers{ Public classProductcontroller:controller { PublicActionResult Index () {using(Efdbcontext db =NewEfdbcontext ()) { varProfiler =miniprofiler.current; List<Product>m; using(Profiler. Step ("Get the Product list") ) {m=db. Products.tolist (); } returnView (m); } } }}
Rebuild the project and run the view page again, such as:
You can see more of the "Get product List" record that we just added manually. This allows for subtle monitoring of the internal time of the method, which helps us find the bottleneck of our program quickly and easily.
Original address: http://www.lanhusoft.com/Article/125.html
Note: This article for Ef6,nuget in the EF5 version, a little change can be.
Go: ASP. NET MVC EF performance monitoring debugging tool Miniprofiler