-
-
Save mahizsas/b88faf4288bffef5f738 to your computer and use it in GitHub Desktop.
Razor mini profiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using StackExchange.Profiling; | |
namespace MiniProfiler.Razor { | |
public class ProfiledRazorViewEngine : RazorViewEngine { | |
protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath) { | |
using (MiniProfiler.Current.Step("CreatePartialView " + partialPath)) { | |
IView view = base.CreatePartialView(controllerContext, partialPath); | |
return new ProfiledView(view, partialPath); | |
} | |
} | |
protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) { | |
using (MiniProfiler.Current.Step("CreateView " + viewPath)) { | |
IView view = base.CreateView(controllerContext, viewPath, masterPath); | |
return new ProfiledView(view, viewPath); | |
} | |
} | |
private class ProfiledView : IView { | |
private readonly IView view; | |
private readonly string debugName; | |
public ProfiledView(IView view, string debugName) { | |
this.view = view; | |
this.debugName = debugName; | |
} | |
public void Render(ViewContext viewContext, System.IO.TextWriter writer) { | |
using (MiniProfiler.Current.Step("Rendering " + debugName)) { | |
view.Render(viewContext, writer); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment