Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

« NHProf, bags, the select N+1 problem and solving itnhibernate, nunit 2.4.6 and log4net »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

As a user of nHibernate it was about time I got to check out NHProf. NHProf is a profiler for nHibernate applications. In other words you can see what SQL nHinernate is producing and it also gives alerts for parts that have suspect code in it.

First of course I had to download the package you can have a 30 day trail to go so you can test it on your application. I just bought it. Let's not forget that this is still in Beta so because of that you get a discount for when the full version comes out.

Then I had to set it up to work with my application. But remember you are not supposed to ship the binaries with your application (what would be the point anyway?)

First you add a reference to the HibernatingRhinos.NHibernate.Profiler.Appender.dll and then you add this line of code to your startup routine.

  1. HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize()

of course you could just add that line anywhere you want NHProf to start profiling.

There is also another way of initializing NHProf. You can add an XML config file.

That looks like this

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <log4net>
  3.   <appender name="NHibernate.Profiler"
  4.       type="HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfilerAppender,
  5.         HibernatingRhinos.NHibernate.Profiler.Appender" >
  6.     <sink value="tcp://127.0.0.1:22897/NHibernateAppenderLoggingSink" />
  7.   </appender>
  8.   <logger name="NHibernate.Transaction.AdoTransaction">
  9.     <level value="DEBUG"/>
  10.     <appender-ref ref="NHibernate.Profiler"/>
  11.   </logger>
  12.   <logger name="NHibernate.Loader.Loader">
  13.     <level value="DEBUG"/>
  14.     <appender-ref ref="NHibernate.Profiler"/>
  15.   </logger>
  16.   <logger name="NHibernate.Event.Default.DefaultLoadEventListener">
  17.     <level value="DEBUG"/>
  18.     <appender-ref ref="NHibernate.Profiler"/>
  19.   </logger>
  20.   <logger name="NHibernate.Impl.AbstractSessionImpl">
  21.     <level value="DEBUG"/>
  22.     <appender-ref ref="NHibernate.Profiler"/>
  23.   </logger>
  24.   <logger name="NHibernate.SQL">
  25.     <level value="DEBUG"/>
  26.     <appender-ref ref="NHibernate.Profiler"/>
  27.   </logger>
  28.   <logger name="NHibernate.Impl.SessionImpl">
  29.     <level value="DEBUG"/>
  30.     <appender-ref ref="NHibernate.Profiler"/>
  31.   </logger>
  32.   <logger name="NHibernate.Persister.Entity.AbstractEntityPersister">
  33.     <level value="DEBUG"/>
  34.     <appender-ref ref="NHibernate.Profiler"/>
  35.   </logger>
  36. </log4net>

but then you need to initialize NHProf with this line of code.

  1. log4net.Config.XmlConfigurator.Configure(New FileInfo("log4net.config"))

Problem number 1

The first problem I had was that I have the sourcecode of log4net and that I therefor use a custom version. Allthough both versions have the same versionnumber I had to change over to the binary NHProf uses. No big problem since I use a wrapper assembly and I only had one reference to log4net that I had to change. I mailed the problem to Ayende and I got an imediate reply.

Problem solved.

Problem number 2

The second problem I faced was this.

I have worked around it

I use this piece of code for making my windowsforms application singleinstance. It's in VB.Net but there's not much code. In essence it inherits from WindowsFormsApplicationBase which is the problem it seems.

  1. Imports Microsoft.VisualBasic.ApplicationServices
  2.  
  3.  
  4. Namespace Startup
  5.     ''' <summary>
  6.     '''
  7.     ''' </summary>
  8.     ''' <remarks></remarks>
  9.     Public Class SingleInstanceController
  10.         Inherits WindowsFormsApplicationBase
  11.         Implements Interfaces.ISingleInstanceController
  12.  
  13. #Region " Private members "
  14.         ''' <summary>
  15.         '''
  16.         ''' </summary>
  17.         ''' <remarks></remarks>
  18.         Private _Menu As Forms.Interfaces.IMenu
  19. #End Region
  20.  
  21. #Region " Constructors "
  22.         ''' <summary>
  23.         '''
  24.         ''' </summary>
  25.         ''' <remarks></remarks>
  26.         Public Sub New(ByVal Menu As Forms.Interfaces.IMenu)
  27.             _Menu = Menu
  28.             IsSingleInstance = True
  29.         End Sub
  30. #End Region
  31.  
  32. #Region " Evenhandlers "
  33.         ''' <summary>
  34.         ''' When the user tries to open our application again then menu will just become visible and be pushed to the front.
  35.         ''' </summary>
  36.         ''' <param name="sender"></param>
  37.         ''' <param name="e"></param>
  38.         ''' <remarks></remarks>
  39.         Private Sub this_StartupNextInstance(ByVal sender As Object, ByVal e As StartupNextInstanceEventArgs) Handles MyBase.StartupNextInstance
  40.             Me.MainForm.Show()
  41.             Me.MainForm.BringToFront()
  42.         End Sub
  43. #End Region
  44.  
  45. #Region " public methods "
  46.         ''' <summary>
  47.         ''' When the application is run the first time this method is called.
  48.         ''' </summary>
  49.         ''' <remarks>We make a new instance of the Menu and it will be shown</remarks>
  50.         Protected Overrides Sub OnCreateMainForm()
  51.            MainForm = CType(_Menu, System.Windows.Forms.Form)
  52.         End Sub
  53.  
  54.         ''' <summary>
  55.         '''
  56.         ''' </summary>
  57.         ''' <param name="args"></param>
  58.         ''' <remarks></remarks>
  59.         Public Shadows Sub Run(ByVal args As String()) Implements Interfaces.ISingleInstanceController.Run
  60.             MyBase.Run(args)
  61.         End Sub
  62. #End Region
  63.  
  64.     End Class
  65. End Namespace
The exception is tcp channel is already registered (freely translated) and it's a remotingexception. NHProf is registered before that and All the nhibernate code before that gets nicely caught by NHProf (the little there is). So I'm guessing NHProf and it use the same channel ;-). I haven't looked further into it.

Also got a swift reply.

Christian,
Yes, that is a known problem, and it will be fixed shortly, we change the way that we communicate and that would solve the issue for you.
The release data for this is a few days

I'll forgive him for misspelling my name.


Problem solved.

So now I have a working NHProf.

And now I have something else to talk too ;-).

About the Author

User bio imageChristiaan is a forensic technician who programs on the side, although my function description says that I do IT-things for 90% of the time . I'm an avid VB.NET fan and I use lots of the ALT.Net techniques, like unit-testing, nhibernate, logging, IoC, ...
Social SitingsTwitterLinkedInHomePageLTD RSS Feed
452 views
nhprof, vb.net
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

1 comment

Comment from: Alex Ullrich [Member] Email
*****
This is something I would love to have for my personal use, but I haven't had a ton of time to look into (just read a little bit). Since that beta discount is pretty substantial I might have to move kicking the tires on that to the front burner.

You say the beginning, I hope this means you'll be posting more on the subject :)
07/05/09 @ 15:40

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)