Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cpu profiling

508 views

Published on

CPU Profiling in Ruby on Rails using qcachegrind or kcachegrind

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Cpu profiling

  1. 1. Quick guide to CPU profiling Rails apps with k/qcachegrind Mike Auclair @mikeauclair github.com/mikeauclair
  2. 2. Step 1: Acquire kcachegrind(KDE) or qcachegrind (everything else) ● qcachegrind is available in homebrew
  3. 3. Step 2: Grab development_profiler.rb or something similar to asbtract away some of the profiling configuration, plop it in lib/
  4. 4. development_profiler.rb class DevelopmentProfiler def self.prof(file_name) if Rails.env.development? RubyProf.start yield results = RubyProf.stop File.open "#{Rails.root}/tmp/performance/callgrind.#{file_name}.clt", 'w' do |file| RubyProf::CallTreePrinter.new(results).print(file) end else yield end end end
  5. 5. Step 3: Wrap your suspect code in a .prof block: DevelopmentProfiler.prof('junk') do SlowThing.new(45000) end
  6. 6. Step 4: Run your code and bust open the file in qcachegrind
  7. 7. Contrived Example class Shitty def initialize(some_int) @symbols = (0..some_int).map(&:to_s).map(&:to_sym) end end
  8. 8. Improved Contrived Example class Better def initialize(some_int) @symbols = (0..some_int).map{|i| i.to_s.to_sym} end end

×