Created
August 12, 2015 20:29
-
-
Save christopherstyles/d9285b33ee64831990e6 to your computer and use it in GitHub Desktop.
Profile an RSpec 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
| #!/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