Class: ActiveRecordTracer::Report
- Inherits:
-
Object
- Object
- ActiveRecordTracer::Report
- Defined in:
- lib/active_record_tracer/report.rb
Instance Method Summary collapse
-
#initialize(total_runtime, queries_counts, backtrace_queries, loaded_records, loaded_records_backtraces, top:) ⇒ Report
constructor
A new instance of Report.
-
#pretty_print(io = $stdout, to_file: nil, detailed_report: true) ⇒ Object
Output the results of the report.
Constructor Details
#initialize(total_runtime, queries_counts, backtrace_queries, loaded_records, loaded_records_backtraces, top:) ⇒ Report
Returns a new instance of Report.
6 7 8 9 10 11 12 13 |
# File 'lib/active_record_tracer/report.rb', line 6 def initialize(total_runtime, queries_counts, backtrace_queries, loaded_records, loaded_records_backtraces, top:) @total_runtime = total_runtime @queries_counts = queries_counts @backtrace_queries = backtrace_queries @loaded_records = loaded_records @loaded_records_backtraces = loaded_records_backtraces @top = top end |
Instance Method Details
#pretty_print(io = $stdout, to_file: nil, detailed_report: true) ⇒ Object
Output the results of the report
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_record_tracer/report.rb', line 20 def pretty_print(io = $stdout, to_file: nil, detailed_report: true) # Handle the special case that Ruby PrettyPrint expects `pretty_print` # to be a customized pretty printing function for a class. return io.pp_object(self) if defined?(PP) && io.is_a?(PP) io = File.open(to_file, "w") if to_file # Summary stats. io.puts("Total runtime: #{@total_runtime.round(2)}s") io.puts("Total SQL queries: #{@queries_counts.values.sum}") io.puts("Total loaded records: #{total_loaded_records}") io.puts if detailed_report != false # Queries stats. print_queries_by_count(io) if @backtrace_queries.any? print_queries_by_location(io) print_queries_by_file(io) print_queries_by_backtrace(io) end # Loaded records stats. print_records_by_model(io) if @loaded_records_backtraces.any? print_records_by_location(io) print_records_by_file(io) print_records_by_backtrace(io) end end nil ensure io.close if io.is_a?(File) end |