Embed NhProf into CruiseControl.net

There is a brief document on NHProf website describing how to embed NhProf into CI server, here are practical problems I encountered and my solutions/workaround.

First problem is, once NhProf command line start up, it sits there until Ctl+C. I need to make it run in background mode, in window term, start it in a new command window. This is simple, adding a start right before the start batch fixed the problem.

But the second problem is very difficult, NhProf can output to xml format or html format, but there is no xslt file available to let user to do xml transformation.

I could create my own xslt file, but looked into the html output, it’s a lot of work. I decided to simply embed the whole html chunk as the CData block into CruiseControl merged result.


  <target name="run.test.with.nhprof" depends="launch.nhprof, run.test, shutdown.nhprof, wrap.nhprof.output" />

  <target name="launch.nhprof" >
	<if test="${file::exists('c:\app\nhprof\start_nhprof.bat')}">
	    <exec basedir="${dir.tools}/nhprof/" workingdir="${dir.compile}" program="c:\app\nhprof\start_nhprof.bat" />
		<echo message="NHibernate Profiler started." />

  <target name="shutdown.nhprof" >
  	<if test="${file::exists('c:\app\nhprof\shutdown_nhprof.bat')}">
		<exec basedir="${dir.tools}/nhprof/" workingdir="${dir.compile}" program="c:\app\nhprof\shutdown_nhprof.bat" />

  <target name="wrap.nhprof.output" >
	<echo message="Waiting for NhProf generating output file..." />
	<sleep milliseconds="1000" />

                property="nhprof.output" />
	<echo file="${dir.compile}/nhprof_output.xml" message="&lt;nhprof&gt;&lt;![CDATA[${nhprof.output}]]&gt;&lt;/nhprof&gt;" />


 	<xsl:template match="/">
		<xsl:value-of select="cruisecontrol//nhprof" disable-output-escaping="yes" />

Here is the result:

Note: IE doesn’t support nested html tag (html/html), this screen shot is taken from Firefox.


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