BENCHMARKABLE by Aman King

bitbucket.org/amanking/benchmarkable/

A module that allows a class to mention which instance methods to benchmark, and then allows retrieving the benchmark report in csv format from the class’s instances. The csv includes the method invocation timestamp, some context description (if provided), the method name along with arguments passed for the invocation, and the number of seconds the method took to execute.

Eg: class Gateway

# ...
def make_request(url)
  url = URI.parse(url)
  Net::HTTP.start(url.host, url.port) {|http|
    http.get('/index.html')
  }
rescue => error
  puts "Unexpected error: #{error.message}"
end
# ...

include Benchmarkable
benchmark :make_request

end

gateway = Gateway.new gateway.make_request(‘www.google.com/’) gateway.make_request(‘www.yahoo.com/’) gateway.make_request(‘www.wikyblog.com/AmanKing/’) File.open(‘./gateway_performance_report.csv’, ‘a+’) do |file|

file.puts gateway.benchmark_report.to_csv(:starting_context => 'gateway')

end

Output (in gateway_performance_report.csv): “2009-09-10T20:13:59+05:30”,“gateway”,“make_request www.google.com/”,“0.306514978408813” “2009-09-10T20:13:59+05:30”,“gateway”,“make_request www.yahoo.com/”,“1.08063411712646” “2009-09-10T20:14:00+05:30”,“gateway”,“make_request www.wikyblog.com/AmanKing/”,“2.1521680355072”

(see samples/ajaxy_blog_spec.rb for an example of how to use Benchmarkable to monitor ajax performance using selenium, and look at spec/benchmarkable_spec.rb for more details about the api)

License

Copyright 2009 Aman King

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.