mishrsud / mvc-mini-profiler

Automatically exported from code.google.com/p/mvc-mini-profiler
0 stars 0 forks source link

Serialization support for running profiler #34

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I would like to be able to serialize a (running) profiler to send back and 
forth across remote procedure calls. I have the feeling that the 
MiniProfiler.ToJson(profiler) method is not far from this, so I'm hoping that 
this is not a huge ask.

However, the problem is that the Step() method calls the CurrentDuration 
property, which relies upon a (now null) stopwatch member. Would it be possible 
to support this scenario (even if it required me to maintain a local 
mini-fork?).

This is what I'm after:
MiniProfiler.Start();
using (MiniProfiler.Current.Step("Step 1"))
    Thread.Sleep(100);

var json = MiniProfiler.ToJson(MiniProfiler.Current);

MiniProfiler prof = MiniProfiler.FromJson(json);
using (prof.Step("Step 2"))
    Thread.Sleep(100);

MiniProfiler.Stop();

Original issue reported on code.google.com by tsi...@gmail.com on 22 Jun 2011 at 8:25

GoogleCodeExporter commented 8 years ago
We support a way of doing what you're after in the code already.  Since you 
can't serialize a Stopwatch and other issues, supporting a *running* profiler 
isn't realistic.  

However there is an extension method for your profling: 
   .AddProfilerResults(this MiniProfiler profiler, MiniProfiler externalProfiler)

What you can do is have your remote call run its own profiler and pass it back 
- through whatever serialization method you want. JSON serialization is in the 
core project, or it's serializable via protobuf - we do this at StackOverflow 
for example.

On the caller side, just attach that profiler to your main via:
  localProfiler.AddProfilerResults(otherProfiler)

...then the "other profiler" and its children will appear as a child at the 
current step in your main profiler.

Original comment by nrcraver on 22 Jun 2011 at 7:48