2 tricks to NHProf

Haven’t touch NhProf for a while, this morning the error message said, the installed license for NHibernate Profiler is not valid!

After contact with Ayende, it turns out the issue is from our user profile, because if I switch to a different user, everything works smoothly.

OK, while waiting for somebody can figure out that specific user profile problem, what I can do is to use the runas command to ‘sudo’ nhprof to run under another user account.

One annoying thing is windows keep asking input password when runas starts, echo password or pipe into a text file doesn’t work. The trick is to use built-in savecred option in runas command, just type in the password once, then it will save it.

runas /savecred /user:local\nhprof c:\app\nhprof\launch_nhprof.bat

Also, the trick for waiting for nhprof to generate report when shutting down:

runas /savecred /user:local\nhprof c:\app\nhprof\kill_nhprof.bat

@echo off
@echo waitinging for output report generating ...
:WAIT_FOR_OUTPUT
if not exist c:\tmp\nhprof_Output.html (
GOTO WAIT_FOR_OUTPUT
)
@echo on

Initialize NhProf in NUnit test

NhProf can be setup without changing the app code, but that assume you already have log4net hooked up in app. Our experience is setting up log4net is still more work comparing to init nhprof in unit-test code. http://nhprof.com/Learn/GettingStarted

Here is a easy way to init Nhprof in unit-test project, create a Global class with SetupFixture attribute, remove any namespace, this will ensure the setup code in this class run before any of the fixtures in the entire assembly. (NUnit doc)


    [SetUpFixture]
    public class Global
    {
        [SetUp]
        public void RunBeforeAnyTests()
        {
			Console.WriteLine("Initializing NHibernateProfiler......");
            HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
        }

    }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s