Profiling NHibernate with Glimpse

Glimpse is a popular diagnostics and profiling framework, built especially for .NET web applications. In this recipe, we will show you how to use Glimpse and the Glimpse.NHibernate add-on, in order to profile NHibernate requests.

Getting ready

Open an existing ASP.NET web application project that uses NHibernate or complete the Setting up session-per-web request recipe from Chapter 3, Sessions and Transactions.

How to do it...

  1. Install Glimpse for MVC using the NuGet Package Manager Console by executing the following command:
    Install-Package Glimpse.MVC5
    
  2. Install the NHibernate.Glimpse package using the NuGet Package Manager Console by executing the following command:
    Install-Package NHibernate.Glimpse
    
  3. Run the web application.
  4. Navigate to /glimpse.axd.
  5. Click the button labeled Turn Glimpse On.
  6. Navigate to any URL which executes NHibernate queries, such as the /books page in the example application.
  7. Click on the Glimpse logo in the bottom-right corner of the page.
  8. Investigate the query log in the NHibernate tab, as shown in this screenshot:
    How to do it...

How does it work...

Once enabled, Glimpse uses an ASP.NET HttpModule, which injects markup and script into your page, in order to display its user interface. Normally, this is activated only when the application is running locally.

Additionally, the NHibernate add-on configures a custom logger, which intercepts NHibernate's log messages and parses them into data points for Glimpse.

All necessary configurations will be added by the NuGet package installer, but if you want to see detailed data about the executed commands, you can edit an appSetting in web.config.

<add key="NHibernate.Glimpse.Loggers" value="command,connection,flush,load,transaction"/>

More information about Glimpse can be found at http://getglimpse.com.

See also

  • Setting up a session-per-web request
  • Configure log4net logging
  • Using NHibernate Profiler
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.164.75