Module: Homebrew::PhaseTimings Private

Defined in:
utils/phase_timings.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Constant Summary collapse

Event =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.type_alias { T::Hash[String, T.any(Integer, String)] }

Class Method Summary collapse

Class Method Details

.detail_for(receiver, args) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'utils/phase_timings.rb', line 113

def self.detail_for(receiver, args)
  object = if receiver.respond_to?(:formula)
    receiver.public_method(:formula).call
  elsif receiver.respond_to?(:url)
    receiver.public_method(:url).call
  else
    args.first
  end

  if object.respond_to?(:full_name)
    object.full_name.to_s
  elsif object.respond_to?(:download_queue_name)
    object.download_queue_name.to_s
  elsif object.is_a?(String) || object.is_a?(Symbol) || object.is_a?(Pathname)
    object.to_s
  end
end

.install!void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



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
86
87
88
89
90
91
92
93
# File 'utils/phase_timings.rb', line 52

def self.install!
  # A class can only be instrumented once it is loaded, so load the install
  # path here rather than reporting zero for phases a command loads later.
  measure("instrumentation") do
    require "cleanup"
    require "download_queue"
    require "formula_installer"
  end

  instrument(Homebrew::CLI::NamedArgs, :to_formulae_and_casks, "formula_resolution") if defined?(Homebrew::CLI)
  instrument(Formulary.singleton_class, :factory, "formula_inflation") if defined?(Formulary)
  instrument(Homebrew::API.singleton_class, :fetch_api_files!, "api_metadata_load") if defined?(Homebrew::API)
  if defined?(Homebrew::API::Internal)
    instrument(Homebrew::API::Internal.singleton_class, :formula_struct, "api_metadata_load")
  end
  if defined?(Homebrew::Install)
    instrument(Homebrew::Install.singleton_class, :formula_installers, "planning")
    instrument(Homebrew::Install.singleton_class, :perform_preinstall_checks_once, "preinstall_checks")
  end
  instrument(FormulaInstaller, :prelude, "planning")
  instrument(FormulaInstaller, :compute_dependencies, "dependency_resolution")
  instrument(FormulaInstaller, :pour, "pour")
  instrument(FormulaInstaller, :link, "link")
  instrument(FormulaInstaller, :clean, "cleanup")
  instrument(FormulaInstaller, :post_install, "postinstall")
  instrument(Homebrew::DownloadQueue, :enqueue, "download_enqueue")
  instrument(Cleanup.singleton_class, :install_formula_clean!, "cleanup")
  if defined?(Utils::Curl)
    instrument(Utils::Curl, :curl_headers, "curl_headers")
    instrument(Utils::Curl.singleton_class, :curl_headers, "curl_headers")
    instrument(Utils::Curl, :curl_download, "curl_body")
    instrument(Utils::Curl.singleton_class, :curl_download, "curl_body")
  end
  instrument(Downloadable::VerificationCache, :verify, "checksum") if defined?(Downloadable::VerificationCache)
  if defined?(AbstractFileDownloadStrategy)
    instrument(AbstractFileDownloadStrategy, :create_symlink_to_cached_download, "symlink")
  end
  instrument(AbstractDownloadStrategy, :stage, "extraction") if defined?(AbstractDownloadStrategy)
  instrument(Bottle, :stage_from_download_queue, "extraction") if defined?(Bottle)
  instrument(Cask::Download, :stage_from_download_queue, "extraction") if defined?(Cask::Download)
  instrument(Tab, :write, "tab_write") if defined?(Tab)
end

.measure(phase, detail: nil, &_block) ⇒ T.type_parameter(:U)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • phase (String)
  • detail (String, nil) (defaults to: nil)
  • _block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U))


38
39
40
41
42
43
44
45
46
47
48
49
# File 'utils/phase_timings.rb', line 38

def self.measure(phase, detail: nil, &_block)
  # Recording is opt-in via `$HOMEBREW_PHASE_TIMINGS`, so callers on the
  # startup path can measure unconditionally without paying for it.
  return yield if @output_path.nil?

  started_at = monotonic_time
  begin
    yield
  ensure
    record(phase, started_at, monotonic_time, detail:)
  end
end

.start!(output_path:, started_at:, command:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



21
22
23
24
25
26
27
# File 'utils/phase_timings.rb', line 21

def self.start!(output_path:, started_at:, command:)
  @output_path = Pathname(output_path)
  @started_at = started_at
  @command = command
  @mutex.synchronize { @events = [] }
  record("startup", started_at, monotonic_time)
end

.write!void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'utils/phase_timings.rb', line 96

def self.write!
  output_path = @output_path
  return if output_path.nil?

  require "json"

  events = @mutex.synchronize { @events.sort_by { |event| event.fetch("start") } }
  output_path.dirname.mkpath
  output_path.write("#{JSON.pretty_generate({
    "schema_version" => 1,
    "time_unit"      => "microseconds",
    "command"        => @command,
    "events"         => events,
  })}\n")
end