mishrsud / mvc-mini-profiler

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

Step should be a method on the `MiniProfiler` instance, for scenarios where adding a `using` directive is not available. #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Step should be a method on the `MiniProfiler` instance, for scenarios where 
adding a `using` directive is not available.

For example, in a view (where the namespace MvcMiniProfiler is included in the 
current scope), it may be helpful to call MiniProfiler.Step() for things like 
rendering a grid, or the like.

Original issue reported on code.google.com by Spoonful...@gmail.com on 9 Jun 2011 at 5:55

GoogleCodeExporter commented 8 years ago
Can you clarify? perhaps giving an example of where it is impossible / 
undesirable to add a using directive?

Original comment by marc.gravell on 9 Jun 2011 at 10:36

GoogleCodeExporter commented 8 years ago
You can just store the result of a .Step() call in a variable:

   var disposeMeLater = MiniProfiler.Current.Step("This spans lots of stuff!");

   ...

   if (disposeMeLater != null)
       disposeMeLater.Dispose(); // stop this step's timer

The extension method .Step() protects you from having to check 

   MiniProfiler.Current != null

every time you want to call .Step()

Original comment by jarrod.m.dixon on 9 Jun 2011 at 10:39

GoogleCodeExporter commented 8 years ago
@marc,
I was planning on wrapping the code for starting and stopping in an `#if 
PROFILING` directive, and I wanted to have it all together; forcing a using 
makes it such that I can't do "remove and sort usings", because one of them 
would be wrapped in the `#if` directives.  I also wanted to use it in my 
_Layout.cshtml, without adding it to my web.config.

@jarrod,
Did that comment belong on issue #4, perhaps?

Original comment by Spoonful...@gmail.com on 10 Jun 2011 at 12:36

GoogleCodeExporter commented 8 years ago
I was just giving an example of how to use .Step() outside of a using block 
(yes, it's not the prettiest code).

I don't know how we could make this cleaner, other than exposing 
MiniProfiler.StepImpl() to return a Timing object, which you could then call 
.Stop() on.

Original comment by jarrod.m.dixon on 13 Jun 2011 at 6:54

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Right, however, this request is to drop the need for:

    using MvcMiniProfiler;
    namespace Foo
    {
        ...
    }

issue #4 discusses a non-IDisposable version of `Step`.

Original comment by Spoonful...@gmail.com on 13 Jun 2011 at 7:34

GoogleCodeExporter commented 8 years ago
Could we add some static methods on `MvcProfiler` that make use of the existing 
extension methods?

Something like:

    public class MvcProfiler
    {
        ...
        public static IDisposable Step(string name, ProfileLevel level = ...)
        {
            return MvcProfiler.Current.Step(name, level);
        }
    }

That would allow us to call `MvcProfiler.Step` statically, eliminating the need 
for extension methods in the simple case.

Original comment by Spoonful...@gmail.com on 13 Jun 2011 at 7:39

GoogleCodeExporter commented 8 years ago
http://code.google.com/p/mvc-mini-profiler/source/detail?r=b867900956199fe09873c
d73460910a122f5eb5a

If you can think of a better name, I'm happy to change it!

Original comment by jarrod.m.dixon on 14 Jun 2011 at 10:29

GoogleCodeExporter commented 8 years ago

Original comment by jarrod.m.dixon on 14 Jun 2011 at 10:38