prof: improve brew prof functionality.

- Add `--stackprof` to allow using stackprof
- Use the latest version of `ruby-prof`
- Automatically open the generated HTML output
This commit is contained in:
Mike McQuaid 2020-08-20 13:01:58 +01:00
parent f6e035ec98
commit a4d0174d7b
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
5 changed files with 41 additions and 6 deletions

1
.gitignore vendored
View File

@ -133,6 +133,7 @@
**/vendor/bundle/ruby/*/gems/ruby-progressbar-*/ **/vendor/bundle/ruby/*/gems/ruby-progressbar-*/
**/vendor/bundle/ruby/*/gems/simplecov-*/ **/vendor/bundle/ruby/*/gems/simplecov-*/
**/vendor/bundle/ruby/*/gems/simplecov-html-*/ **/vendor/bundle/ruby/*/gems/simplecov-html-*/
**/vendor/bundle/ruby/*/gems/stackprof-*/
**/vendor/bundle/ruby/*/gems/thor-*/ **/vendor/bundle/ruby/*/gems/thor-*/
**/vendor/bundle/ruby/*/gems/unf_ext-*/ **/vendor/bundle/ruby/*/gems/unf_ext-*/
**/vendor/bundle/ruby/*/gems/unf-*/ **/vendor/bundle/ruby/*/gems/unf-*/

View File

@ -1,5 +1,12 @@
# frozen_string_literal: true # 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"] 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 std_trap = trap("INT") { exit! 130 } # no backtrace thanks
@ -186,4 +193,9 @@ rescue Exception => e # rubocop:disable Lint/RescueException
exit 1 exit 1
else else
exit 1 if Homebrew.failed? exit 1 if Homebrew.failed?
ensure
if ENV["HOMEBREW_STACKPROF"]
StackProf.stop
StackProf.results("prof/stackprof.dump")
end
end end

View File

@ -10,17 +10,32 @@ module Homebrew
usage_banner <<~EOS usage_banner <<~EOS
`prof` [<command>] `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 EOS
switch "--stackprof",
description: "Use `stackprof` instead of `ruby-prof` (the default)."
end end
end end
def prof def prof
args = prof_args.parse 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 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
end end

View File

@ -1082,7 +1082,10 @@ Apply the bottle commit and publish bottles to Bintray.
### `prof` [*`command`*] ### `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`*] ### `release-notes` [*`options`*] [*`previous_tag`*] [*`end_ref`*]

View File

@ -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\. Use the specified \fIURL\fR as the root of the bottle\'s URL instead of Homebrew\'s default\.
. .
.SS "\fBprof\fR [\fIcommand\fR]" .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]" .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\. 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\.