Skip to content

Instantly share code, notes, and snippets.

@christopherstyles
Created August 12, 2015 20:29
Show Gist options
  • Select an option

  • Save christopherstyles/d9285b33ee64831990e6 to your computer and use it in GitHub Desktop.

Select an option

Save christopherstyles/d9285b33ee64831990e6 to your computer and use it in GitHub Desktop.
Profile an RSpec example
#!/usr/bin/env ruby
$:.unshift 'spec'
require 'rspec'
require 'rails_helper'
spec = ARGV[0]
# -----------------------------------------------------------------------------
# If using StackProf
#
require 'stackprof'
interval = ENV.fetch('INTERVAL', 1000).to_i
limit = ENV.fetch('LIMIT', 20)
output_file = "tmp/#{spec.split('/').last}.dump"
StackProf.run(mode: :wall, out: output_file) do
10.times do
RSpec::Core::Runner.run([spec], $stderr, $stdout)
end
end
system("stackprof #{output_file} --text --limit #{limit}")
# -----------------------------------------------------------------------------
# If using RubyProf
#
require 'ruby-prof'
result = RubyProf.profile do
RSpec::Core::Runner.run([spec], $stderr, $stdout)
end
File.open('tmp/graphs/callstack.html', 'w') do |file|
RubyProf::CallStackPrinter.new(result).print(file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment