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

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

Defined Under Namespace

Modules: ProfilerHooks, ProfilerSubSteps

Class Method Summary collapse

Class Method Details

.enable!Object



21
22
23
# File 'lib/cocoapods-podgenerate/benchmark/profiler.rb', line 21

def enable!
  @enabled_override = true
end

.enabled?Boolean

Returns:

  • (Boolean)


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

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

.installObject



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

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

.record_phase(name, duration) ⇒ Object



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

def record_phase(name, duration)
  @timings_mutex.synchronize { @phase_timings << [name, duration] }
end

.reportObject



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

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"
  @phase_timings.clear
end