Class: ReportParser

Inherits:
Object
  • Object
show all
Defined in:
lib/report/report_parser.rb

Instance Method Summary collapse

Instance Method Details

#looks_ok_on_quick_peek?(content) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
# File 'lib/report/report_parser.rb', line 103

def looks_ok_on_quick_peek?(content)
  return false if content.nil? || content.empty? 
  return false if (content =~ /No requests to analyze/)
  return true
end

#parse(report_name, content) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/report/report_parser.rb', line 56

def parse(report_name, content)
  report = Report.new
  report.name=report_name
  #TODO: parse report name as a time
  report.started_at=report_name#Time.parse(report_name)
  #ALL REQUESTS:                                   11830   0.085   0.052   0.001   1.053
  content =~ /ALL REQUESTS:\s*([0-9]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)/
  report.summary.count=Integer($1)
  report.summary.avg_time=Float($2)
  report.summary.std_dev=Float($3)
  report.summary.min_time=Float($4)
  report.summary.max_time=Float($5)

  content =~ /\nALL REQUESTS:.*?\n\n(.*)\n\nSlowest Request Times/m
  
  request_lines_block = $1
  throw "No requests found" if request_lines_block.nil?
  request_lines_block.split(/\n/).each_with_index do |line, i|
    request = parse_request(line)
    request.fixup_controller_name!
    if request.nil? || request.controller.nil?
      puts "WARN: unparseable request line: #{line}, index #{i}"
      next
    end
    report.requests << request
  end
  return report
end

#parse_request(request_line) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/report/report_parser.rb', line 85

def parse_request(request_line)
  r = Request.new
  #Examples:
  #FooController#update.PUT.xml:         3557    0.144   0.037   0.059   0.712
  #FooController#show.GET:               11707   0.107   0.063   0.015   1.075
  request_line =~ /([a-zA-Z0-9:]+)#([^\.: ]+)\.?([a-zA-Z]+)?\.?([a-zA-Z]+)?:\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/
  r.controller = $1
  r.action = $2
  r.verb = $3.upcase unless $3.nil?
  r.format = $4.downcase unless $4.nil?
  r.count = $5.to_i
  r.avg_time = $6.to_f
  r.std_dev = $7.to_f
  r.min_time = $8.to_f
  r.max_time = $9.to_f
  r
end