diff --git a/.gitignore b/.gitignore index bedc02b47f..05579c2c25 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ /Library/Homebrew/.npmignore /Library/Homebrew/bin /Library/Homebrew/doc +/Library/Homebrew/prof /Library/Homebrew/test/.gem /Library/Homebrew/test/.subversion /Library/Homebrew/test/coverage diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 5ca3ee4f0c..d9fd4d2a3e 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -2,6 +2,7 @@ # frozen_string_literal: true if ENV["HOMEBREW_STACKPROF"] + require "rubygems" require "stackprof" StackProf.start(mode: :wall, raw: true) end diff --git a/Library/Homebrew/dev-cmd/prof.rb b/Library/Homebrew/dev-cmd/prof.rb index dfc7f1ae18..4a1f5e5ae0 100644 --- a/Library/Homebrew/dev-cmd/prof.rb +++ b/Library/Homebrew/dev-cmd/prof.rb @@ -37,7 +37,9 @@ module Homebrew output_filename = "prof/d3-flamegraph.html" safe_system "stackprof --d3-flamegraph prof/stackprof.dump > #{output_filename}" else - Homebrew.install_gem_setup_path! "ruby-prof" + # NOTE: ruby-prof v1.4.3 is the last version that supports Ruby 2.6.x + # TODO: Remove explicit version arg when we move to a newer version of Ruby + Homebrew.install_gem_setup_path! "ruby-prof", version: "1.4.3" output_filename = "prof/call_stack.html" safe_system "ruby-prof", "--printer=call_stack", "--file=#{output_filename}", brew_rb, "--", *args.named end diff --git a/Library/Homebrew/test/dev-cmd/prof_spec.rb b/Library/Homebrew/test/dev-cmd/prof_spec.rb index c8a62801ae..cdbe09687d 100644 --- a/Library/Homebrew/test/dev-cmd/prof_spec.rb +++ b/Library/Homebrew/test/dev-cmd/prof_spec.rb @@ -5,4 +5,24 @@ require "cmd/shared_examples/args_parse" describe "brew prof" do it_behaves_like "parseable arguments" + + describe "integration tests", :integration_test, :needs_network do + after do + FileUtils.rm_rf HOMEBREW_LIBRARY_PATH/"prof" + end + + it "works using ruby-prof (the default)" do + expect { brew "prof", "help", "HOMEBREW_BROWSER" => "echo" } + .to output(/^Example usage:/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + + it "works using stackprof" do + expect { brew "prof", "--stackprof", "help", "HOMEBREW_BROWSER" => "echo" } + .to output(/^Example usage:/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + end end