### Install ExtJS Type Definitions Source: https://github.com/miniprofiler/dotnet/blob/main/src/MiniProfiler.Shared/ui/lib/node_modules/@types/extjs/README.md Install the ExtJS type definitions package using npm. ```bash npm install --save @types/extjs ``` -------------------------------- ### Install MiniProfiler NuGet Package Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNet.md Use the Package Manager Console to install the MiniProfiler.Mvc5 NuGet package. ```powershell Install-Package MiniProfiler.Mvc5 -IncludePrerelease ``` -------------------------------- ### Install MiniProfiler NuGet Package Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNetCore.md Use this Package Manager Console command to install the MiniProfiler.AspNetCore.Mvc NuGet package, which includes all required dependencies. ```powershell Install-Package MiniProfiler.AspNetCore.Mvc -IncludePrerelease ``` -------------------------------- ### Install MiniProfiler NuGet Package Source: https://github.com/miniprofiler/dotnet/blob/main/docs/ConsoleDotNet.md Use this command in the Package Manager Console to install the MiniProfiler NuGet package, including pre-release versions. ```powershell Install-Package MiniProfiler -IncludePrerelease ``` -------------------------------- ### Configure MiniProfiler in Global.asax.cs Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNet.md Configure MiniProfiler options in the Application_Start method and start profiling requests in Application_BeginRequest. Ensure to stop the profiler in Application_EndRequest. ```csharp protected void Application_Start() { MiniProfiler.Configure(new MiniProfilerOptions { // Sets up the route to use for MiniProfiler resources: // Here, ~/profiler is used for things like /profiler/mini-profiler-includes.js RouteBasePath = "~/profiler", // Example of using SQLite storage instead Storage = new SqliteMiniProfilerStorage(ConnectionString), // Different RDBMS have different ways of declaring sql parameters - SQLite can understand inline sql parameters just fine. // By default, sql parameters will be displayed. //SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(), // These settings are optional and all have defaults, any matching setting specified in .RenderIncludes() will // override the application-wide defaults specified here, for example if you had both: // PopupRenderPosition = RenderPosition.Right; // and in the page: // @MiniProfiler.Current.RenderIncludes(position: RenderPosition.Left) // ...then the position would be on the left on that page, and on the right (the application default) for anywhere that doesn't // specified position in the .RenderIncludes() call. PopupRenderPosition = RenderPosition.Right, // defaults to left PopupMaxTracesToShow = 10, // defaults to 15 PopupDecimalPlaces = 1, // defaults to 2 ColorScheme = ColorScheme.Auto, // defaults to light // ResultsAuthorize (optional - open to all by default): // because profiler results can contain sensitive data (e.g. sql queries with parameter values displayed), we // can define a function that will authorize clients to see the JSON or full page results. // we use it on http://stackoverflow.com to check that the request cookies belong to a valid developer. ResultsAuthorize = request => request.IsLocal, // ResultsListAuthorize (optional - open to all by default) // the list of all sessions in the store is restricted by default, you must return true to allow it ResultsListAuthorize = request => { // you may implement this if you need to restrict visibility of profiling lists on a per request basis return true; // all requests are legit in this example }, // Stack trace settings StackMaxLength = 256, // default is 120 characters // (Optional) You can disable "Connection Open()", "Connection Close()" (and async variant) tracking. // (defaults to true, and connection opening/closing is tracked) TrackConnectionOpenClose = true } // Optional settings to control the stack trace output in the details pane, examples: .ExcludeType("SessionFactory") // Ignore any class with the name of SessionFactory) .ExcludeAssembly("NHibernate") // Ignore any assembly named NHibernate .ExcludeMethod("Flush") // Ignore any method with the name of Flush .AddViewProfiling() // Add MVC view profiling (you want this) // If using EntityFrameworkCore, here's where it'd go. // .AddEntityFramework() // Extension method in the MiniProfiler.EntityFrameworkCore package ); // If we're using EntityFramework 6, here's where it'd go. // This is in the MiniProfiler.EF6 NuGet package. // MiniProfilerEF6.Initialize(); } protected void Application_BeginRequest() { // You can decide whether to profile here, or it can be done in ActionFilters, etc. // We're doing it here so profiling happens ASAP to account for as much time as possible. if (Request.IsLocal) // Example of conditional profiling, you could just call MiniProfiler.StartNew(); { MiniProfiler.StartNew(); } } protected void Application_EndRequest() { MiniProfiler.Current?.Stop(); // Be sure to stop the profiler! } ``` -------------------------------- ### Configure and Start MiniProfiler in Program.cs Source: https://github.com/miniprofiler/dotnet/blob/main/docs/ConsoleDotNetCore.md Integrate MiniProfiler into your .NET Core console application by configuring it and starting a new profiler instance. The `using` statement ensures the profiler is properly disposed. ```csharp public static void Main() { // Default configuration usually works for most, but override, you can call: // MiniProfiler.Configure(new MiniProfilerOptions { ... }); var profiler = MiniProfiler.StartNew("My Profiler Name"); using (profiler.Step("Main Work")) { // Do some work... } } ``` -------------------------------- ### Install MiniProfiler NuGet Package Source: https://github.com/miniprofiler/dotnet/blob/main/docs/ConsoleDotNetCore.md Use this command in the Package Manager Console to install the MiniProfiler.AspNetCore NuGet package, which includes necessary dependencies for .NET Core console applications. ```powershell Install-Package MiniProfiler.AspNetCore -IncludePrerelease ``` -------------------------------- ### Initialize MiniProfiler for Entity Framework 6 Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileEF6.md Call this method once during application startup to enable EF6 profiling. Ensure the MiniProfiler.EF6 NuGet package is installed. ```csharp using StackExchange.Profiling.EntityFramework6; protected void Application_Start() { MiniProfilerEF6.Initialize(); } ``` -------------------------------- ### Configure Services for MiniProfiler Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNetCore.md Register MiniProfiler services and configure various options like route base path, storage, SQL formatting, authorization, and profiling behavior. This setup is optional and defaults can be used by simply calling AddMiniProfiler(). ```csharp public void ConfigureServices(IServiceCollection services) { // ...existing configuration... // Note .AddMiniProfiler() returns a IMiniProfilerBuilder for easy intellisense services.AddMiniProfiler(options => { // All of this is optional. You can simply call .AddMiniProfiler() for all defaults // (Optional) Path to use for profiler URLs, default is /mini-profiler-resources options.RouteBasePath = "/profiler"; // (Optional) Control storage // (default is 30 minutes in MemoryCacheStorage) // Note: MiniProfiler will not work if a SizeLimit is set on MemoryCache! // See: https://github.com/MiniProfiler/dotnet/issues/501 for details (options.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(60); // (Optional) Control which SQL formatter to use, InlineFormatter is the default options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(); // (Optional) To control authorization, you can use the Func options: // (default is everyone can access profilers) options.ResultsAuthorize = request => MyGetUserFunction(request).CanSeeMiniProfiler; options.ResultsListAuthorize = request => MyGetUserFunction(request).CanSeeMiniProfiler; // Or, there are async versions available: options.ResultsAuthorizeAsync = async request => (await MyGetUserFunctionAsync(request)).CanSeeMiniProfiler; options.ResultsListAuthorizeAsync = async request => (await MyGetUserFunctionAsync(request)).CanSeeMiniProfilerLists; // (Optional) To control which requests are profiled, use the Func option: // (default is everything should be profiled) options.ShouldProfile = request => MyShouldThisBeProfiledFunction(request); // (Optional) Profiles are stored under a user ID, function to get it: // (default is null, since above methods don't use it by default) options.UserIdProvider = request => MyGetUserIdFunction(request); // (Optional) Swap out the entire profiler provider, if you want // (default handles async and works fine for almost all applications) options.ProfilerProvider = new MyProfilerProvider(); // (Optional) You can disable "Connection Open()", "Connection Close()" (and async variant) tracking. // (defaults to true, and connection opening/closing is tracked) options.TrackConnectionOpenClose = true; // (Optional) Use something other than the "light" color scheme. // (defaults to "light") options.ColorScheme = StackExchange.Profiling.ColorScheme.Auto; // Optionally change the number of decimal places shown for millisecond timings. // (defaults to 2) options.PopupDecimalPlaces = 1; // The below are newer options, available in .NET Core 3.0 and above: // (Optional) You can disable MVC filter profiling // (defaults to true, and filters are profiled) options.EnableMvcFilterProfiling = true; // ...or only save filters that take over a certain millisecond duration (including their children) // (defaults to null, and all filters are profiled) // options.MvcFilterMinimumSaveMs = 1.0m; // (Optional) You can disable MVC view profiling // (defaults to true, and views are profiled) options.EnableMvcViewProfiling = true; // ...or only save views that take over a certain millisecond duration (including their children) // (defaults to null, and all views are profiled) // options.MvcViewMinimumSaveMs = 1.0m; // (Optional) listen to any errors that occur within MiniProfiler itself // options.OnInternalError = e => MyExceptionLogger(e); // (Optional - not recommended) You can enable a heavy debug mode with stacks and tooltips when using memory storage // It has a lot of overhead vs. normal profiling and should only be used with that in mind // (defaults to false, debug/heavy mode is off) //options.EnableDebugMode = true; }); } ``` -------------------------------- ### Profile a Code Section with Step Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileCode.md Use the `.Step()` extension method within a `using` statement to time a specific block of code. The timing starts when the `using` block is entered and stops when it's exited. ```csharp using (MiniProfiler.Current.Step("InitUser")) { var user = User.Get(); user.Init(); } ``` -------------------------------- ### Client Timings JSON Example Source: https://github.com/miniprofiler/dotnet/blob/main/src/MiniProfiler.Shared/ui/README.md This JSON structure represents client-side timing data captured by MiniProfiler, including network request timings and event timings like DOMContentLoaded and Load events. ```json { "Id": "779f22e9-2c1d-45ae-2677-ae5f34c3f39f", "Name": "goapp.Main", "Started": 1368211203000, "MachineName": "mjibson-mbp.local", "Root": { "Id": "4362ec49-b625-4184-2bb4-95d904cb466d", "Name": "GET http://localhost:8080/", "DurationMilliseconds": 5.964, "StartMilliseconds": 0, "Children": null, "CustomTimings": { "memcache": [ { "Id": "83a9d0a9-ed37-4e9d-27cd-4f8813ac6408", "ExecuteType": "Get", "CommandString": "Get\n\nkey:"agtkZXZ-Z28tcmVhZHIcCxIBVSIVMTg1ODA0NzY0MjIwMTM5MTI0MTE4DA" for_cas:true ", "StackTraceSnippet": "Call Call GetMulti Get includes Main", "StartMilliseconds": 0.978, "DurationMilliseconds": 2.323, "FirstFetchDurationMilliseconds": 0 } ] } }, "ClientTimings": { "RedirectCount": 0, "Timings": [ { "Name": "Connect", "Start": 2, "Duration": 0 }, { "Name": "Request", "Start": 2, "Duration": -1 }, { "Name": "Response", "Start": 17, "Duration": 1 }, { "Name": "Unload Event", "Start": 18, "Duration": 0 }, { "Name": "Dom Content Loaded Event", "Start": 183, "Duration": 67 }, { "Name": "Load Event", "Start": 320, "Duration": 1 } ] }, "DurationMilliseconds": 5.964, "CustomLinks": { "appstats": "http://localhost:8080/_ah/stats/details?time=511483000" } } ``` -------------------------------- ### MiniProfiler JSON Output Example Source: https://github.com/miniprofiler/dotnet/blob/main/src/MiniProfiler.Shared/ui/README.md This JSON represents a complete profiling session, including the root timing, child timings, custom timings, and custom links. It is typically generated by the MiniProfiler backend and consumed by the UI. ```json { "Id": "7659f15a-6c47-4731-2854-67c6f2b92a3f", "Name": "goapp.ListFeeds", "Started": 1368211081000, "MachineName": "mjibson-mbp.local", "Root": { "Id": "0ee41f07-c4a7-44f9-2b81-b300cba7e856", "Name": "GET http://localhost:8080/user/list-feeds", "DurationMilliseconds": 17.595, "StartMilliseconds": 0, "Children": [ { "Id": "9f6660ee-286b-4d2a-2d1d-90d2dcbfb4f3", "Name": "unmarshal user data", "DurationMilliseconds": 0.03399999999999981, "StartMilliseconds": 5.828, "Children": null, "CustomTimings": null }, { "Id": "8f35fc4b-57dd-4455-22d4-e25fb27a13c8", "Name": "fetch feeds", "DurationMilliseconds": 2.6899999999999995, "StartMilliseconds": 5.865, "Children": null, "CustomTimings": { "memcache": [ { "Id": "7345c3d3-6fd0-4417-21e9-1b3b2014b18e", "ExecuteType": "Get", "CommandString": "Get\n\nkey:"agtkZXZ-Z28tcmVhZHIlCxIBRiIeaHR0cDovL21hdHRqaWJzb24uY29tL2F0b20ueG1sDA" for_cas:true ", "StackTraceSnippet": "Call Call GetMulti Step ListFeeds", "StartMilliseconds": 6.221, "DurationMilliseconds": 1.442, "FirstFetchDurationMilliseconds": 0 } ] } }, { "Id": "62078d64-7f70-4194-2a3f-d778d1844a35", "Name": "feed fetch + wait", "DurationMilliseconds": 8.904000000000002, "StartMilliseconds": 8.571, "Children": null, "CustomTimings": { "datastore_v3": [ { "Id": "decc860e-be66-4274-2c9e-bf63380c59c0", "ExecuteType": "RunQuery", "CommandString": "RunQuery\n\napp:"dev~go-read" kind:"S" ancestor:<app:"dev~go-read" path:<Element{type:"F" name:"http://mattjibson.com/atom.xml" } > > Filter{op:GREATER_THAN prope...", "StackTraceSnippet": "Call Call GetAll", "StartMilliseconds": 8.963, "DurationMilliseconds": 5.435, "FirstFetchDurationMilliseconds": 0 } ], "memcache": [ { "Id": "d8ccb046-f3e8-41cc-22a6-fee03497f4fb", "ExecuteType": "Get", "CommandString": "Get\n\nfor_cas:true ", "StackTraceSnippet": "Call Call GetMulti", "StartMilliseconds": 14.921, "DurationMilliseconds": 2.486, "FirstFetchDurationMilliseconds": 0 } ] } }, { "Id": "92011933-a3d9-40e8-23ff-799492f7530a", "Name": "json marshal", "DurationMilliseconds": 0.06099999999999994, "StartMilliseconds": 17.529, "Children": null, "CustomTimings": null } ], "CustomTimings": { "memcache": [ { "Id": "e5a454d0-d434-4c97-29b7-1c383a8711d5", "ExecuteType": "Get", "CommandString": "Get\n\nkey:"agtkZXZ-Z28tcmVhZHIcCxIBVSIVMTg1ODA0NzY0MjIwMTM5MTI0MTE4DA" key:"agtkZXZ-Z28tcmVhZHIoCxIBVSIVMTg1ODA0NzY0MjIwMTM5MTI0MTE4DAsSAlVEIgRkYXRhDA" for_...", "StackTraceSnippet": "Call Call GetMulti ListFeeds", "StartMilliseconds": 0.535, "DurationMilliseconds": 4.032, "FirstFetchDurationMilliseconds": 0 } ] } }, "ClientTimings": null, "DurationMilliseconds": 17.595, "CustomLinks": { "appstats": "http://localhost:8080/_ah/stats/details?time=542064000" } } ``` -------------------------------- ### Initialize MiniProfiler for EF6 Source: https://github.com/miniprofiler/dotnet/blob/main/src/MiniProfiler.EF6/README.md Call this method in your application startup logic before any EF usage. Ensure the necessary using directive is present. ```csharp using StackExchange.Profiling.EntityFramework6; ... protected void Application_Start() { MiniProfilerEF6.Initialize(); } ``` -------------------------------- ### Profile SQL Server Connection Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileSql.md Wrap a `SqlConnection` with `ProfiledDbConnection` to enable SQL Server profiling. Ensure `MiniProfiler.Current` is available. ```csharp public DbConnection GetConnection() { DbConnection connection = new System.Data.SqlClient.SqlConnection("..."); return new StackExchange.Profiling.Data.ProfiledDbConnection(connection, MiniProfiler.Current); } ``` -------------------------------- ### Profile SQLite Connection Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileSql.md Wrap a `SQLiteConnection` with `ProfiledDbConnection` for SQLite profiling. Ensure `MiniProfiler.Current` is available. ```csharp public static DbConnection GetConnection() { DbConnection connection = new System.Data.SQLite.SQLiteConnection("Data Source=:memory:"); return new StackExchange.Profiling.Data.ProfiledDbConnection(connection, MiniProfiler.Current); } ``` -------------------------------- ### Configure Web.config for MiniProfiler Resources Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNet.md Edit your Web.config file to serve MiniProfiler resources. Ensure the 'path' attribute matches the 'RouteBasePath' setting in your MiniProfiler configuration. ```xml ``` -------------------------------- ### Configure Entity Framework Core Profiling Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileEFCore.md Add Entity Framework Core profiling support by calling AddEntityFramework() after AddMiniProfiler() in your ConfigureServices method. ```csharp public void ConfigureServices(IServiceCollection services) { services.AddMiniProfiler() .AddEntityFramework(); } ``` -------------------------------- ### Configure SQL Server Storage Source: https://github.com/miniprofiler/dotnet/blob/main/docs/NuGet.md To store MiniProfiler results in SQL Server, reference the MiniProfiler.Providers.SqlServer NuGet package and configure the storage provider in options. ```csharp MiniProfiler.Settings.Storage = new SqlServerStorage(ConnectionString); ``` -------------------------------- ### Configure Middleware for MiniProfiler Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNetCore.md Add the MiniProfiler middleware to the application pipeline. This call must precede the call to app.UseMvc. ```csharp public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IMemoryCache cache) { // ...existing configuration... app.UseMiniProfiler(); // The call to app.UseMiniProfiler must come before the call to app.UseMvc app.UseMvc(routes => { // ... }); } ``` -------------------------------- ### Profile Custom Operations with CustomTiming Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileCode.md Employ `.CustomTiming()` within a `using` statement to profile operations categorized by type (e.g., 'http', 'sql'). This is useful for tracking external service calls or database queries. Provide a category, command string, and optionally an execute type. ```csharp var url = "https://google.com"; using (profiler.CustomTiming("http", "GET " + url)) { var client = new WebClient(); var reply = client.DownloadString(url); } ``` -------------------------------- ### Render MiniProfiler Results as Plain Text Source: https://github.com/miniprofiler/dotnet/blob/main/docs/ConsoleDotNetCore.md Output the profiling results as plain text to the console. You can render the results for a specific profiler instance or the currently active one. ```csharp Console.WriteLine(profiler.RenderPlainText()); // or for the active profiler: Console.WriteLine(MiniProfiler.Current.RenderPlainText()); ``` -------------------------------- ### Inline Profiling with .Inline() Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileCode.md Use .Inline() for profiling simple code blocks without requiring a 'using' statement. It accepts a Func that returns a value. ```csharp var url = "https://stackoverflow.com"; var html = MiniProfiler.Current.Inline(() => new WebClient().DownloadString(url), "Fetch Stack Overflow"); ``` -------------------------------- ### MyGet Feed URLs Source: https://github.com/miniprofiler/dotnet/blob/main/docs/NuGet.md Provides URLs for accessing early access Alpha and Beta builds of MiniProfiler via MyGet feeds. ```plaintext https://www.myget.org/F/miniprofiler/api/v3/index.json ``` ```plaintext https://www.myget.org/F/miniprofiler/api/v2 ``` -------------------------------- ### Include MiniProfiler Script Tag Helper Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNetCore.md Use the `` tag helper in your views to automatically include the necessary JavaScript and CSS for MiniProfiler. This tag helper supports various configuration options. ```html ``` -------------------------------- ### Add MiniProfiler Tag Helpers Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNetCore.md Include the necessary Tag Helper directive in your `_ViewImports.cshtml` file to enable MiniProfiler's view integration. ```cshtml @using StackExchange.Profiling @addTagHelper *, MiniProfiler.AspNetCore.Mvc ``` -------------------------------- ### Profile Code Section with Profile Tag Helper Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNetCore.md Utilize the `` tag helper within your Razor views to profile specific sections of code. This is useful for identifying performance bottlenecks in view rendering. ```html @{ SomethingExpensive(); } Hello Mars! ``` -------------------------------- ### Render MiniProfiler Includes in Layout Source: https://github.com/miniprofiler/dotnet/blob/main/docs/AspDotNet.md Include the MiniProfiler rendering tag in your main layout file to display profiling information. ```cshtml @using StackExchange.Profiling ... @(MiniProfiler.Current?.RenderIncludes()) ``` -------------------------------- ### Disabling Profiling with .Ignore() Source: https://github.com/miniprofiler/dotnet/blob/main/docs/HowTo/ProfileCode.md Use .Ignore() within a 'using' statement to disable profiling for specific code sections. This is useful for excluding libraries or operations that generate excessive profiling data. ```csharp using (MiniProfiler.Current.Ignore()) { // stuff we really don't care about - maybe a library that does a lot of profiling, etc. // in here, no timings would be recorded } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.