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:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'utils/phase_timings.rb', line 102

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.



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
# File 'utils/phase_timings.rb', line 50

def self.install!
  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
  instrument(Homebrew::Install.singleton_class, :formula_installers, "planning") if defined?(Homebrew::Install)
  if defined?(FormulaInstaller)
    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")
  end
  instrument(Homebrew::DownloadQueue, :enqueue, "download_enqueue") if defined?(Homebrew::DownloadQueue)
  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)
  return unless defined?(Cleanup)

  instrument(Cleanup.singleton_class, :install_formula_clean!, "cleanup")
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))


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

def self.measure(phase, detail: nil, &_block)
  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:



23
24
25
26
27
28
29
# File 'utils/phase_timings.rb', line 23

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.



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'utils/phase_timings.rb', line 87

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

  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