Класс: Homebrew::DevCmd::Prof Закрытый
- Наследует:
- AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::Prof
- Определено в:
- dev-cmd/prof.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/prof.rbi
Этот класс является частью закрытого API. Этот класс можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности не следует использовать этот класс, поскольку он может быть удалён или изменён без предупреждения.
Определено в пространстве имён
Классы: Args
Краткое описание методов экземпляра свернуть
- #args ⇒ Homebrew::DevCmd::Prof::Args закрытый
- #run ⇒ void закрытый
Методы, унаследованные от AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Методы, подключённые из Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_upgradable, #pretty_warning
Подробное описание конструкторов
Этот класс наследует конструктор от Homebrew::AbstractCommand
Подробное описание методов экземпляра
#args ⇒ Homebrew::DevCmd::Prof::Args
Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности не следует использовать этот метод, поскольку он может быть удалён или изменён без предупреждения.
10 | # File 'sorbet/rbi/dsl/homebrew/dev_cmd/prof.rbi', line 10 def args; end |
#run ⇒ void
Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности не следует использовать этот метод, поскольку он может быть удалён или изменён без предупреждения.
Этот метод возвращает неопределённое значение.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | # File 'dev-cmd/prof.rb', line 23 def run Homebrew.install_bundler_gems!(groups: ["prof"], setup_path: false) brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path FileUtils.mkdir_p "prof" cmd = T.must(args.named.first) case Commands.path(cmd)&.extname when ".rb" # expected file extension so we do nothing when ".sh" raise UsageError, <<~EOS `#{cmd}` is a Bash command! Try `hyperfine` for benchmarking instead. EOS else raise UsageError, "`#{cmd}` is an unknown command!" end Homebrew.setup_gem_environment! if args.stackprof? 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}" # `brew prof` is often run from tests or scripts. Only open the HTML # report automatically when the user is attached to a terminal. exec_browser output_filename if $stdout.tty? elsif args.vernier? output_filename = "prof/vernier.json" Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid # Avoid `vernier run`: it injects `vernier/autorun` through `RUBYOPT`, # which child Ruby processes inherit. Profiling only this Ruby process # keeps nested `brew` commands from trying to write the same profile. # # `HOMEBREW_SPAWN_SYSTEM` is intentionally scoped to this profiled # process. It lets selected process helpers avoid manual fork paths # that can inherit Vernier's active native collector state. safe_system({ "HOMEBREW_SPAWN_SYSTEM" => "1", "VERNIER_ALLOCATION_INTERVAL" => "500", "VERNIER_OUTPUT" => output_filename }, RUBY_PATH, "-I", (Pathname(Gem::Specification.find_by_name("vernier").full_gem_path)/"lib").to_s, "-r", "vernier/autorun", "-r", (HOMEBREW_LIBRARY_PATH/"prof/vernier_fork_guard").to_s, brew_rb, *args.named) ohai "Profiling complete!" puts "Upload the results from #{output_filename} to:" puts "#{Formatter.url("https://vernier.prof")}" else output_filename = "prof/call_stack.html" safe_system "ruby-prof", "--printer=call_stack", "--file=#{output_filename}", brew_rb, "--", *args.named # Match the stackprof behaviour above: generating the file is useful # in non-interactive runs but launching a browser is not. exec_browser output_filename if $stdout.tty? end rescue OptionParser::InvalidOption => e ofail e # The invalid option could have been meant for the subcommand. # Suggest `brew prof list -r` -> `brew prof -- list -r` args = ARGV - ["--"] puts "Try `brew prof -- #{args.join("")}` instead." end |
© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/Homebrew/DevCmd/Prof.html