Graphing your CruiseControl build times with Gruff

There had been some concern on my last project about build times. My erstwhile colleague Ben started graphing the builds on a sheet of paper and posting it in the kitchen so everybody in the team could see it. When the sheet fell of the wall and the cleaners threw it away, I knew it was time to do something.

Cruise Publisher
How do you get the build time in the first place? I wrote a CruiseControl publisher that called some Ruby code to extract the build duration from the CruiseControl log, which is an XML file. It was a very simple script that matched duration of the Ant build in the XML file, converted the text to a number of seconds, and then made an HTTP POST to a Rails application. The build duration got passed as a POST argument.

We had a Rails application to display other project information. So for us, this was a convenient way to store the information, with the date coming from the database. You could use a text file to store this information instead. Once everything was in place it was easy to write some more Ruby to make the graph appear.

The Code

require ‘chart’
require ‘gruff’

data = { “count” => [ 3, 5, 2 ] }
g = 640
g.title = “Usages of the word ‘foo'”
g.labels = { 0 => ‘Monday’, 1 => ‘Tuesday’, 2 => ‘Wednesday’}
data.each_pair {|k, v|, v)}
blob = g.to_blob

out =“blob.png”,”w+”)
out < blob

This code uses Gruff to actually generate the chart, and you’ll need to install this separately. Pass it some data and it will build a PNG file with your graph. By plumbing it into the radiator, the trend in build times is visible to the entire room. It really helped to keep the team focussed on the length of the build – especially for browser based tests that can easy start to slow things down.

%d bloggers like this: