Module: Pod::PodGenerate::Benchmark::Profiler

Defined in:
lib/cocoapods-podgenerate/benchmark/profiler.rb

Defined Under Namespace

Modules: ProfilerHooks

Class Method Summary collapse

Class Method Details

.enable!Object



19
20
21
# File 'lib/cocoapods-podgenerate/benchmark/profiler.rb', line 19

def enable!
  @enabled = true
end

.enabled?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/cocoapods-podgenerate/benchmark/profiler.rb', line 14

def enabled?
  @enabled ||= ENV['POD_GENERATE_DEBUG'] == '1' ||
               ENV['COCOAPODS_PODGENERATE_DEBUG'] == '1'
end

.installObject



23
24
25
26
# File 'lib/cocoapods-podgenerate/benchmark/profiler.rb', line 23

def install
  return unless enabled?
  Pod::Installer.prepend(ProfilerHooks)
end

.record_phase(name, duration) ⇒ Object



28
29
30
# File 'lib/cocoapods-podgenerate/benchmark/profiler.rb', line 28

def record_phase(name, duration)
  @phase_timings << [name, duration]
end

.reportObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cocoapods-podgenerate/benchmark/profiler.rb', line 36

def report
  return if @phase_timings.empty?
  total = @phase_timings.map(&:last).sum
  Pod::UI.puts "\n[cocoapods-podgenerate] Performance Report:"
  @phase_timings.each do |name, dur|
    pct = total > 0 ? (dur / total * 100) : 0
    Pod::UI.puts "  #{format('%-35s', name)} #{format('%.2f', dur)}s (#{format('%.1f', pct)}%)"
  end
  Pod::UI.puts "  #{'' * 50}"
  Pod::UI.puts "  #{format('%-35s', 'TOTAL')} #{format('%.2f', total)}s"
end

.swap_or_default(phase_name) ⇒ Object



32
33
34
# File 'lib/cocoapods-podgenerate/benchmark/profiler.rb', line 32

def swap_or_default(phase_name)
  # Called from hooks: returns a timing helper or nil
end