Cpu profiling

502 views
333 views

Published on

CPU Profiling in Ruby on Rails using qcachegrind or kcachegrind

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
502
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×