FiveRuns Blog

On Rails production performance and monitoring

Posts
No comments

Introducing "Instrument"

“Instrument” is a little utility library to get useful information out of methods with a minimum of fuss, and without having to dig into code to add debugging output. We’ve released it as a gem, and it’s being developed on GitHub.

Here’s a simple example. Let’s say you have a [contrived] class like this:

  class Car
    # ...
    def drive(miles)
      # ...
    end
  end

.. and you’d like to get some basic statistics whenever the drive method is called on an instance. With instrument, there’s no need to modify the actual Car class directly; you can just wrap the method with a handler that’s called after every invocation with the instance, time taken to invoke, and any arguments:

  require 'instrument'

  instrument 'Car#drive' do |car, time, miles|
    puts "#{car} was driven #{miles}mi (#{time})" 
  end
  # Drive a lot of cars

If you’d also like to know track the number of cars instantiated, just increment a counter:

  cars = 0
  instrument 'Car.new' do |klass, *args|
    cars += 1
  end
  # Make a lot of cars
  puts "Made #{cars} car(s)!" 

You can use the library to get basic performance numbers, to output tracing information, or just to do a bit of exploratory poking around.

Play with it, fork it, and send pull requests!

Bookmark and Share
Continued Discussion

No comments have been added yet.

Contribute

Continue the conversation and share your thoughts. A name is required. Your e-mail address will not be displayed on the site. Textile formatting may be used in your comments (but will not be rendered in the live comment preview).

→ Posted by You on June 09, 2009 at 02:23 PM

Flickr

FiveRuns tagged photos on Flickr.

  • fiveruns-penn-and-teller-8
  • Five Runs, Eric Schank, Lauren Sell and Brian Gugliemetti
  • ye old scroll of shameful tunes
  • fiveruns-penn-and-teller-4
  • fiveruns-penn-and-teller-3
  • Eric Lindvall and Penn
  • dwi_1201a
  • dwi_1201b

See more FiveRuns tagged photos…

Previous Entries

Other Categories

Entries are also organized under the following general topic categories.