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 =
"\n  \\e[1mPROFILING REPORT\\e[22m\n  ----------------\n\n  \\e[1mAPI RUNTIME\\e[22m\n    Total Runtime     : %s ms\n    Database Runtime  : %s ms\n    View Runtime      : %s ms\n\n  \\e[1mMETHOD CALLS\\e[22m\n    SLOWEST           : %s (%s ms)\n    MOSTLY CALLED     : %s (%s number of calls in %s ms)\n\n  \\e[1mSQL CALLS\\e[22m\n    Total             : %s\n    Total Unique      : %s\n\n    \\e[1mSLOWEST\\e[22m\n      Total Runtime   : %s ms\n      SQL             : %s\n      Source          : %s\n\n    \\e[1mMOSTLY CALLED\\e[22m\n      Total Calls     : %s\n      Total Runtime   : %s ms\n      SQL             : %s\n      Sources         : %s\n\n".strip_heredoc
METHODS_DETAILS_TEMPLATE =
"\n  \\e[1mPROFILING REPORT\\e[22m\n  ----------------\n\n  \\e[1mAPI RUNTIME\\e[22m\n    Total Runtime     : %s ms\n    Database Runtime  : %s ms\n    View Runtime      : %s ms\n\n  \\e[1mMETHOD CALLS\\e[22m\n    SLOWEST           : %s (%s ms)\n    MOSTLY CALLED     : %s (%s number of calls in %s ms)\n\n".strip_heredoc
SQLS_DETAILS_TEMPLATE =
"\n  \\e[1mPROFILING REPORT\\e[22m\n  ----------------\n\n  \\e[1mAPI RUNTIME\\e[22m\n    Total Runtime     : %s ms\n    Database Runtime  : %s ms\n    View Runtime      : %s ms\n\n  \\e[1mSQL CALLS\\e[22m\n    Total             : %s\n    Total Unique      : %s\n\n    \\e[1mSLOWEST\\e[22m\n      Total Runtime   : %s ms\n      SQL             : %s\n      Source          : %s\n\n    \\e[1mMOSTLY CALLED\\e[22m\n      Total Calls     : %s\n      Total Runtime   : %s ms\n      SQL             : %s\n      Sources         : %s\n\n".strip_heredoc

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