Skip to content
Snippets Groups Projects
Unverified Commit 893cc99b authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #8408 from MikeMcQuaid/prof

prof: improve `brew prof` functionality.
parents 8041649c a4d0174d
No related branches found
No related tags found
No related merge requests found
......@@ -133,6 +133,7 @@
**/vendor/bundle/ruby/*/gems/ruby-progressbar-*/
**/vendor/bundle/ruby/*/gems/simplecov-*/
**/vendor/bundle/ruby/*/gems/simplecov-html-*/
**/vendor/bundle/ruby/*/gems/stackprof-*/
**/vendor/bundle/ruby/*/gems/thor-*/
**/vendor/bundle/ruby/*/gems/unf_ext-*/
**/vendor/bundle/ruby/*/gems/unf-*/
......
# frozen_string_literal: true
if ENV["HOMEBREW_STACKPROF"]
require_relative "utils/gems"
Homebrew.setup_gem_environment!
require "stackprof"
StackProf.start(mode: :wall, raw: true)
end
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"]
std_trap = trap("INT") { exit! 130 } # no backtrace thanks
......@@ -186,4 +193,9 @@ rescue Exception => e # rubocop:disable Lint/RescueException
exit 1
else
exit 1 if Homebrew.failed?
ensure
if ENV["HOMEBREW_STACKPROF"]
StackProf.stop
StackProf.results("prof/stackprof.dump")
end
end
......@@ -10,17 +10,32 @@ module Homebrew
usage_banner <<~EOS
`prof` [<command>]
Run Homebrew with the Ruby profiler, e.g. `brew prof readall`.
Run Homebrew with a Ruby profiler, e.g. `brew prof readall`.
EOS
switch "--stackprof",
description: "Use `stackprof` instead of `ruby-prof` (the default)."
end
end
def prof
args = prof_args.parse
Homebrew.install_gem_setup_path! "ruby-prof", version: "0.18.0"
FileUtils.mkdir_p "prof"
brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path
safe_system "ruby-prof", "--printer=multi", "--file=prof", brew_rb, "--", *args.named
FileUtils.mkdir_p "prof"
if args.stackprof?
Homebrew.install_gem_setup_path! "stackprof"
with_env HOMEBREW_STACKPROF: "1" do
safe_system ENV["HOMEBREW_RUBY_PATH"], brew_rb, *args.named
end
output_filename = "prof/d3-flamegraph.html"
safe_system "stackprof --d3-flamegraph prof/stackprof.dump > #{output_filename}"
else
Homebrew.install_gem_setup_path! "ruby-prof"
output_filename = "prof/call_stack.html"
safe_system "ruby-prof", "--printer=call_stack", "--file=#{output_filename}", brew_rb, "--", *args.named
end
exec_browser output_filename
end
end
......@@ -1082,7 +1082,10 @@ Apply the bottle commit and publish bottles to Bintray.
### `prof` [*`command`*]
Run Homebrew with the Ruby profiler, e.g. `brew prof readall`.
Run Homebrew with a Ruby profiler, e.g. `brew prof readall`.
* `--stackprof`:
Use `stackprof` instead of `ruby-prof` (the default).
### `release-notes` [*`options`*] [*`previous_tag`*] [*`end_ref`*]
......
......@@ -1498,7 +1498,11 @@ Upload to the specified Bintray organisation (default: \fBhomebrew\fR)\.
Use the specified \fIURL\fR as the root of the bottle\'s URL instead of Homebrew\'s default\.
.
.SS "\fBprof\fR [\fIcommand\fR]"
Run Homebrew with the Ruby profiler, e\.g\. \fBbrew prof readall\fR\.
Run Homebrew with a Ruby profiler, e\.g\. \fBbrew prof readall\fR\.
.
.TP
\fB\-\-stackprof\fR
Use \fBstackprof\fR instead of \fBruby\-prof\fR (the default)\.
.
.SS "\fBrelease\-notes\fR [\fIoptions\fR] [\fIprevious_tag\fR] [\fIend_ref\fR]"
Print the merged pull requests on Homebrew/brew between two Git refs\. If no \fIprevious_tag\fR is provided it defaults to the latest tag\. If no \fIend_ref\fR is provided it defaults to \fBorigin/master\fR\.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment