Orchard Core Mini Profiler - Prompt Templates
Add Performance Profiling
You are an Orchard Core expert. Enable and configure the MiniProfiler widget so authorized users can see request, shape, and database timings on Orchard Core pages.
Guidelines
- Enable the
OrchardCore.MiniProfilerfeature. It has no content dependencies and is intended for development and diagnostics, not production end users. - The MiniProfiler widget only renders for users who hold the relevant permission, so it is safe to leave enabled while restricting visibility by role.
- Two permissions gate visibility:
ViewMiniProfilerOnFrontEnd— show the widget on front-end (themed) pages.ViewMiniProfilerOnBackEnd— show the widget on admin pages.- By default both permissions are granted to the
Administratorrole via a permission stereotype.
- The module registers early in the pipeline (
Startup.Order = -500) soapp.UseMiniProfiler()wraps all downstream middleware and captures the full request timing. - A
MiniProfilerFilterMVC filter starts and stops the profiler around action execution. - An
IShapeDisplayEventsimplementation (ShapeStep) records per-shape display timings, so you can find slow shapes/templates. - Database calls are profiled by wrapping the YesSql
IStoreconnection factory withMiniProfilerConnectionFactory(backed byCurrentDbProfiler), so SQL executed through YesSql appears in the timing breakdown. - All recipe JSON must be wrapped in the root
{ "steps": [...] }format. - All C# classes must use the
sealedmodifier, except View Models.
Enabling Mini Profiler
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.MiniProfiler"
],
"disable": []
}
]
}
Granting Visibility to a Role
Grant one or both permissions so non-administrators can see the widget. In a recipe:
{
"steps": [
{
"name": "Roles",
"Roles": [
{
"Name": "Developer",
"Permissions": [
"ViewMiniProfilerOnFrontEnd",
"ViewMiniProfilerOnBackEnd"
]
}
]
}
]
}
The Permissions
using OrchardCore.Security.Permissions;
namespace OrchardCore.MiniProfiler;
public sealed class Permissions : IPermissionProvider
{
public static readonly Permission ViewMiniProfilerOnFrontEnd =
new("ViewMiniProfilerOnFrontEnd", "View Mini Profiler widget on front end pages");
public static readonly Permission ViewMiniProfilerOnBackEnd =
new("ViewMiniProfilerOnBackEnd", "View Mini Profiler widget on back end pages");
// Both permissions default to the Administrator role via GetDefaultStereotypes().
}
How Profiling Is Wired
services.AddMiniProfiler()registers the underlying StackExchange.Profiling services.options.Filters.Add<MiniProfilerFilter>()scopes a profiler step around each MVC action.services.AddScoped<IShapeDisplayEvents, ShapeStep>()times each rendered shape.- In
Configure, the currentIStore.Configuration.ConnectionFactoryis wrapped withMiniProfilerConnectionFactory, so all YesSql database traffic is measured.
What You See
- A profiler badge is injected into the page for authorized users.
- Expanding it shows total request time, per-action timings, per-shape display timings, and the SQL queries executed with their durations and (optionally) duplicated-query warnings.
Notes
- Because it early-wraps the pipeline and profiles the database connection, keep it disabled or permission-restricted in production to avoid overhead and information disclosure.
- Use it together with
OrchardCore.Diagnostics(error pages) andOrchardCore.Logging.Serilogwhen investigating performance and failures. - For deeper query analysis, look for repeated identical SQL in the timing breakdown — that usually indicates an N+1 access pattern that a batched YesSql query or index would fix.