Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Zero cost(ish) diagnositcs when disabled #8349

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class ControllerActionInvoker : ResourceInvoker, IActionInvoker

internal ControllerActionInvoker(
ILogger logger,
DiagnosticSource diagnosticSource,
DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper,
ControllerContext controllerContext,
ControllerActionInvokerCacheEntry cacheEntry,
IFilterMetadata[] filters)
: base(diagnosticSource, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
: base(diagnosticListener, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
{
if (cacheEntry == null)
{
Expand Down Expand Up @@ -115,7 +115,7 @@ private Task Next(ref State next, ref Scope scope, ref object state, ref bool is
var filter = (IAsyncActionFilter)state;
var actionExecutingContext = _actionExecutingContext;

_diagnosticSource.BeforeOnActionExecution(actionExecutingContext, filter);
_diagnosticListener.BeforeOnActionExecution(actionExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter,
nameof(IAsyncActionFilter.OnActionExecutionAsync),
Expand Down Expand Up @@ -153,7 +153,7 @@ private Task Next(ref State next, ref Scope scope, ref object state, ref bool is
};
}

_diagnosticSource.AfterOnActionExecution(_actionExecutedContext, filter);
_diagnosticListener.AfterOnActionExecution(_actionExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter,
nameof(IAsyncActionFilter.OnActionExecutionAsync),
Expand All @@ -170,15 +170,15 @@ private Task Next(ref State next, ref Scope scope, ref object state, ref bool is
var filter = (IActionFilter)state;
var actionExecutingContext = _actionExecutingContext;

_diagnosticSource.BeforeOnActionExecuting(actionExecutingContext, filter);
_diagnosticListener.BeforeOnActionExecuting(actionExecutingContext, filter);
_logger.BeforeExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuting),
filter);

filter.OnActionExecuting(actionExecutingContext);

_diagnosticSource.AfterOnActionExecuting(actionExecutingContext, filter);
_diagnosticListener.AfterOnActionExecuting(actionExecutingContext, filter);
_logger.AfterExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuting),
Expand Down Expand Up @@ -220,15 +220,15 @@ private Task Next(ref State next, ref Scope scope, ref object state, ref bool is
var filter = (IActionFilter)state;
var actionExecutedContext = _actionExecutedContext;

_diagnosticSource.BeforeOnActionExecuted(actionExecutedContext, filter);
_diagnosticListener.BeforeOnActionExecuted(actionExecutedContext, filter);
_logger.BeforeExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuted),
filter);

filter.OnActionExecuted(actionExecutedContext);

_diagnosticSource.AfterOnActionExecuted(actionExecutedContext, filter);
_diagnosticListener.AfterOnActionExecuted(actionExecutedContext, filter);
_logger.AfterExecutingMethodOnFilter(
MvcCoreLoggerExtensions.ActionFilter,
nameof(IActionFilter.OnActionExecuted),
Expand Down Expand Up @@ -336,13 +336,13 @@ private async Task InvokeActionMethodAsync()
var actionMethodExecutor = _cacheEntry.ActionMethodExecutor;
var orderedArguments = PrepareArguments(arguments, objectMethodExecutor);

var diagnosticSource = _diagnosticSource;
var diagnosticListener = _diagnosticListener;
var logger = _logger;

IActionResult result = null;
try
{
diagnosticSource.BeforeActionMethod(
diagnosticListener.BeforeActionMethod(
controllerContext,
arguments,
controller);
Expand All @@ -363,7 +363,7 @@ private async Task InvokeActionMethodAsync()
}
finally
{
diagnosticSource.AfterActionMethod(
diagnosticListener.AfterActionMethod(
controllerContext,
arguments,
controllerContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public class ControllerActionInvokerProvider : IActionInvokerProvider
private readonly IReadOnlyList<IValueProviderFactory> _valueProviderFactories;
private readonly int _maxModelValidationErrors;
private readonly ILogger _logger;
private readonly DiagnosticSource _diagnosticSource;
private readonly DiagnosticListener _diagnosticListener;
private readonly IActionResultTypeMapper _mapper;

public ControllerActionInvokerProvider(
ControllerActionInvokerCache controllerActionInvokerCache,
IOptions<MvcOptions> optionsAccessor,
ILoggerFactory loggerFactory,
DiagnosticSource diagnosticSource,
DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper)
{
_controllerActionInvokerCache = controllerActionInvokerCache;
_valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
_maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors;
_logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
_diagnosticSource = diagnosticSource;
_diagnosticListener = diagnosticListener;
_mapper = mapper;
}

Expand All @@ -59,7 +59,7 @@ public void OnProvidersExecuting(ActionInvokerProviderContext context)

var invoker = new ControllerActionInvoker(
_logger,
_diagnosticSource,
_diagnosticListener,
_mapper,
controllerContext,
cacheResult.cacheEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ public class MvcAttributeRouteHandler : IRouter
private readonly IActionInvokerFactory _actionInvokerFactory;
private readonly IActionSelector _actionSelector;
private readonly ILogger _logger;
private DiagnosticSource _diagnosticSource;
private DiagnosticListener _diagnosticListener;

public MvcAttributeRouteHandler(
IActionInvokerFactory actionInvokerFactory,
IActionSelector actionSelector,
DiagnosticSource diagnosticSource,
DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory)
: this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null)
: this(actionInvokerFactory, actionSelector, diagnosticListener, loggerFactory, actionContextAccessor: null)
{
}

public MvcAttributeRouteHandler(
IActionInvokerFactory actionInvokerFactory,
IActionSelector actionSelector,
DiagnosticSource diagnosticSource,
DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory,
IActionContextAccessor actionContextAccessor)
{
Expand All @@ -42,7 +42,7 @@ public MvcAttributeRouteHandler(

_actionInvokerFactory = actionInvokerFactory;
_actionSelector = actionSelector;
_diagnosticSource = diagnosticSource;
_diagnosticListener = diagnosticListener;
_logger = loggerFactory.CreateLogger<MvcAttributeRouteHandler>();
}

Expand Down
Loading