Skip to content

Commit

Permalink
dev-cmd/prof: add vernier support.
Browse files Browse the repository at this point in the history
It's the newest great profiler for Ruby.
  • Loading branch information
MikeMcQuaid committed May 17, 2024
1 parent e97864a commit fd7df63
Show file tree
Hide file tree
Showing 6 changed files with 590 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
**/vendor/bundle/ruby/*/gems/unparser-*/
**/vendor/bundle/ruby/*/gems/uri_template-*/
**/vendor/bundle/ruby/*/gems/vernier-*/
**/vendor/bundle/ruby/*/gems/webrobots-*/
**/vendor/bundle/ruby/*/gems/yard-*/
**/vendor/bundle/ruby/*/gems/yard-sorbet-*/
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ end
group :prof, optional: true do
gem "ruby-prof", require: false
gem "stackprof", require: false
gem "vernier", require: false
end
group :pry, optional: true do
gem "pry", require: false
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ GEM
unf_ext
unf_ext (0.0.9.1)
unicode-display_width (2.5.0)
vernier (1.0.1)
warning (1.3.0)
yard (0.9.36)
yard-sorbet (0.8.1)
Expand Down Expand Up @@ -201,6 +202,7 @@ DEPENDENCIES
spoom
stackprof
tapioca
vernier
warning
yard
yard-sorbet
Expand Down
15 changes: 13 additions & 2 deletions Library/Homebrew/dev-cmd/prof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Prof < AbstractCommand
EOS
switch "--stackprof",
description: "Use `stackprof` instead of `ruby-prof` (the default)."
switch "--vernier",
description: "Use `vernier` instead of `ruby-prof` (the default)."

named_args :command, min: 1
end
Expand Down Expand Up @@ -39,17 +41,26 @@ def run
Homebrew.setup_gem_environment!

if args.stackprof?
# odeprecated. vernier is better in every way
with_env HOMEBREW_STACKPROF: "1" do
system(*HOMEBREW_RUBY_EXEC_ARGS, brew_rb, *args.named)
end
output_filename = "prof/d3-flamegraph.html"
safe_system "stackprof --d3-flamegraph prof/stackprof.dump > #{output_filename}"
exec_browser output_filename
elsif args.vernier?
output_filename = "prof/vernier.json"
Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid
safe_system "vernier", "run", "--output=#{output_filename}", "--allocation_sample_rate=500", "--",

Check warning on line 54 in Library/Homebrew/dev-cmd/prof.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/prof.rb#L54

Added line #L54 was not covered by tests
RUBY_PATH, brew_rb, *args.named
ohai "Profiling complete!"
puts "Upload the results from #{output_filename} to:"
puts " #{Formatter.url("https://vernier.prof")}"

Check warning on line 58 in Library/Homebrew/dev-cmd/prof.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/prof.rb#L56-L58

Added lines #L56 - L58 were not covered by tests
else
output_filename = "prof/call_stack.html"
safe_system "ruby-prof", "--printer=call_stack", "--file=#{output_filename}", brew_rb, "--", *args.named
exec_browser output_filename
end

exec_browser output_filename
rescue OptionParser::InvalidOption => e
ofail e

Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/prof.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd7df63

Please sign in to comment.