DOT

VVM

 DOCS

Version: |

MiniProfiler

This feature is available in DotVVM 1.1.5 and higher.

MiniProfiler is a library and UI for profiling your application. By letting you see where your time is spent, which queries are run, and any other custom timings you want to add. It helps you debug issues and optimize performance.

MiniProfiler was designed by the team at Stack Overflow and is extensively used in production by their team.

DotVVM supports this library and tracks some additional metrics which it collects during the processing of an HTTP request.

You can display the collected DotVVM metrics by adding the MiniProfiler Widget to a DOTHTML page:

DotVVM metrics in MiniProfiler

It is also possible to view the data traced in previous HTTP requests:

List of traced HTTP requests with details

MiniProfiler is capable of profiling other 3rd party services, e.g. Entity Framework, Entity Framework Core and Redis.

Getting Started

MiniProfiler installation and configuration differs for ASP.NET Core and OWIN. You can find the details for extended configuration in the MiniProfiler documentation.

For both ASP.NET Core and OWIN, you can use the MiniProfilerWidget, which is a DotVVM control with many options like MaxTraces, Position, StartHidden etc.:

    <dot:MiniProfilerWidget Position="Right" ShowTrivial="true" StartHidden="true" />

You can easily profile your code. It can look like this (check Profile Code section in MiniProfiler documentation):

using (MiniProfiler.Current.Step("GetOrder"))
{
    return orderRepository.Get();
}

ASP.NET Core

Be aware that MiniProfiler for ASP.NET Core is currently in alpha pre-release version.

  1. Run the following commands in the Package Manager Console window:
Install-Package MiniProfiler.AspNetCore -IncludePrerelease
Install-Package DotVVM.Tracing.MiniProfiler.AspNetCore
  1. Next, you can register the MiniProfiler integration into DotVVM request tracing in the ConfigureServices method this way:
services.AddDotVVM(options =>
{
    options.AddMiniProfilerEventTracing();
});
  1. As the last step, you need to add the MiniProfiler middleware before app.UseDotVVM<DotvvmStartup>():
public void Configure(IApplicationBuilder app, IMemoryCache cache)
{
    ...

    app.UseMiniProfiler(new MiniProfilerOptions
    {
        // Path to use for profiler URLs
        RouteBasePath = "~/profiler",

        // (Optional) Control storage
        Storage = new MemoryCacheStorage(cache, TimeSpan.FromMinutes(60)),
    });
    
    app.UseDotVVM<DotvvmStartup>();
    ...
}

To see it in action, you can simply navigate to ~/profiler/results-index and view profiled HTTP requests.

We have a sample application to show how MiniProfiler can be used with ASP.NET Core.


OWIN

  1. Either use the NuGet UI to install DotVVM.Tracing.MiniProfiler.Owin, or use the following commands in the Package Manager Console window:
Install-Package DotVVM.Tracing.MiniProfiler.Owin
  1. Register the DotVVM request tracing in the ConfigureServices method this way:
var dotvvmConfiguration = app.UseDotVVM<DotvvmStartup>(applicationPhysicalPath, options: options =>
{
    options.AddMiniProfilerEventTracing();
});

To see it in action, you can simply navigate to ~/mini-profiler-resources/results-index and view profiled HTTP requests.

You can change MiniProfiler default setting as you would do without DotVVM integration, for example:

StackExchange.Profiling.MiniProfiler.Settings.RouteBasePath = "~/profiler";
StackExchange.Profiling.MiniProfiler.Settings.Results_List_Authorize = (r) => true;

We have a sample application to show how MiniProfiler can be used with Owin.

Next Chapter



Suggestions


Help & Contribute

The documentation is maintained on GitHub.
We'll be happy if you edit the page and create a pull request.

Send message