Class: SlowestQueriesReport

Inherits:
GenericReport show all
Defined in:
lib/pqa.rb

Instance Method Summary collapse

Methods inherited from GenericReport

#colorize, #pctg_of, #round

Constructor Details

#initialize(log, top = DEFAULT_TOP) ⇒ SlowestQueriesReport

Returns a new instance of SlowestQueriesReport.



1047
1048
1049
1050
# File 'lib/pqa.rb', line 1047

def initialize(log, top=DEFAULT_TOP)
  super(log)
  @top = top
end

Instance Method Details

#applicableObject



1052
1053
1054
# File 'lib/pqa.rb', line 1052

def applicable
  @log.includes_duration
end

#create_reportObject



1079
1080
1081
# File 'lib/pqa.rb', line 1079

def create_report
  (@log.queries.reject{|q| q.duration.nil?}).sort {|a,b| b.duration.to_f <=> a.duration.to_f }.slice(0,@top)
end

#htmlObject



1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/pqa.rb', line 1069

def html
  list = create_report
  rpt = "<h3>#{title}</h3>\n"
  rpt << "<table><tr><th>Rank</th><th>Time</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].duration}</td><td>#{colorize(list[x].text)}</td></tr>\n" 
  }
  rpt << "</table>\n"
end

#textObject



1060
1061
1062
1063
1064
1065
1066
1067
# File 'lib/pqa.rb', line 1060

def text
  list = create_report
  rpt = "######## #{title}\n"
  (list.size < @top ? list.size : @top).times {|x| 
      rpt << "#{"%2.3f" % list[x].duration} seconds: #{list[x].text}\n" 
  }
  rpt
end

#titleObject



1056
1057
1058
# File 'lib/pqa.rb', line 1056

def title  
  "Slowest queries"
end