From cb8d080f1d1c4d3da52f682056fc00a1f941763d Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Sun, 12 May 2013 19:05:49 -1000 Subject: [PATCH] Removes the abstraction on the profiler, no need for a resolver, it will work in unit tests and we can override the provider if needed. Added better support for MVC profiling by using the built in ProfilingViewEngine and ProfilingActionFilter. --- src/Umbraco.Core/CoreBootManager.cs | 3 - src/Umbraco.Core/Profiling/IProfiler.cs | 78 ++--- src/Umbraco.Core/Profiling/LogProfiler.cs | 62 ++-- ...xtensions.cs => MiniProfilerExtensions.cs} | 5 +- .../Profiling/ProfilerResolver.cs | 66 ++-- src/Umbraco.Core/Profiling/WebProfiler.cs | 290 +++++++++--------- src/Umbraco.Core/Umbraco.Core.csproj | 2 +- src/Umbraco.Core/UmbracoApplicationBase.cs | 75 +++-- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 4 + src/Umbraco.Web.UI/packages.config | 1 + src/Umbraco.Web.UI/umbraco/umbraco.aspx | 3 +- src/Umbraco.Web/Mvc/ControllerExtensions.cs | 10 + src/Umbraco.Web/Mvc/UmbracoTemplatePage.cs | 3 +- src/Umbraco.Web/Umbraco.Web.csproj | 4 + src/Umbraco.Web/WebBootManager.cs | 11 +- src/Umbraco.Web/packages.config | 1 + .../umbraco.presentation/default.aspx.cs | 9 +- src/Umbraco.Web/umbraco.presentation/item.cs | 5 +- src/Umbraco.Web/umbraco.presentation/macro.cs | 21 +- .../umbraco/masterpages/default.Master.cs | 3 +- .../umbraco/masterpages/umbracoPage.Master.cs | 3 +- .../umbraco/templateControls/ItemRenderer.cs | 5 +- 22 files changed, 362 insertions(+), 302 deletions(-) rename src/Umbraco.Core/Profiling/{ProfilerExtensions.cs => MiniProfilerExtensions.cs} (70%) diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 419f9cd873..e5dc8240a7 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -187,9 +187,6 @@ namespace Umbraco.Core /// protected virtual void InitializeResolvers() { - //By default we'll initialize the Log profiler (in the web project, we'll override with the web profiler) - ProfilerResolver.Current = new ProfilerResolver(new LogProfiler()); - //by default we'll use the standard configuration based sync ServerRegistrarResolver.Current = new ServerRegistrarResolver( new ConfigServerRegistrar()); diff --git a/src/Umbraco.Core/Profiling/IProfiler.cs b/src/Umbraco.Core/Profiling/IProfiler.cs index 6021fb8a4a..12e6e6714f 100644 --- a/src/Umbraco.Core/Profiling/IProfiler.cs +++ b/src/Umbraco.Core/Profiling/IProfiler.cs @@ -1,44 +1,44 @@ -using System; +//using System; -namespace Umbraco.Core.Profiling -{ - /// - /// Defines an object for use in the application to profile operations - /// - public interface IProfiler - { +//namespace Umbraco.Core.Profiling +//{ +// /// +// /// Defines an object for use in the application to profile operations +// /// +// public interface IProfiler +// { - /// - /// Render the UI to display the profiler - /// - /// - /// - /// Generally used for HTML displays - /// - string Render(); +// /// +// /// Render the UI to display the profiler +// /// +// /// +// /// +// /// Generally used for HTML displays +// /// +// string Render(); - /// - /// Profile a step - /// - /// - /// - /// - /// Use the 'using(' syntax - /// - IDisposable Step(string name); +// /// +// /// Profile a step +// /// +// /// +// /// +// /// +// /// Use the 'using(' syntax +// /// +// IDisposable Step(string name); - /// - /// Start the profiler - /// - void Start(); +// /// +// /// Start the profiler +// /// +// void Start(); - /// - /// Start the profiler - /// - /// - /// set discardResults to false when you want to abandon all profiling, this is useful for - /// when someone is not authenticated or you want to clear the results based on some other mechanism. - /// - void Stop(bool discardResults = false); - } -} \ No newline at end of file +// /// +// /// Start the profiler +// /// +// /// +// /// set discardResults to false when you want to abandon all profiling, this is useful for +// /// when someone is not authenticated or you want to clear the results based on some other mechanism. +// /// +// void Stop(bool discardResults = false); +// } +//} \ No newline at end of file diff --git a/src/Umbraco.Core/Profiling/LogProfiler.cs b/src/Umbraco.Core/Profiling/LogProfiler.cs index a074d9e409..22b35f4de5 100644 --- a/src/Umbraco.Core/Profiling/LogProfiler.cs +++ b/src/Umbraco.Core/Profiling/LogProfiler.cs @@ -1,35 +1,35 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Umbraco.Core.Logging; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using Umbraco.Core.Logging; -namespace Umbraco.Core.Profiling -{ - /// - /// A profiler that outputs its results to the LogHelper - /// - public class LogProfiler : IProfiler - { - public string Render() - { - return string.Empty; - } +//namespace Umbraco.Core.Profiling +//{ +// /// +// /// A profiler that outputs its results to the LogHelper +// /// +// public class LogProfiler : IProfiler +// { +// public string Render() +// { +// return string.Empty; +// } - public IDisposable Step(string name) - { - LogHelper.Debug(typeof(LogProfiler), "Starting - " + name); - return DisposableTimer.Start(l => LogHelper.Info(typeof (LogProfiler), () => name + " (took " + l + "ms)")); - } +// public IDisposable Step(string name) +// { +// LogHelper.Debug(typeof(LogProfiler), "Starting - " + name); +// return DisposableTimer.Start(l => LogHelper.Info(typeof (LogProfiler), () => name + " (took " + l + "ms)")); +// } - public void Start() - { - //the log will alwasy be started - } +// public void Start() +// { +// //the log will alwasy be started +// } - public void Stop(bool discardResults = false) - { - //we don't need to do anything here - } - } -} +// public void Stop(bool discardResults = false) +// { +// //we don't need to do anything here +// } +// } +//} diff --git a/src/Umbraco.Core/Profiling/ProfilerExtensions.cs b/src/Umbraco.Core/Profiling/MiniProfilerExtensions.cs similarity index 70% rename from src/Umbraco.Core/Profiling/ProfilerExtensions.cs rename to src/Umbraco.Core/Profiling/MiniProfilerExtensions.cs index b9718271b9..8eb8a2ba63 100644 --- a/src/Umbraco.Core/Profiling/ProfilerExtensions.cs +++ b/src/Umbraco.Core/Profiling/MiniProfilerExtensions.cs @@ -1,8 +1,9 @@ using System; +using StackExchange.Profiling; namespace Umbraco.Core.Profiling { - public static class ProfilerExtensions + public static class MiniProfilerExtensions { /// /// Writes out a step prefixed with the type @@ -11,7 +12,7 @@ namespace Umbraco.Core.Profiling /// /// /// - public static IDisposable Step(this IProfiler profiler, string name) + public static IDisposable Step(this MiniProfiler profiler, string name) { return profiler.Step(string.Format("[" + typeof (T).Name + "] " + name)); } diff --git a/src/Umbraco.Core/Profiling/ProfilerResolver.cs b/src/Umbraco.Core/Profiling/ProfilerResolver.cs index 250084c441..92009967f2 100644 --- a/src/Umbraco.Core/Profiling/ProfilerResolver.cs +++ b/src/Umbraco.Core/Profiling/ProfilerResolver.cs @@ -1,37 +1,37 @@ -using Umbraco.Core.ObjectResolution; +//using Umbraco.Core.ObjectResolution; -namespace Umbraco.Core.Profiling -{ - /// - /// A resolver exposing the current profiler - /// - public class ProfilerResolver : SingleObjectResolverBase - { - /// - /// Constructor - /// - /// - public ProfilerResolver(IProfiler profiler) - : base(profiler) - { +//namespace Umbraco.Core.Profiling +//{ +// /// +// /// A resolver exposing the current profiler +// /// +// public class ProfilerResolver : SingleObjectResolverBase +// { +// /// +// /// Constructor +// /// +// /// +// public ProfilerResolver(IProfiler profiler) +// : base(profiler) +// { - } +// } - /// - /// Method allowing to change the profiler during startup - /// - /// - internal void SetProfiler(IProfiler profiler) - { - Value = profiler; - } +// /// +// /// Method allowing to change the profiler during startup +// /// +// /// +// internal void SetProfiler(IProfiler profiler) +// { +// Value = profiler; +// } - /// - /// Gets the current profiler - /// - public IProfiler Profiler - { - get { return Value; } - } - } -} \ No newline at end of file +// /// +// /// Gets the current profiler +// /// +// public IProfiler Profiler +// { +// get { return Value; } +// } +// } +//} \ No newline at end of file diff --git a/src/Umbraco.Core/Profiling/WebProfiler.cs b/src/Umbraco.Core/Profiling/WebProfiler.cs index 99465102e7..1c1d40cd45 100644 --- a/src/Umbraco.Core/Profiling/WebProfiler.cs +++ b/src/Umbraco.Core/Profiling/WebProfiler.cs @@ -1,161 +1,161 @@ -using System; -using System.Web; -using StackExchange.Profiling; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; +//using System; +//using System.Web; +//using StackExchange.Profiling; +//using Umbraco.Core.Configuration; +//using Umbraco.Core.Logging; -namespace Umbraco.Core.Profiling -{ - /// - /// A profiler used for web based activity based on the MiniProfiler framework - /// - public class WebProfiler : IProfiler - { +//namespace Umbraco.Core.Profiling +//{ +// /// +// /// A profiler used for web based activity based on the MiniProfiler framework +// /// +// public class WebProfiler : IProfiler +// { - /// - /// Constructor - /// - /// - /// Binds to application events to enable the MiniProfiler - /// - internal WebProfiler() - { - UmbracoApplicationBase.ApplicationInit += UmbracoApplicationApplicationInit; - } +// /// +// /// Constructor +// /// +// /// +// /// Binds to application events to enable the MiniProfiler +// /// +// internal WebProfiler() +// { +// UmbracoApplicationBase.ApplicationInit += UmbracoApplicationApplicationInit; +// } - /// - /// Handle the Init event o fthe UmbracoApplication which allows us to subscribe to the HttpApplication events - /// - /// - /// - void UmbracoApplicationApplicationInit(object sender, EventArgs e) - { - var app = sender as HttpApplication; - if (app == null) return; +// /// +// /// Handle the Init event o fthe UmbracoApplication which allows us to subscribe to the HttpApplication events +// /// +// /// +// /// +// void UmbracoApplicationApplicationInit(object sender, EventArgs e) +// { +// var app = sender as HttpApplication; +// if (app == null) return; - if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) - { - //If we don't have a high enough trust level we cannot bind to the events - LogHelper.Info("Cannot start the WebProfiler since the application is running in Medium trust"); - } - else - { - app.BeginRequest += UmbracoApplicationBeginRequest; - app.EndRequest += UmbracoApplicationEndRequest; - } - } +// if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) +// { +// //If we don't have a high enough trust level we cannot bind to the events +// LogHelper.Info("Cannot start the WebProfiler since the application is running in Medium trust"); +// } +// else +// { +// app.BeginRequest += UmbracoApplicationBeginRequest; +// app.EndRequest += UmbracoApplicationEndRequest; +// } +// } - /// - /// Handle the begin request event - /// - /// - /// - void UmbracoApplicationEndRequest(object sender, EventArgs e) - { - if (GlobalSettings.DebugMode == false) return; - var request = TryGetRequest(sender); - if (request.Success == false) return; - if (request.Result.Url.IsClientSideRequest()) return; - if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false) - { - //stop the profiler - Stop(); - } - } +// /// +// /// Handle the begin request event +// /// +// /// +// /// +// void UmbracoApplicationEndRequest(object sender, EventArgs e) +// { +// if (GlobalSettings.DebugMode == false) return; +// var request = TryGetRequest(sender); +// if (request.Success == false) return; +// if (request.Result.Url.IsClientSideRequest()) return; +// if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false) +// { +// //stop the profiler +// Stop(); +// } +// } - /// - /// Handle the end request event - /// - /// - /// - void UmbracoApplicationBeginRequest(object sender, EventArgs e) - { - if (GlobalSettings.DebugMode == false) return; - var request = TryGetRequest(sender); - if (request.Success == false) return; - if (request.Result.Url.IsClientSideRequest()) return; - if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false) - { - //start the profiler - Start(); - } - } +// /// +// /// Handle the end request event +// /// +// /// +// /// +// void UmbracoApplicationBeginRequest(object sender, EventArgs e) +// { +// if (GlobalSettings.DebugMode == false) return; +// var request = TryGetRequest(sender); +// if (request.Success == false) return; +// if (request.Result.Url.IsClientSideRequest()) return; +// if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false) +// { +// //start the profiler +// Start(); +// } +// } - /// - /// Render the UI to display the profiler - /// - /// - /// - /// Generally used for HTML displays - /// - public string Render() - { - return MiniProfiler.RenderIncludes().ToString(); - } +// /// +// /// Render the UI to display the profiler +// /// +// /// +// /// +// /// Generally used for HTML displays +// /// +// public string Render() +// { +// return MiniProfiler.RenderIncludes().ToString(); +// } - /// - /// Profile a step - /// - /// - /// - /// - /// Use the 'using(' syntax - /// - public IDisposable Step(string name) - { - if (GlobalSettings.DebugMode == false) return null; +// /// +// /// Profile a step +// /// +// /// +// /// +// /// +// /// Use the 'using(' syntax +// /// +// public IDisposable Step(string name) +// { +// if (GlobalSettings.DebugMode == false) return null; - return MiniProfiler.Current.Step(name); - } +// return MiniProfiler.Current.Step(name); +// } - /// - /// Start the profiler - /// - public void Start() - { - if (GlobalSettings.DebugMode == false) return; - //will not run in medium trust - if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return; +// /// +// /// Start the profiler +// /// +// public void Start() +// { +// if (GlobalSettings.DebugMode == false) return; +// //will not run in medium trust +// if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return; - MiniProfiler.Start(); - } +// MiniProfiler.Start(); +// } - /// - /// Start the profiler - /// - /// - /// set discardResults to false when you want to abandon all profiling, this is useful for - /// when someone is not authenticated or you want to clear the results based on some other mechanism. - /// - public void Stop(bool discardResults = false) - { - if (GlobalSettings.DebugMode == false) return; - //will not run in medium trust - if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return; +// /// +// /// Start the profiler +// /// +// /// +// /// set discardResults to false when you want to abandon all profiling, this is useful for +// /// when someone is not authenticated or you want to clear the results based on some other mechanism. +// /// +// public void Stop(bool discardResults = false) +// { +// if (GlobalSettings.DebugMode == false) return; +// //will not run in medium trust +// if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return; - MiniProfiler.Stop(discardResults); - } +// MiniProfiler.Stop(discardResults); +// } - /// - /// Gets the request object from the app instance if it is available - /// - /// The application object - /// - private Attempt TryGetRequest(object sender) - { - var app = sender as HttpApplication; - if (app == null) return Attempt.False; +// /// +// /// Gets the request object from the app instance if it is available +// /// +// /// The application object +// /// +// private Attempt TryGetRequest(object sender) +// { +// var app = sender as HttpApplication; +// if (app == null) return Attempt.False; - try - { - var req = app.Request; - return new Attempt(true, new HttpRequestWrapper(req)); - } - catch (HttpException ex) - { - return new Attempt(ex); - } - } +// try +// { +// var req = app.Request; +// return new Attempt(true, new HttpRequestWrapper(req)); +// } +// catch (HttpException ex) +// { +// return new Attempt(ex); +// } +// } - } -} \ No newline at end of file +// } +//} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f013f5a6b7..3279f12251 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -523,7 +523,7 @@ - + diff --git a/src/Umbraco.Core/UmbracoApplicationBase.cs b/src/Umbraco.Core/UmbracoApplicationBase.cs index eef1aa2215..8cedd54bc9 100644 --- a/src/Umbraco.Core/UmbracoApplicationBase.cs +++ b/src/Umbraco.Core/UmbracoApplicationBase.cs @@ -25,11 +25,6 @@ namespace Umbraco.Core public static event EventHandler ApplicationStarting; public static event EventHandler ApplicationStarted; - /// - /// Called when the HttpApplication.Init() is fired, allows developers to subscribe to the HttpApplication events - /// - public static event EventHandler ApplicationInit; - /// /// Boots up the Umbraco application /// @@ -53,17 +48,49 @@ namespace Umbraco.Core protected void Application_Start(object sender, EventArgs e) { StartApplication(sender, e); + + if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) + { + //If we don't have a high enough trust level we cannot bind to the events + LogHelper.Info("Cannot use the MiniProfiler since the application is running in Medium trust"); + } } /// - /// Override init and raise the event + /// Initializes the mini profiler for the request /// - public override void Init() + protected void Application_BeginRequest() { - base.Init(); - OnApplicationInit(this, new EventArgs()); + if (GlobalSettings.DebugMode == false) return; + var request = TryGetRequest(); + if (request.Success == false) return; + if (request.Result.Url.IsClientSideRequest()) return; + if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return; + if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false) + { + //start the profiler + MiniProfiler.Start(); + } } + /// + /// Closes the mini profiler for the request + /// + protected void Application_EndRequest() + { + if (GlobalSettings.DebugMode == false) return; + var request = TryGetRequest(); + if (request.Success == false) return; + if (request.Result.Url.IsClientSideRequest()) return; + if (SystemUtilities.GetCurrentTrustLevel() < AspNetHostingPermissionLevel.High) return; + if (string.IsNullOrEmpty(request.Result["umbDebug"]) == false) + { + //stop the profiler + MiniProfiler.Stop(); + } + } + + /// /// Developers can override this method to modify objects on startup /// @@ -85,18 +112,7 @@ namespace Umbraco.Core if (ApplicationStarted != null) ApplicationStarted(sender, e); } - - /// - /// Called to raise the ApplicationInit event - /// - /// - /// - private void OnApplicationInit(object sender, EventArgs e) - { - if (ApplicationInit != null) - ApplicationInit(sender, e); - } - + /// /// A method that can be overridden to invoke code when the application has an error. /// @@ -146,5 +162,22 @@ namespace Umbraco.Core protected abstract IBootManager GetBootManager(); + /// + /// Gets the request object from the app instance if it is available + /// + /// + private Attempt TryGetRequest() + { + try + { + var req = Request; + return new Attempt(true, new HttpRequestWrapper(req)); + } + catch (HttpException ex) + { + return new Attempt(ex); + } + } + } } diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 43a2e3e60f..68a4476536 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -127,6 +127,10 @@ False ..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll + + False + ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll + False ..\packages\MySql.Data.6.6.4\lib\net40\MySql.Data.dll diff --git a/src/Umbraco.Web.UI/packages.config b/src/Umbraco.Web.UI/packages.config index 4e7a226db2..e1ede92f48 100644 --- a/src/Umbraco.Web.UI/packages.config +++ b/src/Umbraco.Web.UI/packages.config @@ -16,6 +16,7 @@ + diff --git a/src/Umbraco.Web.UI/umbraco/umbraco.aspx b/src/Umbraco.Web.UI/umbraco/umbraco.aspx index c153bae576..4a9490b049 100644 --- a/src/Umbraco.Web.UI/umbraco/umbraco.aspx +++ b/src/Umbraco.Web.UI/umbraco/umbraco.aspx @@ -4,6 +4,7 @@ <%@ Import Namespace="System.Web.Script.Serialization" %> <%@ Register Src="controls/Tree/TreeControl.ascx" TagName="TreeControl" TagPrefix="umbraco" %> +<%@ Import Namespace="StackExchange.Profiling" %> <%@ Import Namespace="Umbraco.Core.Profiling" %> <%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> <%@ Register TagPrefix="uc1" TagName="quickSearch" Src="Search/QuickSearch.ascx" %> @@ -391,7 +392,7 @@ <%if(string.IsNullOrEmpty(Request["umbDebug"]) == false && umbraco.GlobalSettings.DebugMode) { - Response.Write(ProfilerResolver.Current.Profiler.Render()); + Response.Write(MiniProfiler.RenderIncludes()); }%> diff --git a/src/Umbraco.Web/Mvc/ControllerExtensions.cs b/src/Umbraco.Web/Mvc/ControllerExtensions.cs index d17b1f2afe..087f124c6a 100644 --- a/src/Umbraco.Web/Mvc/ControllerExtensions.cs +++ b/src/Umbraco.Web/Mvc/ControllerExtensions.cs @@ -22,6 +22,16 @@ namespace Umbraco.Web.Mvc } /// + /// Return the controller name from the controller instance + /// + /// + /// + internal static string GetControllerName(this IController controllerInstance) + { + return GetControllerName(controllerInstance.GetType()); + } + + /// /// Return the controller name from the controller type /// /// diff --git a/src/Umbraco.Web/Mvc/UmbracoTemplatePage.cs b/src/Umbraco.Web/Mvc/UmbracoTemplatePage.cs index 208b077c41..9ba2f6e92c 100644 --- a/src/Umbraco.Web/Mvc/UmbracoTemplatePage.cs +++ b/src/Umbraco.Web/Mvc/UmbracoTemplatePage.cs @@ -1,4 +1,5 @@ using System; +using StackExchange.Profiling; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Dictionary; @@ -94,7 +95,7 @@ namespace Umbraco.Web.Mvc } else { - var profilerMarkup = ProfilerResolver.Current.Profiler.Render(); + var profilerMarkup = MiniProfiler.RenderIncludes(); text = text.Substring(0, pos) + profilerMarkup + text.Substring(pos, text.Length - pos); } base.WriteLiteral(text); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index f42b0fb0ee..aff039e771 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -126,6 +126,10 @@ False ..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll + + False + ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll + ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index a4a693bcb9..e9315add13 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -5,6 +5,7 @@ using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Routing; +using StackExchange.Profiling.MVCHelpers; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Dictionary; @@ -72,13 +73,16 @@ namespace Umbraco.Web new MasterControllerFactory(FilteredControllerFactoriesResolver.Current)); //set the render view engine - ViewEngines.Engines.Add(new RenderViewEngine()); + ViewEngines.Engines.Add(new ProfilingViewEngine(new RenderViewEngine())); //set the plugin view engine - ViewEngines.Engines.Add(new PluginViewEngine()); + ViewEngines.Engines.Add(new ProfilingViewEngine(new PluginViewEngine())); //set model binder ModelBinders.Binders.Add(new KeyValuePair(typeof(RenderModel), new RenderModelBinder())); + //add the profiling action filter + GlobalFilters.Filters.Add(new ProfilingActionFilter()); + return this; } @@ -236,9 +240,6 @@ namespace Umbraco.Web { base.InitializeResolvers(); - //Set the profiler to be the web profiler - ProfilerResolver.Current.SetProfiler(new WebProfiler()); - //set the default RenderMvcController DefaultRenderMvcControllerResolver.Current = new DefaultRenderMvcControllerResolver(typeof(RenderMvcController)); diff --git a/src/Umbraco.Web/packages.config b/src/Umbraco.Web/packages.config index 8763102da7..547b8010a1 100644 --- a/src/Umbraco.Web/packages.config +++ b/src/Umbraco.Web/packages.config @@ -15,6 +15,7 @@ + diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs index b3727b4a31..5405c384f0 100644 --- a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs @@ -6,6 +6,7 @@ using System.Web.UI; using System.IO; using System.Xml; using System.Text.RegularExpressions; +using StackExchange.Profiling; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Profiling; @@ -45,7 +46,7 @@ namespace umbraco protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); - using (ProfilerResolver.Current.Profiler.Step("PreInit")) + using (MiniProfiler.Current.Step("PreInit")) { // handle the infamous umbDebugShowTrace, etc @@ -82,7 +83,7 @@ namespace umbraco protected override void OnInit(EventArgs e) { - using (ProfilerResolver.Current.Profiler.Step("Init")) + using (MiniProfiler.Current.Step("Init")) { base.OnInit(e); @@ -119,7 +120,7 @@ namespace umbraco protected override void OnLoad(EventArgs e) { - using (ProfilerResolver.Current.Profiler.Step("Load")) + using (MiniProfiler.Current.Step("Load")) { base.OnLoad(e); @@ -133,7 +134,7 @@ namespace umbraco protected override void Render(HtmlTextWriter writer) { - using (ProfilerResolver.Current.Profiler.Step("Render")) + using (MiniProfiler.Current.Step("Render")) { // do the original rendering diff --git a/src/Umbraco.Web/umbraco.presentation/item.cs b/src/Umbraco.Web/umbraco.presentation/item.cs index f864e9494c..9063d154f7 100644 --- a/src/Umbraco.Web/umbraco.presentation/item.cs +++ b/src/Umbraco.Web/umbraco.presentation/item.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Web; using System.Xml; +using StackExchange.Profiling; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Profiling; @@ -98,7 +99,7 @@ namespace umbraco /// private string GetRecursiveValueLegacy(IDictionary elements) { - using (ProfilerResolver.Current.Profiler.Step("Checking recusively")) + using (MiniProfiler.Current.Step("Checking recusively")) { var content = ""; @@ -130,7 +131,7 @@ namespace umbraco private void ParseItem(IDictionary attributes) { - using (ProfilerResolver.Current.Profiler.Step("Start parsing " + _fieldName)) + using (MiniProfiler.Current.Step("Start parsing " + _fieldName)) { HttpContext.Current.Trace.Write("item", "Start parsing '" + _fieldName + "'"); if (helper.FindAttribute(attributes, "textIfEmpty") != "" && _fieldContent == "") diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index 465eba4a0c..5225163527 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -17,6 +17,7 @@ using System.Web.UI.WebControls; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; +using StackExchange.Profiling; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Events; @@ -235,7 +236,7 @@ namespace umbraco ? string.Format("Render Inline Macro, Cache: {0})", Model.CacheDuration) : string.Format("Render Macro: {0}, type: {1}, cache: {2})", Name, Model.MacroType, Model.CacheDuration); - using (ProfilerResolver.Current.Profiler.Step(macroInfo)) + using (MiniProfiler.Current.Step(macroInfo)) { TraceInfo("renderMacro", macroInfo); @@ -281,7 +282,7 @@ namespace umbraco return GetControlForErrorBehavior("Error loading Partial View script (file: " + ScriptFile + ")", macroErrorEventArgs); }; - using (ProfilerResolver.Current.Profiler.Step("Executing Partial View: " + Model.TypeName)) + using (MiniProfiler.Current.Step("Executing Partial View: " + Model.TypeName)) { TraceInfo("umbracoMacro", "Partial View added (" + Model.TypeName + ")"); try @@ -317,7 +318,7 @@ namespace umbraco } case (int) MacroTypes.UserControl: - using (ProfilerResolver.Current.Profiler.Step("Executing UserControl: " + Model.TypeName)) + using (MiniProfiler.Current.Step("Executing UserControl: " + Model.TypeName)) { try { @@ -361,7 +362,7 @@ namespace umbraco case (int) MacroTypes.CustomControl: - using (ProfilerResolver.Current.Profiler.Step("Executing CustomControl: " + Model.TypeName + "." + Model.TypeAssembly)) + using (MiniProfiler.Current.Step("Executing CustomControl: " + Model.TypeName + "." + Model.TypeAssembly)) { try { @@ -423,7 +424,7 @@ namespace umbraco return GetControlForErrorBehavior("Error loading MacroEngine script (file: " + ScriptFile + ")", macroErrorEventArgs); }; - using (ProfilerResolver.Current.Profiler.Step("Executing MacroEngineScript: " + ScriptFile)) + using (MiniProfiler.Current.Step("Executing MacroEngineScript: " + ScriptFile)) { try { @@ -500,7 +501,7 @@ namespace umbraco { string dateAddedCacheKey; - using (ProfilerResolver.Current.Profiler.Step("Saving MacroContent To Cache: " + Model.CacheIdentifier)) + using (MiniProfiler.Current.Step("Saving MacroContent To Cache: " + Model.CacheIdentifier)) { // NH: Scripts and XSLT can be generated as strings, but not controls as page events wouldn't be hit (such as Page_Load, etc) @@ -830,7 +831,7 @@ namespace umbraco return new LiteralControl(string.Empty); } - using (ProfilerResolver.Current.Profiler.Step("Executing XSLT: " + XsltFile)) + using (MiniProfiler.Current.Step("Executing XSLT: " + XsltFile)) { XmlDocument macroXml = null; @@ -859,7 +860,7 @@ namespace umbraco { var xsltFile = getXslt(XsltFile); - using (ProfilerResolver.Current.Profiler.Step("Performing transformation")) + using (MiniProfiler.Current.Step("Performing transformation")) { try { @@ -1681,8 +1682,8 @@ namespace umbraco //Trace out to profiling... doesn't actually profile, just for informational output. if (excludeProfiling == false) { - //NOTE: we cannot even do this since it throws an exception, need to use using clause: ProfilerResolver.Current.Profiler.Step(message).Dispose(); - using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}, Error: {1}", message, ex))) + //NOTE: we cannot even do this since it throws an exception, need to use using clause: MiniProfiler.Current.Step(message).Dispose(); + using (MiniProfiler.Current.Step(string.Format("{0}, Error: {1}", message, ex))) { } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/default.Master.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/default.Master.cs index 3536aae6c7..c37e2b6cdf 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/default.Master.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/default.Master.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Web.UI; +using StackExchange.Profiling; using Umbraco.Core.Profiling; using umbraco.presentation.LiveEditing; using umbraco.presentation.LiveEditing.Controls; @@ -40,7 +41,7 @@ namespace umbraco.presentation.masterpages base.Render(new HtmlTextWriter(baseWriter)); var baseOutput = baseWriter.ToString(); - baseOutput = baseOutput.Replace("", ProfilerResolver.Current.Profiler.Render() + ""); + baseOutput = baseOutput.Replace("", MiniProfiler.RenderIncludes() + ""); writer.Write(baseOutput); } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/umbracoPage.Master.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/umbracoPage.Master.cs index f86587256a..fe412b2adb 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/umbracoPage.Master.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/masterpages/umbracoPage.Master.cs @@ -7,6 +7,7 @@ using System.Web.UI.WebControls; //This is only in case an upgrade goes wrong and the the /masterpages/ files are not copied over //which would result in an error. so we have kept the old namespaces intact with references to new ones +using StackExchange.Profiling; using Umbraco.Core.Profiling; using mp = umbraco.presentation.masterpages; namespace umbraco.presentation.umbraco.masterpages @@ -42,7 +43,7 @@ namespace umbraco.presentation.masterpages // profiling if (string.IsNullOrEmpty(Request.QueryString["umbDebug"]) == false && GlobalSettings.DebugMode) { - baseOutput = baseOutput.Replace("", ProfilerResolver.Current.Profiler.Render() + ""); + baseOutput = baseOutput.Replace("", MiniProfiler.RenderIncludes() + ""); } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs index 341009f024..1f918a8011 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs @@ -8,6 +8,7 @@ using System.Web; using System.Web.Caching; using System.Web.UI; using System.Xml; +using StackExchange.Profiling; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Macros; @@ -134,7 +135,7 @@ namespace umbraco.presentation.templateControls /// The item. public virtual void Load(Item item) { - using (ProfilerResolver.Current.Profiler.Step(string.Format("Item: {0}", item.Field))) + using (MiniProfiler.Current.Step(string.Format("Item: {0}", item.Field))) { ParseMacros(item); } @@ -152,7 +153,7 @@ namespace umbraco.presentation.templateControls string elementText = GetFieldContents(item); - using (ProfilerResolver.Current.Profiler.Step("Parsing Macros")) + using (MiniProfiler.Current.Step("Parsing Macros")) { MacroTagParser.ParseMacros(