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, MiniProfiler helps you debug issues and optimize performance.
Edit your Startup.cs to add the middleware and configure options:
1 2 3 4 5 6 7 8 9 10 11 12
// Startup.ConfigureServices
publicvoidConfigureServices(IServiceCollection services) { // The services.AddMemoryCache(); code is required // There is a bug in MiniProfiler, if we have not configured MemoryCache, it will fail. services.AddMemoryCache(); // HERE services.AddMiniProfiler(options => options.RouteBasePath = "/profiler");
services.AddControllers(); }
Once, you configure the RouteBasePath property, We are able access to
/profiler/results-index: Get list of all requests.
/profiler/results: Get the current request.
/profiler/results-list: Get list of all requests as JSON.
Next we need add the MiniProfiler middleware, You can do like this.
public IActionResult Put([FromRoute]int id, [FromBody]WeatherForecast weatherForecast) { // HERE using (MiniProfiler.Current.Step("PUT method for WeatherForecast controller")) { WeatherForecast weatherForecastById = null; using (MiniProfiler.Current.Step("Getting Weather Forecase for the Id")) { weatherForecastById = GetWeatherForecast(id); }
if (weatherForecastById == null) { return NotFound(); }
if (weatherForecastById.Id != id) { return BadRequest(); } using (MiniProfiler.Current.Step("Updating the Data")) { _databaseContext.Entry(weatherForecast).State = EntityState.Modified; _databaseContext.SaveChanges(); } return NoContent(); } }
Entity Framework Core
Hooking up profiling to Entity Framework Core is easy to do: