Class: RuntimeProfiler::TextReport

Inherits:
Object
  • Object
show all
Defined in:
lib/runtime_profiler/text_report.rb

Constant Summary collapse

COUNT_WIDTH =
5
DURATION_WIDTH =
22
TOTAL_RUNTIME_WIDTH =
20
FULL_DETAILS_TEMPLATE =
<<-EOT.strip_heredoc

  \e[1mPROFILING REPORT\e[22m
  ----------------

  \e[1mAPI RUNTIME\e[22m
    Total Runtime     : %s ms
    Database Runtime  : %s ms
    View Runtime      : %s ms

  \e[1mMETHOD CALLS\e[22m
    SLOWEST           : %s (%s ms)
    MOSTLY CALLED     : %s (%s number of calls in %s ms)

  \e[1mSQL CALLS\e[22m
    Total             : %s
    Total Unique      : %s

    \e[1mSLOWEST\e[22m
      Total Runtime   : %s ms
      SQL             : %s
      Source          : %s

    \e[1mMOSTLY CALLED\e[22m
      Total Calls     : %s
      Total Runtime   : %s ms
      SQL             : %s
      Sources         : %s

EOT
METHODS_DETAILS_TEMPLATE =
<<-EOT.strip_heredoc

  \e[1mPROFILING REPORT\e[22m
  ----------------

  \e[1mAPI RUNTIME\e[22m
    Total Runtime     : %s ms
    Database Runtime  : %s ms
    View Runtime      : %s ms

  \e[1mMETHOD CALLS\e[22m
    SLOWEST           : %s (%s ms)
    MOSTLY CALLED     : %s (%s number of calls in %s ms)

EOT
SQLS_DETAILS_TEMPLATE =
<<-EOT.strip_heredoc

  \e[1mPROFILING REPORT\e[22m
  ----------------

  \e[1mAPI RUNTIME\e[22m
    Total Runtime     : %s ms
    Database Runtime  : %s ms
    View Runtime      : %s ms

  \e[1mSQL CALLS\e[22m
    Total             : %s
    Total Unique      : %s

    \e[1mSLOWEST\e[22m
      Total Runtime   : %s ms
      SQL             : %s
      Source          : %s

    \e[1mMOSTLY CALLED\e[22m
      Total Calls     : %s
      Total Runtime   : %s ms
      SQL             : %s
      Sources         : %s

EOT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_file, options) ⇒ TextReport

Returns a new instance of TextReport.



88
89
90
91
# File 'lib/runtime_profiler/text_report.rb', line 88

def initialize(json_file, options)
  self.data = JSON.parse(File.read(json_file))
  self.options = options
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



86
87
88
# File 'lib/runtime_profiler/text_report.rb', line 86

def data
  @data
end

#optionsObject

Returns the value of attribute options.



86
87
88
# File 'lib/runtime_profiler/text_report.rb', line 86

def options
  @options
end

Instance Method Details



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/runtime_profiler/text_report.rb', line 93

def print
  print_summary

  if options.details == 'full'
    if only_methods?
      print_profiled_methods
    elsif only_sqls?
      print_profiled_sql_calls
    else
      print_profiled_methods
      print_profiled_sql_calls
    end
  end
end