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.
This commit is contained in:
Shannon Deminick
2013-05-12 18:06:26 -10:00
parent b2fe35695f
commit 09a6cdc8b6
9 changed files with 58 additions and 54 deletions

View File

@@ -0,0 +1,19 @@
using System;
namespace Umbraco.Core.Profiling
{
public static class ProfilerExtensions
{
/// <summary>
/// Writes out a step prefixed with the type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="profiler"></param>
/// <param name="name"></param>
/// <returns></returns>
public static IDisposable Step<T>(this IProfiler profiler, string name)
{
return profiler.Step(string.Format(typeof (T).Name + ", " + name));
}
}
}

View File

@@ -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
/// </summary>
public class WebProfiler : IProfiler
{
private readonly UmbracoApplicationBase _umbracoApplication;
/// <summary>
/// Constructor
/// </summary>
/// <param name="umbracoApplication"></param>
/// <remarks>
/// Binds to application events to enable the MiniProfiler
/// </remarks>
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<WebProfiler>("Cannot start the WebProfiler since the application is running in Medium trust");
}
else
{
app.BeginRequest += UmbracoApplicationBeginRequest;
app.EndRequest += UmbracoApplicationEndRequest;
}
}
/// <summary>

View File

@@ -523,6 +523,7 @@
<Compile Include="Persistence\UnitOfWork\PetaPocoUnitOfWorkProvider.cs" />
<Compile Include="Profiling\IProfiler.cs" />
<Compile Include="Profiling\LogProfiler.cs" />
<Compile Include="Profiling\ProfilerExtensions.cs" />
<Compile Include="Profiling\ProfilerResolver.cs" />
<Compile Include="Profiling\WebProfiler.cs" />
<Compile Include="PropertyEditors\Attributes\PropertyEditorAttribute.cs" />

View File

@@ -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));

View File

@@ -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<UmbracoDefault>("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<UmbracoDefault>("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<UmbracoDefault>("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<UmbracoDefault>("Render"))
{
// do the original rendering

View File

@@ -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;

View File

@@ -98,7 +98,7 @@ namespace umbraco
/// <returns></returns>
private string GetRecursiveValueLegacy(IDictionary elements)
{
using (ProfilerResolver.Current.Profiler.Step("Checking recusively"))
using (ProfilerResolver.Current.Profiler.Step<item>("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<item>("Start parsing " + _fieldName))
{
HttpContext.Current.Trace.Write("item", "Start parsing '" + _fieldName + "'");
if (helper.FindAttribute(attributes, "textIfEmpty") != "" && _fieldContent == "")

View File

@@ -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<macro>(macroInfo))
{
TraceInfo("renderMacro", macroInfo, excludeProfiling: true);
TraceInfo("renderMacro", macroInfo);
StateHelper.SetContextValue(MacrosAddedKey, StateHelper.GetContextValue<int>(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<macro>("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<macro>("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<macro>("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<macro>("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<macro>("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<macro>("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<macro>("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)

View File

@@ -134,7 +134,7 @@ namespace umbraco.presentation.templateControls
/// <param name="item">The item.</param>
public virtual void Load(Item item)
{
using (ProfilerResolver.Current.Profiler.Step(string.Format("Item: {0}", item.Field)))
using (ProfilerResolver.Current.Profiler.Step<ItemRenderer>(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<ItemRenderer>("Parsing Macros"))
{
MacroTagParser.ParseMacros(