mvc-mini-profiler - An effective mini profiler for ASP.NET MVC

The mvc-mini-profiler is a lightweight, but effective mini profiler tool for ASP.NET apps specially designed for ASP.NET MVC 3 apps. The mvc-mini-profiler is an free and open source tool from Stack Overflow team. The tool is initially developed for StackOverflow family of websites and open sources the tool later. This is an another great open source tool from Stack Overflow team after Dapper object mapper for .Net. The mvc-mini-profiler is available from http://code.google.com/p/mvc-mini-profiler/ . The mvc-mini-profiler is also available as a NuGet package .

How to using mvc-mini-profile

Step 1

Add reference to MvcMiniProfiler. You can use NuGet to add reference to MvcMiniProfiler

Step 2

Write out the css and javascript includes in the layout page

  1. @MiniProfiler.RenderIncludes()

Step 3

Start the mini profiler when you want to start profiling

  1. @using MvcMiniProfiler;

The below code block of the Application_BeginRequest event will start profiling if the request is from local computer

  1. protected void Application_BeginRequest()
  2. {
  3.     MiniProfiler profiler = null;
  4.     if (Request.IsLocal)
  5.     {
  6.         profiler = MvcMiniProfiler.MiniProfiler.Start();
  7.     }
  8. }

Step 4

Do the profiling when you want to perform profiling

  1. public ActionResult Index()
  2. {
  3.     var profiler = MiniProfiler.Current;
  4.     using (profiler.Step("IndexPage"))
  5.     {
  6.         ViewBag.Title = "Home Page";               
  7.     }
  8.     using (profiler.Step("Doing complex stuff"))
  9.     {
  10.         using (profiler.Step("Step A"))
  11.         {
  12.             Thread.Sleep(100);
  13.         }
  14.         using (profiler.Step("Step B"))
  15.         {
  16.             Thread.Sleep(250);
  17.         }
  18.     }
  19.  
  20.     return View();
  21. }

 

Step 5

Stop the mini profiler when you want to stop it

  1. protected void Application_EndRequest()
  2. {
  3.     MvcMiniProfiler.MiniProfiler.Stop();
  4. }

 

The above code stops the mini profiler in the Application_EndRequest() event.

Published Monday, June 13, 2011 4:45 AM by shiju

Comments

# mvc-mini-profiler - An effective mini-profiler for ASP.NET MVC

Monday, June 13, 2011 5:14 AM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: mvc-mini-profiler - An effective mini-profiler for ASP.NET MVC

Monday, June 13, 2011 11:35 AM by Alvin

Thanks for the details with .Good one

# mvc-mini-profiler - An effective mini profiler for ASP.NET MVC

Monday, June 27, 2011 6:14 AM by DotNetAlbum - An Exclusive Directory for .NET Geeks

Thank you for submitting this cool story - Trackback from DotNetAlbum - An Exclusive Directory for .NET Geeks

# @wayne_douglas http://weblogs.asp.net/shijuvarghese/archive/2011/06/13/mvc-mini-profiler-an-effective-mini-profiler-for-asp-net-mvc.aspx ?

Tuesday, July 05, 2011 7:38 AM by Twitter Mirror

@wayne_douglas http://weblogs. asp.net /shijuvarghese/archive/2011/06/13/mvc-mini-profiler-an-effective

# some Usefull Links

Tuesday, September 13, 2011 7:23 AM by Azizkhani WebSite

some Usefull Links

Leave a Comment

(required) 
(required) 
(optional)
(required)