I want to use MiniProfiler to call a function once a set time limit has gone by. This is how MiniProfiler is set up. After that I've included the profiling script which we use to profile whatever needs profiling. My problem is to create some sort of middleware that can intercept this "MiniProfiler.Current.Step" call when the timing is greater than 1000ms.
app.UseMiniProfiler(new MiniProfilerOptions
{
ResultsAuthorize = x => false,
ResultsListAuthorize = x => false,
Storage = new SqlServerStorage(Configuration.GetConnectionString("MiniProfiler"))
});
MiniProfilerEF6.Initialize();
app.Use(async (context, next) =>
{
MiniProfiler.Current.Name = context.Request.GetDisplayUrl();
await next.Invoke();
});
/// <summary>
/// The main profiler, useage:
/// using(this.Profile("more context"))
/// {
/// Do things that needs profiling, and you may nest it.
/// }
/// </summary>
/// <param name="profiled">The object that is profiled</param>
/// <param name="subSectionName">More context for the output result</param>
/// <param name="methodName">Possible override for the method name called</param>
/// <param name="profiledTypeName">Possible override for the profiled type</param>
/// <returns>An IDisposable, to help with scoping</returns>
public static IDisposable Profile(this object profiled,
string subSectionName = null,
[CallerMemberName] string methodName = "",
string profiledTypeName = null)
{
if (profiled == null)
throw new ArgumentNullException(nameof(profiled));
var profiledType = profiledTypeName ?? profiled.GetType().Name;
return Profile(methodName, profiledType, subSectionName);
}
public static IDisposable Profile(string methodName,
string profiledTypeName,
string subSectionName = null)
{
var name = subSectionName != null
? $"{profiledTypeName}.{methodName}:{subSectionName}"
: $"{profiledTypeName}.{methodName}";
return MiniProfiler.Current?.Step(name);
}