A simple tool to instrument Ruby code and output basic metrics to a logger or store them in a hash.
From the French noun étalon
meaning:
standard: something used as a measure for comparative evaluations
Installation
Add this line to your application's Gemfile:
gem 'etalon'
And then execute:
$ bundle
Or install it yourself as:
$ gem install etalon
In that last case, you'll need to manually require "etalon"
.
Usage
Assuming the following instrumented code:
class Cooking
def self.potato
Etalon.time("Making taters") do
peel_potato
cook_potato
end
end
end
You can do the following:
$ irb
require "cooking"
=> true
Etalon.activate
=> true
Etalon.print_timings
=> {:making_taters=>["count: 1", "min: 0", "max: 400", "mean: 400.0", "deviation: ±0%", "top 5: [400]"]}
If Rails.logger
is available, Etalon will also output the following with
a call to Rails.logger.debug
in the relevant log file:
Making Taters - count: 1 | min: 0 | max: 400 | mean: 400.0 | deviation: ±0.0% | top 5: [400]
If Rails.logger
isn't available, Etalon attempts to require
syslog/logger
from the Ruby standard library as a fallback
logging mechanism.
Contributing
Bug reports and pull requests are welcome.