Step-by-step MVC Mini Profiler without embedded applications

We model a complex system based on complex entity relationships in Dynamics CRM 4.0

Due to the nature of the development, we had to implement a repository style template and have many different providers that are related to each other.

What I really want to do is profile their constructors and various lazy getters, but I want to model this at the top level.

The problem, of course, is Scope - if I close the constructor in the using block, it will not be available for anything else. If I extend the used block so that everything that refers to the object that I am profiling falls into the scope, then the profiler does not just profile the constructor, but defines everything else.

Similarly, there is a level of nesting. If I insert the data correctly, then the code becomes unreadable.

I looked at Profiler.Inline, but that does not serve my purposes.

What I really would like to do is:

ref = Profiler.StartStep("Creating CRM Model"); //Do horrible CRM work var myNewHorribleObject = CRM.ModelHorribleStuff(...); Profiler.StopStep(ref); ref = Profiler.StartStep("How long does it take to get X"); var data = Repository.GetSomething(myNewHorribleObject.SomeId); Profiler.StopStep(ref); ref = Profiler.StartStep("How long does it take to get Y"); var newData = Repository.GetSomethingElse(myNewHorribleObject.ContextId); Profiler.StopStep(ref); 

It makes sense? Hope I missed something in the Mini Profiler, but I would welcome any suggestions!

I would like to redo the code a bit, but there is no time for this, and while it looks weird, we really have pretty good cyclic complexity.

+6
source share
1 answer

Yes it is possible. Instead of using using just use "MiniProfiler.Current.Step (" blah ")". This will return an object that implements IDisposeable . When this object is actually deleted, this is when the timeouts stop. You can even embed things with using statements, as usual.

Example:

  IDisposable executingStep; executingStep= MiniProfiler.Current.Step("Some code after this"); // do long code Thread.Sleep(100); using (profiler.Step("Step 2313")) { Thread.Sleep(100); } executingStep.Dispose(); 
+7
source

Source: https://habr.com/ru/post/909622/


All Articles