Mini MVC profiler: appears to be displaying profile times for every static resource
Asked Answered
C

2

28

I've just started using the mvc-mini-profiler (http://code.google.com/p/mvc-mini-profiler/) and I think it's awesome. However, I'm getting some odd behaviour while using it.

I've got an ASP.NET Webforms site running on IIS7.5 and for some reason when I load a page with the profiler enabled, I not only get a time measurement for the aspx page, but I also get it for random css and js resources on the page.

The aspx profile works correctly, with the SQL query also being profiled correctly. However, as the picture shows I also get a bunch of other results which appear to be results for static CSS and JS files. As far as I can tell, these are being served up statically by IIS, so the profiler code shouldn't even be invoked for these.

The relevant parts of my Global.asax are:

    protected void Application_BeginRequest()
    {
        MiniProfiler profiler = null;

        // might want to decide here (or maybe inside the action) whether you want
        // to profile this request - for example, using an "IsSystemAdmin" flag against
        // the user, or similar; this could also all be done in action filters, but this
        // is simple and practical; just return null for most users. For our test, we'll
        // profile only for local requests (seems reasonable)
        profiler = MiniProfiler.Start();

        using (profiler.Step("Application_BeginRequest"))
        {
            // you can start profiling your code immediately
        }
    }

    protected void Application_EndRequest()
    {
        MvcMiniProfiler.MiniProfiler.Stop();
    }

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (User == null || !User.Identity.IsAuthenticated)
        {
            MvcMiniProfiler.MiniProfiler.Stop(true);
        }
    }

Is this behaviour expected?

Couplet answered 11/7, 2011 at 9:36 Comment(0)
S
44

Yes this is correct but it is very easy to filter these out.

Taken from the sample code in the project Source

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup

    // some things should never be seen
    var ignored = MiniProfiler.Settings.IgnoredPaths.ToList();

    ignored.Add("WebResource.axd");
    ignored.Add("/Styles/");

    MiniProfiler.Settings.IgnoredPaths = ignored.ToArray();
}

This lets you filter out what you want to see or not this is a sample of what I have excluded in my web application which i am finding is working for my application

ignored.Add("WebResource.axd");
ignored.Add("ScriptResource.axd");
ignored.Add("/Styles/");
ignored.Add("/Images/");
ignored.Add(".js");
Sting answered 11/7, 2011 at 13:9 Comment(2)
One thing i noticed with the latest code is there is some debug code that has been left in and causes some issues with IE. I have logged an issue on the issue tracker Issue 53Sting
I'll keep an eye out - thanks. All our devs are on Chrome/FF, so I'm not that worried.Couplet
E
1

You can actually put that in one line and also omit the slashes. Like this:

    protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            MiniProfiler.Start();
            MiniProfiler.Settings.IgnoredPaths = new[] { "static", "webresource.axd", "styles", "images" };
        }
     }
Enroot answered 4/12, 2013 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.