Skip to content

Instantly share code, notes, and snippets.

@cmatheson
Last active December 14, 2015 20:59
Show Gist options
  • Save cmatheson/5147678 to your computer and use it in GitHub Desktop.
Save cmatheson/5147678 to your computer and use it in GitHub Desktop.
perftools.rb example
# log_to_stdout! (useful if you're running this as a script/runner thing)
Object.send(:remove_const, :RAILS_DEFAULT_LOGGER)
Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
ActiveRecord::Base.logger = Rails.logger
Mailman.config.logger = Rails.logger
ActiveRecord::Base.connection_handler.clear_all_connections!
require 'perftools' # add perftools.rb to your Gemfile
time = Time.now.to_i
bm_data = "/tmp/profile_#{time}.data"
gif = "/tmp/profile_#{time}.gif"
PerfTools::CpuProfiler.start(bm_data) do
# PROFILED STUFF GOES HERE
end
# don't exec your browser if you are doing this in script/server
system "bundle exec pprof.rb --gif #{bm_data} > #{gif}"
exec "chromium-browser --app=\"file://#{gif}\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment