Sha256: e6f4ca290ad767ad4f6c6e2195d05a077f9a6aa067a08a26bf4d7951440a6fd7

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

Capistrano::Configuration.instance(:must_exist).load do |config|
  start_times = {}
  end_times   = {}
  order       = []

  on :before do
    order << [:start, current_task]
    start_times[current_task] = Time.now
  end

  on :after do
    order << [:end, current_task]
    end_times[current_task] = Time.now
  end

  config.on :exit do
    print_report(start_times, end_times, order)
  end

  def print_report(start_times, end_times, order)
    def l(s)
      logger.info s
    end

    l " Performance Report"
    l "=========================================================="

    indent = 0
    (order + [nil]).each_cons(2) do |payload1, payload2|
      action, task = payload1
      if action == :start
        l "#{".." * indent}#{task.fully_qualified_name}" unless task == payload2.last
        indent += 1
      else
        indent -= 1
        l "#{".." * indent}#{task.fully_qualified_name} #{(end_times[task] - start_times[task]).to_i}s"
      end
    end
    l "=========================================================="
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-ash-1.4.1 lib/ash/performance.rb