Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With the mini-profiler

When using the mini profiler, does this mean production code will be 'littered' with using blocks?

using (profiler.Step("Set page title"))
{
    ViewBag.Title = "Home Page";
}

I guess if it is 1-off testing I could remove it, but usually you want to keep these in the codebase for constant profiling.

like image 303
codecompleting Avatar asked Aug 16 '11 18:08

codecompleting


People also ask

What is Mini Profiler?

Developers have many tools they can use to profile web applications and find the performance bottlenecks. MiniProfiler is one such tool — a simple yet powerful tool for profiling web applications. MiniProfiler helps you detect slow running queries, slow server response times, and more.

What is MiniProfiler .NET core?

MiniProfiler is a very lightweight, easy to use profiling library for ASP.Net applications which can profile dotnet application during runtime without change to the environment and effect on the application.


1 Answers

That is actually a bad example - you wouldn't normally profile something trivial.

Ultimately, it is elective what you want to profile. There's a hook for things like ADO.NET, but if you want it to profile things outside of this, yes: you need to give it a hand.

Re "littered", well, that is subjective. And the best approach is usually to limit the instrumentation to very high level operations, and then only zoom in with more granular operations as you find you need to (due to an identified problem spot); for example, you might have:

...
using(profiler.Step("Refresh customer"))
{
    // ...
}
...

and then only when you find that taking 1800ms zoom in:

...
using(profiler.Step("Refresh customer"))
{
    using(profiler.Step("Query LDAP"))
    { ... }
    using(profiler.Step("Query primary customer DB"))
    { ... }
    using(profiler.Step("Query aux db"))
    { ... }
    using(profiler.Step("Print, scan, and OCR"))
    { ... }
}
...

There is also an .Inline(...) method for individual commands.

Whether or not you think this is "littering":

  • it emphasises performance is a feature (and indeed, often a requirement) - it is OK to have code to support your features! Indeed, it is a form of evidence that you have considered (and measured) performance of a new / altered piece of code
  • it is entirely contextual how granular you make it
  • it therefore provides a meaningful level of detail to the user - without insane amounts of trivia in the log, and without the performance-invasive nature of most logging
like image 177
Marc Gravell Avatar answered Nov 03 '22 15:11

Marc Gravell