Profiling builds

Posted by aslak.hellesoy

p=. !http://aslakhellesoy.com/files/images/script_profile.png! Our build was slow, so I wanted to identify *where* it was slow. The screenshot above is the standard output of Maven2, as HTML. The font size of each line is proportional with the time it took to execute that line, and the time (in seconds) is also prepended each line. This kind of visual representation makes it extremely easy to identify what's slow. In our case it was Checkstyle and PMD. So we yanked it from the regular build and increased the speed by 20%. How did I generate this HTML? With Ruby of course!
1
2
3
4
5
6
7
8
9
10

# prof.rb
puts "<html><pre>"
STDIN.each do |l| 
  d = (now=Time.new)-($last||=now)
  p = d*100
  puts "<span style=\"font-size:#{p}%\">[#{d}] #{l.strip}</span>"
  $last=now
end
puts "</pre></html>"
And I run it like this:

mvn clean -P integrationtests install | ruby prof.rb > mvn.html
You can use this tiny script to profile *any* command line tool that writes data to standard out. Simple and powerful.