Sha256: 1f86e3c4b264a07ef54bb4e39eef6a25cab03663d7b8d64666d971d27e3e565c

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

if fetch(:borg_performance_reports, true)
  # source: https://github.com/PagerDuty/pd-cap-recipes/blob/master/lib/pd-cap-recipes/tasks/performance.rb
  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

  on :exit do
    print_report(start_times, end_times, order) if order.count > 0
  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

3 entries across 3 versions & 1 rubygems

Version Path
borg-rb-0.1.5 cap/initializers/performance.rb
borg-rb-0.1.4 cap/initializers/performance.rb
borg-rb-0.1.0 cap/initializers/performance.rb