# # Copyright (c) 2012 Lorenzo Pasqualis - DreamBox Learning, Inc # https://github.com/lpasqualis/rubyperf # require 'rubyperf' require 'cgi' module Perf class ReportFormatHtml < ReportFormat PERCENT_FORMAT = "%.2f" # default for :time_format TIME_FORMAT = "%.7f" # default for :percent_format COUNT_FORMAT = "%d" # default for :count_format INDENT = " "*3 # default for :indent_string def initialize super @line=0 end # Formats the report in HTML format and returns an array of strings containing the report. # # ==== Attributes # # * +perf+ - The Perf::Meter object to report # * +options+ - A hash of options as follows: # :time_format => sprintf format of the time (see TIME_FORMAT for default) # :percent_foramt => sprintf format of the percent (see PERCENT_FORMAT for default) # :count_format => sprintf format of the count (see COUNT_FORMAT for default) # :indent_string => what string to use to indent the path (see INDENT for default) # # ==== Example # # m=Perf::Meter.new # m.measure(:something) { something } # m.report_html() def format(perf,options={}) options||={} @time_format = options[:time_format] || TIME_FORMAT @percent_format = options[:percent_format] || PERCENT_FORMAT @count_format = options[:count_format] || COUNT_FORMAT @indent_string = options[:indent_string] || INDENT super end # Formats the header def format_header(v) "
#{v[:title]} | " \ "% | " \ "count | " \ "user | " \ "system | " \ "total | " \ "real | " \ "
---|---|---|---|---|---|---|
#{v[:title]} | " \ "#{percent} | " \ "#{@count_format % v[:count]} | " \ "#{@time_format % v[:time].utime} | " \ "#{@time_format % v[:time].stime} | " \ "#{@time_format % v[:time].total} | " \ "#{@time_format % v[:time].real} | " \ "