Merge pull request #14313 from apainintheneck/fix-brew-prof

cmd/prof: Fix gem errors
This commit is contained in:
Mike McQuaid 2023-01-02 19:14:03 +00:00 committed by GitHub
commit 585d10fdc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 1 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -2,6 +2,7 @@
# frozen_string_literal: true
if ENV["HOMEBREW_STACKPROF"]
require "rubygems"
require "stackprof"
StackProf.start(mode: :wall, raw: true)
end

View File

@ -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

View File

@ -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