Book Image

Mastering ServiceStack

By : Andreas Niedermair
Book Image

Mastering ServiceStack

By: Andreas Niedermair

Overview of this book

Table of Contents (13 chapters)

Profiling requests


The next step is to dig deeper into the timings of your service to examine the concrete request and its execution chain. ServiceStack comes with an adapted implementation of MiniProfiler (original implementation available at http://miniprofiler.com/), a simple but effective mini-profiler.

Its main goal is to bring profiling to hosted services, but we will implement a solution that works for self-hosted services as well.

To start profiling, we need to adapt the Application_BeginRequest method in Global.asax file, as shown:

using System;
using System.Web;
using ServiceStack;
using ServiceStack.MiniProfiler;

public partial class Global : HttpApplication
{
  protected void Application_BeginRequest(object sender,
                                          EventArgs e)
  {
    Profiler.Start();
  }
}

This starts the profiling for every request (service- and website-requests). You can also limit the profiling to debug mode by verifying the value of HostContext.Config.DebugMode or...