Question

I think I'm setting up ServiceStack's profiler correctly, but maybe I'm not. I'm just trying to get the basics in place.

What I've done so far

The only steps I 've taken so far to install profiling -- In Global.asax.cs:

   private void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Request.IsLocal)
        {
            Profiler.Start();
        }
    }

    private void Application_EndRequest(object sender, EventArgs e)
    {
        Profiler.Stop();
    }

In my _SiteLayout.cshtml page, before any other javascript files are rendered, I attempt to render this:

<body>
<!-- ... -->

@Html.Raw(HttpUtility.HtmlDecode(Profiler.RenderIncludes().ToString()))

<!-- ...other scripts... -->
</body>

The Error I receive:

[NullReferenceException: Object reference not set to an instance of an object.]

ServiceStack.MiniProfiler.UI.MiniProfilerHandler.RenderIncludes(Profiler profiler, Nullable1 position, Nullable1 showTrivial, Nullable1 showTimeWithChildren, Nullable1 maxTracesToShow, Boolean xhtml, Nullable`1 showControls, String path) +293

ServiceStack.MiniProfiler.Profiler.RenderIncludes(Nullable1 position, Nullable1 showTrivial, Nullable1 showTimeWithChildren, Nullable1 maxTracesToShow, Boolean xhtml, Nullable`1 showControls) +99

....

Given that I'm trying to accomplish the basics, I'm unsure what could be null at this point. Is some sort of additional setup required prior to starting the profiler? Could it be a routing issue?

Was it helpful?

Solution

The solution in this case seems to be to just use the standard MiniProfiler library instead of the one included with ServiceStack.

Initial Setup

In the Nuget package installer, I ran:

Install-Package MiniProfiler
Install-Package MiniProfiler.MVC4

I modified global.asax in the following ways:

private void Application_BeginRequest(object sender, EventArgs e)
{
        MiniProfiler.Start();
}

private void Application_AuthenticateRequest(object sender, EventArgs e)
{
     //stops the profiler if the user isn't on the tech team
    var currentUser = ClaimsPrincipal.Current.Identity as ClaimsIdentity;
    if (!Request.IsLocal && !currentUser.GetGlobalRoles().Contains(Constant.Roles.TechTeam))
    {
        MiniProfiler.Stop(discardResults:true);
    }
}

private void Application_EndRequest(object sender, EventArgs e)
{
    MiniProfiler.Stop();
}

Then, in my Layout.cshtml file, before the end of the body tag, I placed:

    @MiniProfiler.RenderIncludes()    

    </body>
</html>

Profiling a DB Connection

In the section of code that returns my OrmLiteConnectionFactory, I use the following code:

    private OrmLiteConnectionFactory claimFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString(), true, SqlServerDialect.Provider)
     {
         ConnectionFilter = x => new ProfiledDbConnection(x as System.Data.SqlClient.SqlConnection, MiniProfiler.Current)
     };

This seems to profile the SQL and connections just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top