Last active
December 14, 2015 20:59
-
-
Save cmatheson/5147678 to your computer and use it in GitHub Desktop.
perftools.rb example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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