// Copyright (c) Umbraco.
// See LICENSE for more details.
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Logging;
namespace Umbraco.Cms.Web.Common.Profiler
{
///
/// Initialized the web profiling. Ensures the boot process profiling is stopped.
///
public class InitializeWebProfiling : INotificationHandler
{
private readonly bool _profile;
private readonly WebProfiler _profiler;
///
/// Initializes a new instance of the class.
///
public InitializeWebProfiling(IProfiler profiler, ILogger logger)
{
_profile = true;
// although registered in UmbracoBuilderExtensions.AddUmbraco, ensure that we have not
// been replaced by another component, and we are still "the" profiler
_profiler = profiler as WebProfiler;
if (_profiler != null)
{
return;
}
// if VoidProfiler was registered, let it be known
if (profiler is NoopProfiler)
{
logger.LogInformation(
"Profiler is VoidProfiler, not profiling (must run debug mode to profile).");
}
_profile = false;
}
///
public void Handle(UmbracoApplicationStarting notification)
{
if (_profile)
{
// Stop the profiling of the booting process
_profiler.StopBoot();
}
}
}
}