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:
It is also possible to view the data traced in previous HTTP requests:
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
- Run the following commands in the Package Manager Console window:
Install-Package MiniProfiler.AspNetCore.Mvc
Install-Package DotVVM.Tracing.MiniProfiler.AspNetCore
- Next, you can register the MiniProfiler integration into DotVVM request tracing in the
IDotvvmServiceConfigurator
this way:
public void ConfigureServices(IDotvvmServiceCollection options)
{
options.AddMiniProfilerEventTracing();
}
- As the last step, you need to add the MiniProfiler services in the
ConfigureServices
method and the Miniprofiler middleware beforeapp.UseDotVVM<DotvvmStartup>()
:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddMemoryCache();
services.AddMiniProfiler(options =>
{
options.RouteBasePath = "/profiler";
});
...
}
public void Configure(IApplicationBuilder app)
{
...
app.UseMiniProfiler();
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
- 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
- Next, you can register the MiniProfiler integration into DotVVM request tracing in the
IDotvvmServiceConfigurator
this way:
public void ConfigureServices(IDotvvmServiceCollection 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.