From 09a6cdc8b6a7b85b5226f5c72f29b293df34fbeb Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Sun, 12 May 2013 18:06:26 -1000 Subject: [PATCH] Removed all MiniProfile calls that were trying to be simple trace messages (not actually profiling). This doesn't actually work since MiniProfiler was not meant for that and won't actually output them unless you add Thread.Sleep statements into the using clauses simply to slow down the application, not ideal. Updated the WebProfiler to log a statement when in medium trust. --- .../Profiling/ProfilerExtensions.cs | 19 ++++++++ src/Umbraco.Core/Profiling/WebProfiler.cs | 19 +++++--- src/Umbraco.Core/Umbraco.Core.csproj | 1 + src/Umbraco.Web/WebBootManager.cs | 2 +- .../umbraco.presentation/default.aspx.cs | 10 ++-- .../umbraco.presentation/helper.cs | 3 -- src/Umbraco.Web/umbraco.presentation/item.cs | 6 +-- src/Umbraco.Web/umbraco.presentation/macro.cs | 48 ++++++------------- .../umbraco/templateControls/ItemRenderer.cs | 4 +- 9 files changed, 58 insertions(+), 54 deletions(-) create mode 100644 src/Umbraco.Core/Profiling/ProfilerExtensions.cs diff --git a/src/Umbraco.Core/Profiling/ProfilerExtensions.cs b/src/Umbraco.Core/Profiling/ProfilerExtensions.cs new file mode 100644 index 0000000000..0bdb38fd95 --- /dev/null +++ b/src/Umbraco.Core/Profiling/ProfilerExtensions.cs @@ -0,0 +1,19 @@ +using System; + +namespace Umbraco.Core.Profiling +{ + public static class ProfilerExtensions + { + /// + /// Writes out a step prefixed with the type + /// + /// + /// + /// + /// + public static IDisposable Step(this IProfiler profiler, string name) + { + return profiler.Step(string.Format(typeof (T).Name + ", " + name)); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Profiling/WebProfiler.cs b/src/Umbraco.Core/Profiling/WebProfiler.cs index 1209b884ae..99465102e7 100644 --- a/src/Umbraco.Core/Profiling/WebProfiler.cs +++ b/src/Umbraco.Core/Profiling/WebProfiler.cs @@ -2,6 +2,7 @@ using System.Web; using StackExchange.Profiling; using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; namespace Umbraco.Core.Profiling { @@ -10,18 +11,15 @@ namespace Umbraco.Core.Profiling /// public class WebProfiler : IProfiler { - private readonly UmbracoApplicationBase _umbracoApplication; /// /// Constructor /// - /// /// /// Binds to application events to enable the MiniProfiler /// - internal WebProfiler(UmbracoApplicationBase umbracoApplication) + internal WebProfiler() { - _umbracoApplication = umbracoApplication; UmbracoApplicationBase.ApplicationInit += UmbracoApplicationApplicationInit; } @@ -34,8 +32,17 @@ namespace Umbraco.Core.Profiling { var app = sender as HttpApplication; if (app == null) return; - 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; + } } /// diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 4399ee9f4e..f013f5a6b7 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -523,6 +523,7 @@ + diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 8e876f6b63..a4a693bcb9 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -237,7 +237,7 @@ namespace Umbraco.Web base.InitializeResolvers(); //Set the profiler to be the web profiler - ProfilerResolver.Current.SetProfiler(new WebProfiler(UmbracoApplication)); + ProfilerResolver.Current.SetProfiler(new WebProfiler()); //set the default RenderMvcController DefaultRenderMvcControllerResolver.Current = new DefaultRenderMvcControllerResolver(typeof(RenderMvcController)); diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs index 5b932011d9..b3727b4a31 100644 --- a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs @@ -45,11 +45,11 @@ namespace umbraco protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); - using (ProfilerResolver.Current.Profiler.Step("PreInit")) + using (ProfilerResolver.Current.Profiler.Step("PreInit")) { // handle the infamous umbDebugShowTrace, etc - Page.Trace.IsEnabled &= GlobalSettings.DebugMode && !String.IsNullOrWhiteSpace(Request["umbDebugShowTrace"]); + Page.Trace.IsEnabled &= GlobalSettings.DebugMode && string.IsNullOrWhiteSpace(Request["umbDebugShowTrace"]) == false; // get the document request and the page _docRequest = UmbracoContext.Current.PublishedContentRequest; @@ -82,7 +82,7 @@ namespace umbraco protected override void OnInit(EventArgs e) { - using (ProfilerResolver.Current.Profiler.Step("Init")) + using (ProfilerResolver.Current.Profiler.Step("Init")) { base.OnInit(e); @@ -119,7 +119,7 @@ namespace umbraco protected override void OnLoad(EventArgs e) { - using (ProfilerResolver.Current.Profiler.Step("Load")) + using (ProfilerResolver.Current.Profiler.Step("Load")) { base.OnLoad(e); @@ -133,7 +133,7 @@ namespace umbraco protected override void Render(HtmlTextWriter writer) { - using (ProfilerResolver.Current.Profiler.Step("Render")) + using (ProfilerResolver.Current.Profiler.Step("Render")) { // do the original rendering diff --git a/src/Umbraco.Web/umbraco.presentation/helper.cs b/src/Umbraco.Web/umbraco.presentation/helper.cs index 252cfbad99..da93812949 100644 --- a/src/Umbraco.Web/umbraco.presentation/helper.cs +++ b/src/Umbraco.Web/umbraco.presentation/helper.cs @@ -127,9 +127,6 @@ namespace umbraco !string.IsNullOrEmpty(currentNode.FirstChild.Value) && !string.IsNullOrEmpty(currentNode.FirstChild.Value.Trim())) { - ProfilerResolver.Current.Profiler.Step("Loaded Recursively from " + - splitpath[ - splitpath.Length - i - 1]); HttpContext.Current.Trace.Write("parameter.recursive", "Item loaded from " + splitpath[splitpath.Length - i - 1]); attributeValue = currentNode.FirstChild.Value; break; diff --git a/src/Umbraco.Web/umbraco.presentation/item.cs b/src/Umbraco.Web/umbraco.presentation/item.cs index 9373dfb61c..f864e9494c 100644 --- a/src/Umbraco.Web/umbraco.presentation/item.cs +++ b/src/Umbraco.Web/umbraco.presentation/item.cs @@ -98,7 +98,7 @@ namespace umbraco /// private string GetRecursiveValueLegacy(IDictionary elements) { - using (ProfilerResolver.Current.Profiler.Step("Checking recusively")) + using (ProfilerResolver.Current.Profiler.Step("Checking recusively")) { var content = ""; @@ -119,8 +119,6 @@ namespace umbraco if (currentNode == null || currentNode.FirstChild == null || string.IsNullOrEmpty(currentNode.FirstChild.Value) || string.IsNullOrEmpty(currentNode.FirstChild.Value.Trim())) continue; - ProfilerResolver.Current.Profiler.Step("Found recursive value on " + - splitpath[splitpath.Length - i - 1]); HttpContext.Current.Trace.Write("item.recursive", "Item loaded from " + splitpath[splitpath.Length - i - 1]); content = currentNode.FirstChild.Value; break; @@ -132,7 +130,7 @@ namespace umbraco private void ParseItem(IDictionary attributes) { - using (ProfilerResolver.Current.Profiler.Step("Start parsing " + _fieldName)) + using (ProfilerResolver.Current.Profiler.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 29c26e077e..465eba4a0c 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -234,10 +234,10 @@ namespace umbraco var macroInfo = (Model.MacroType == MacroTypes.Script && Model.Name.IsNullOrWhiteSpace()) ? 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 (ProfilerResolver.Current.Profiler.Step(macroInfo)) { - TraceInfo("renderMacro", macroInfo, excludeProfiling: true); + TraceInfo("renderMacro", macroInfo); StateHelper.SetContextValue(MacrosAddedKey, StateHelper.GetContextValue(MacrosAddedKey) + 1); @@ -281,7 +281,7 @@ namespace umbraco return GetControlForErrorBehavior("Error loading Partial View script (file: " + ScriptFile + ")", macroErrorEventArgs); }; - using (ProfilerResolver.Current.Profiler.Step("Executing Partial View: " + Model.TypeName)) + using (ProfilerResolver.Current.Profiler.Step("Executing Partial View: " + Model.TypeName)) { TraceInfo("umbracoMacro", "Partial View added (" + Model.TypeName + ")"); try @@ -316,8 +316,8 @@ namespace umbraco break; } case (int) MacroTypes.UserControl: - - using (ProfilerResolver.Current.Profiler.Step("Executing UserControl: " + Model.TypeName)) + + using (ProfilerResolver.Current.Profiler.Step("Executing UserControl: " + Model.TypeName)) { try { @@ -360,8 +360,8 @@ namespace umbraco } case (int) MacroTypes.CustomControl: - - using (ProfilerResolver.Current.Profiler.Step("Executing CustomControl: " + Model.TypeName + "." + Model.TypeAssembly)) + + using (ProfilerResolver.Current.Profiler.Step("Executing CustomControl: " + Model.TypeName + "." + Model.TypeAssembly)) { try { @@ -423,7 +423,7 @@ namespace umbraco return GetControlForErrorBehavior("Error loading MacroEngine script (file: " + ScriptFile + ")", macroErrorEventArgs); }; - using (ProfilerResolver.Current.Profiler.Step("Executing MacroEngineScript: " + ScriptFile)) + using (ProfilerResolver.Current.Profiler.Step("Executing MacroEngineScript: " + ScriptFile)) { try { @@ -500,7 +500,7 @@ namespace umbraco { string dateAddedCacheKey; - using (ProfilerResolver.Current.Profiler.Step("Saving MacroContent To Cache: " + Model.CacheIdentifier)) + using (ProfilerResolver.Current.Profiler.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 +830,7 @@ namespace umbraco return new LiteralControl(string.Empty); } - using (ProfilerResolver.Current.Profiler.Step("Executing XSLT: " + XsltFile)) + using (ProfilerResolver.Current.Profiler.Step("Executing XSLT: " + XsltFile)) { XmlDocument macroXml = null; @@ -859,7 +859,7 @@ namespace umbraco { var xsltFile = getXslt(XsltFile); - using (ProfilerResolver.Current.Profiler.Step("Performing transformation")) + using (ProfilerResolver.Current.Profiler.Step("Performing transformation")) { try { @@ -1661,34 +1661,16 @@ namespace umbraco } } - private static void TraceInfo(string category, string message, bool excludeProfiling = false) + private static void TraceInfo(string category, string message) { if (HttpContext.Current != null) - HttpContext.Current.Trace.Write(category, message); - - //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(message)) - { - } - } + HttpContext.Current.Trace.Write(category, message); } - private static void TraceWarn(string category, string message, bool excludeProfiling = false) + private static void TraceWarn(string category, string message) { if (HttpContext.Current != null) HttpContext.Current.Trace.Warn(category, message); - - //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(message)) - { - } - } } private static void TraceWarn(string category, string message, Exception ex, bool excludeProfiling = false) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs index f951bc13db..341009f024 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs @@ -134,7 +134,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 (ProfilerResolver.Current.Profiler.Step(string.Format("Item: {0}", item.Field))) { ParseMacros(item); } @@ -152,7 +152,7 @@ namespace umbraco.presentation.templateControls string elementText = GetFieldContents(item); - using (ProfilerResolver.Current.Profiler.Step("Parsing Macros")) + using (ProfilerResolver.Current.Profiler.Step("Parsing Macros")) { MacroTagParser.ParseMacros(