class Profiler::FlatPrinter

Private Instance Methods

column_lengths() click to toggle source
# File lib/profiler/printers/flat_printer.rb, line 52
def column_lengths
  @column_lengths ||= get_column_lengths
end
columns_to_line(columns) click to toggle source
# File lib/profiler/printers/flat_printer.rb, line 45
def columns_to_line(columns)
  columns = columns.map.with_index do |column, index|
    column.to_s.ljust(column_lengths[index])
  end
  columns.join(' ')
end
get_body() click to toggle source
# File lib/profiler/printers/flat_printer.rb, line 26
def get_body
  column_lengths = get_column_lengths
  paths_durations = result.paths_durations
  paths_durations = paths_durations.sort_by(&:last).reverse
  paths_durations.map do |path, duration|
    count = result.paths_counts[path]
    columns = [
      duration.round(5),
      count,
      path_to_displayed_path(path)
    ]
    columns_to_line(columns)
  end
end
get_column_lengths() click to toggle source
# File lib/profiler/printers/flat_printer.rb, line 56
def get_column_lengths
  [
    9,
    5,
    get_longest_path_length + 1
  ]
end
get_header() click to toggle source
# File lib/profiler/printers/flat_printer.rb, line 18
def get_header
  columns_to_line([
    'Time',
    'Calls',
    'Path'
  ])
end
get_longest_path_length() click to toggle source
# File lib/profiler/printers/flat_printer.rb, line 64
def get_longest_path_length
  result.paths_durations.keys.map { |path| path_to_displayed_path(path).length }.sort.last
end
path_to_displayed_path(path) click to toggle source

For example, convert ‘results_html_haml___3582891738431186295_70358606312040’ to ‘results_html_haml’

# File lib/profiler/printers/flat_printer.rb, line 69
def path_to_displayed_path(path)
  path.gsub(/___[\d_]+/, '')
end
print_result(options) click to toggle source
result_to_string() click to toggle source
# File lib/profiler/printers/flat_printer.rb, line 10
def result_to_string
  lines = []
  lines << get_header
  lines += get_body
  lines << get_footer
  lines.join("\n")
end