Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 42 lines (35 sloc) 1.053 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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
Something went wrong with that request. Please try again.