Class: Omnizip::Profiler::ReportGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/profiler/report_generator.rb

Overview

Generates formatted profiling reports with optimization recommendations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ ReportGenerator

Returns a new instance of ReportGenerator.



12
13
14
# File 'lib/omnizip/profiler/report_generator.rb', line 12

def initialize(report)
  @report = report
end

Instance Attribute Details

#reportObject (readonly)

Returns the value of attribute report.



10
11
12
# File 'lib/omnizip/profiler/report_generator.rb', line 10

def report
  @report
end

Instance Method Details

#generate_json_reportObject

Generate a JSON report



35
36
37
# File 'lib/omnizip/profiler/report_generator.rb', line 35

def generate_json_report
  JSON.pretty_generate(report.to_h)
end

#generate_text_reportObject

Generate a human-readable text report



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omnizip/profiler/report_generator.rb', line 17

def generate_text_report
  lines = []
  lines << ("=" * 80)
  lines << "PERFORMANCE PROFILING REPORT"
  lines << ("=" * 80)
  lines << "Profile: #{report.profile_name}"
  lines << "Timestamp: #{report.timestamp}"
  lines << ""

  lines += generate_summary_section
  lines += generate_results_section
  lines += generate_hot_paths_section
  lines += generate_bottlenecks_section

  lines.join("\n")
end

Print report to console



56
57
58
# File 'lib/omnizip/profiler/report_generator.rb', line 56

def print_report
  puts generate_text_report
end

#save_to_file(filename, format: :text) ⇒ Object

Save report to file



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/omnizip/profiler/report_generator.rb', line 40

def save_to_file(filename, format: :text)
  content = case format
            when :text then generate_text_report
            when :json then generate_json_report
            else raise ArgumentError, "Unknown format: #{format}"
            end

  # Create parent directories if they don't exist
  dir = File.dirname(filename)
  FileUtils.mkdir_p(dir)

  File.write(filename, content)
  puts "Report saved to #{filename}"
end