Miniprofiler.ef6 monitoring Debug MVC5 and EF6 performance

Source: Internet
Author: User
Tags what sql

Reprinted from: https://www.lanhusoft.com/Article/125.html

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.

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>    "miniprofiler" path= " mini-profiler-resources/* " verb="*" type="System.Web.Routing.UrlRoutingModule  "resourcetype="Unspecified" precondition= " Integratedmode" />    

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:

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.

Miniprofiler.ef6 monitoring Debug MVC5 and EF6 performance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.