Add gem in Gemfile:
group :test, :development do
gem 'ruby-prof', '0.18.0'
end
add example file in: lib/scripts/test_provider.rb
require_relative '../../config/environment'
document = Document.where("name IS NOT NULL").last
DevelopmentProfiler.prof('junk') do
100.times do
puts StorageProvider::settings(document)
end
end
add lib file in: lib/development_profiler.rb
class DevelopmentProfiler
def self.prof(file_name)
if Rails.env.development?
RubyProf.start
yield
results = RubyProf.stop
RubyProf::CallTreePrinter.new(results).print({print_file: true})
else
yield
end
end
end
Run in console:
ruby lib/scripts/storage_provider_script.rb
This will generate a profile files, example:
profile.callgrind.out.84797
profile.callgrind.out.84797.70349423984460
profile.callgrind.out.84797.70349436691660
You can now open the file profile.callgrind.out.84797
using command line tool: qcachegrind
Installed using brew install qcachegrind
in mac