This is the scenario I am facing: I am using MiniProfiler to profile some operations. But it lacks a particular functionality that I will have to use. There is a Settings file MiniProfiler that can let me do some configurations like what to consider for profiling and what not, what to think as slow and what not, etc. But these are global settings and apply to all operations being profiled. What I need is to be able to say something like this:
using (mvcminiprofiler.Step("OperationName", 1200)
{
//some C# code
}
This argument '1200' signifies that this operation is expected to take 1200 ms and do not save it's results to the database if it takes anything less than or equal to 1200 ms. But if it takes more than 1200 ms then save this response time to the data base. So I am basically talking about per operation threshold values.
I am willing to write a wrapper around the MiniProfiler for this but I am not willing to change the mini profiler source code. Actually we have already built a little framework around the mini profiler but we would not like to change its source code. But merely extend it's functionality in some ways.
I just added the following new extension methods to MiniProfiler, available in nuget 3.0.10-beta5 and higher:
MiniProfiler.StepIf(string name decimal minSaveMs, bool includeChildren = false)
MiniProfiler.CustomTimingIf(string category, string commandString, deciml minSaveMs, string executeType = null)
You should be able to use these to do exactly what you are looking to do. In your case, you would use code like this:
using (MiniProfiler.Current.StepIf("Operation Name", 1200)) {
// do your stuff
}
You can use the includeChildren
(defaults to false) to set whether or not to use the time recorded in child profiles when determining whether or not to save this CustomTiming
.
More info in this GitHub Issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With