Class: QueriesThatTookUpTheMostTimeReport
Instance Method Summary
collapse
#colorize, #pctg_of, #round
Constructor Details
Returns a new instance of QueriesThatTookUpTheMostTimeReport.
1002
1003
1004
1005
|
# File 'lib/pqa.rb', line 1002
def initialize(log, top=DEFAULT_TOP)
super(log)
@top = top
end
|
Instance Method Details
#applicable ⇒ Object
1011
1012
1013
|
# File 'lib/pqa.rb', line 1011
def applicable
@log.includes_duration
end
|
#create_report ⇒ Object
1034
1035
1036
1037
1038
1039
1040
1041
1042
|
# File 'lib/pqa.rb', line 1034
def create_report
h = {}
@log.queries.each {|q|
next if q.duration.nil?
h[q.text] = LittleWrapper.new(q) if !h.has_key?(q.text)
h[q.text].add(q)
}
h.sort {|a,b| b[1].total_duration <=> a[1].total_duration }
end
|
#html ⇒ Object
1015
1016
1017
1018
1019
1020
1021
1022
1023
|
# File 'lib/pqa.rb', line 1015
def html
list = create_report
rpt = "<h3>#{title}</h3>\n"
rpt << "<table><tr><th>Rank</th><th>Total time (seconds)</th><th>Times executed</th><th>Query text</th>\n"
(list.size < @top ? list.size : @top).times {|x|
rpt << "<tr><td>#{x+1}</td><td>#{"%2.3f" % list[x][1].total_duration}</td><td align=right>#{list[x][1].count}</td><td>#{colorize(list[x][0])}</td></tr>\n"
}
rpt << "</table>\n"
end
|
#text ⇒ Object
1025
1026
1027
1028
1029
1030
1031
1032
|
# File 'lib/pqa.rb', line 1025
def text
list = create_report
rpt = "######## #{title}\n"
(list.size < @top ? list.size : @top).times {|x|
rpt << "#{"%2.3f" % list[x][1].total_duration} seconds: #{list[x][0]}\n"
}
rpt
end
|
#title ⇒ Object
1007
1008
1009
|
# File 'lib/pqa.rb', line 1007
def title
"Queries that took up the most time"
end
|