MiniProfiler for .NET

repository·main·Indexed 25 days ago

https://github.com/miniprofiler/dotnet

A performance profiling tool for .NET applications, including ASP.NET, ASP.NET Core, and ASP.NET MVC, designed to help developers identify bottlenecks in code and database queries. It provides integration for Entity Framework Core, Entity Framework 6, and various database providers such as SQL Server, PostgreSQL, MySQL, SQLite, MongoDB, and Redis. The tool uses a hierarchical JSON structure to represent profiling data, including server-side timing trees and browser-side client timings.

Tokens
11.2K
Snippets
27
Records
60
Agent score
84%

What's inside MiniProfiler for .NET

  1. Overview of MiniProfiler for .NET

    main
    MiniProfiler for .NET is a profiling tool designed for ASP.NET, ASP.NET Core, ASP.NET MVC, and general .NET applications. It allows developers to monitor and profile application performance. The project is part of the .NET Foundation.
  2. Install MiniProfiler for .NET Core Console Applications

    main

    To use MiniProfiler in a .NET Core Console application, you must install the MiniProfiler.AspNetCore NuGet package, as there is no dedicated package for standalone Console applications. This package includes all necessary dependencies.

    Install-Package MiniProfiler.AspNetCore -IncludePrerelease
  3. Configure persistent storage for MiniProfiler results

    main

    By default, MiniProfiler stores results in memory. To persist results in a database, install the appropriate provider package and assign it to MiniProfiler.Settings.Storage.

    Example: Using SQL Server

    1. Install the MiniProfiler.Providers.SqlServer NuGet package.
    2. Configure the storage in your application startup code:
    MiniProfiler.Settings.Storage = new SqlServerStorage(ConnectionString);
  4. Profile Entity Framework Core with MiniProfiler

    main

    To profile Entity Framework Core queries using MiniProfiler, you must install the MiniProfiler.EntityFrameworkCore NuGet package and register it in your application's service configuration. This allows MiniProfiler to intercept and record EF Core database commands.

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMiniProfiler()
                .AddEntityFramework();
    }
  5. Install MiniProfiler for ASP.NET Core

    main

    To use MiniProfiler in an ASP.NET Core application, install the MiniProfiler.AspNetCore.Mvc NuGet package. This package includes all necessary dependencies.

    You can install it via the NuGet UI or using the Package Manager Console.

    Install-Package MiniProfiler.AspNetCore.Mvc -IncludePrerelease
  6. Verify minimum requirements for MiniProfiler v4

    main

    To use MiniProfiler v4, your project must meet the following minimum requirements:

    • Framework: .NET 4.6.1 or above, or .NET Standard 1.5 or above.
    • Note: .NET 4.6.1+ is strictly required to support the async features implemented in version 4.

    If your environment is older than .NET 4.6.1, you must use MiniProfiler v3.x.

  7. Install MiniProfiler.Mvc5 for ASP.NET

    main

    To use MiniProfiler in an ASP.NET MVC 5 application, install the MiniProfiler.Mvc5 NuGet package. This package includes all necessary dependencies.

    You can install it via the NuGet UI or using the Package Manager Console:

    Install-Package MiniProfiler.Mvc5 -IncludePrerelease
  8. Install MiniProfiler for .NET Console Applications

    main

    To use MiniProfiler in a .NET Console application, install the MiniProfiler NuGet package. This package includes all necessary dependencies.

    You can install it via the NuGet UI or using the Package Manager Console.

    Install-Package MiniProfiler -IncludePrerelease
  9. Select the correct MiniProfiler NuGet package for your framework

    main

    MiniProfiler is modular. Choose the package that matches your application type:

    ASP.NET Core (.NET Standard 2.0+)

    • Core functionality: MiniProfiler.AspNetCore
    • MVC Integration: MiniProfiler.AspNetCore.Mvc

    ASP.NET Full Framework

    • Core functionality: MiniProfiler
    • MVC 5 Integration: MiniProfiler.Mvc5
  10. Initialize MiniProfiler for Entity Framework 6

    main

    To enable profiling, you must call MiniProfilerEF6.Initialize() in your application startup logic. This must be called before any Entity Framework operations occur in your application. Ensure you include the StackExchange.Profiling.EntityFramework6 namespace.

    using StackExchange.Profiling.EntityFramework6;
    
    // ...
    
    protected void Application_Start()
    {
        MiniProfilerEF6.Initialize();
    }