Class: Perf::ReportFormat
- Inherits:
-
Object
- Object
- Perf::ReportFormat
- Defined in:
- lib/perf/report_format.rb
Overview
Base class for all the standard formatting options for a Perf::Meter. Provies a simple interface to create custom views of the performance report.
Direct Known Subclasses
ReportFormatHtml, ReportFormatListOfMeasures, ReportFormatSimple
Constant Summary collapse
- ACCURACY_DESCRIPTION =
Descrition of the accuracy, as reported by the reports
{Perf::Meter::ACCURACY_UNKNOWN => "?", Perf::Meter::ACCURACY_VERY_POOR => "very poor", Perf::Meter::ACCURACY_POOR => "poor", Perf::Meter::ACCURACY_FAIR => "fair", Perf::Meter::ACCURACY_GOOD => "good", Perf::Meter::ACCURACY_EXCELLENT => "excellent"}
- MAX_ACCURACY_SIZE =
Largest accuracy description length
ACCURACY_DESCRIPTION.values.map{|x| x.length}.max+1
- MIN_TOTAL_TIME =
Minimum possible time
1.0e-10
Instance Method Summary collapse
-
#format(perf, options = {}) ⇒ Object
Format takes a Perf::Meter plus a hash of options and converts it into a header, followed by a series of entries in a hash format that can be easily converted in any other format such as Text, HTML, XML, etc.
-
#format_accuracy(accuracy) ⇒ Object
Format the accuracy See Perf::Meter#accuracy for more information.
-
#format_footer(options) ⇒ Object
Override to format the output of the footer of the data.
-
#format_header(v) ⇒ Object
Override to format the output of the header of the data.
-
#format_measure(v) ⇒ Object
Override to format the output of a single measure.
-
#format_title(what, options) ⇒ Object
Override to format the output of the header of the data.
Instance Method Details
#format(perf, options = {}) ⇒ Object
Format takes a Perf::Meter plus a hash of options and converts it into a header, followed by a series of entries in a hash format that can be easily converted in any other format such as Text, HTML, XML, etc.
You call this method every time that you want to generate a report from a Perf::Meter object.
Options
-
:max_count_len
: Maximum expected length of a block/espresson/method count. -
filter_below_accuracy
: Minimum accuracy to report the measure; floating point value; default=nil (all) -
filter_below_percent
: Minimum percent to report the measure; floating point value; default=nil (all)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/perf/report_format.rb', line 38 def format(perf,={}) perf.adjust_overhead ||={} [:max_count_len] ||= 6 [:filter_below_accuracy] ||= nil [:filter_below_percent] ||= nil rep=[] percents={} max_count=[:max_count_len] max_title=0 keys_in_order=perf.measurements.keys.sort total = Benchmark::Tms.new perf.measurements.each_pair do |what,m| title_len=format_title(what,).length path = what.split("\\") max_title = title_len if title_len>max_title max_count = m.count.to_s.length if m.count.to_s.length>max_count total += perf.adjusted_time(m) if path.size==2 # This calculates the max of the level-1 entries needed for the root entry. end totals=[total.real+total.total] depth=1 keys_in_order.each do |what| m = perf.measurements[what] path = what.split("\\") if path.size-1 != depth if path.size-1 > depth totals.push 0 else totals.pop(depth-(path.size-1)) end depth=path.size-1 end adj=perf.adjusted_time(m) totals[totals.size-1] = adj.real+adj.total #totals[totals.size-1] = MIN_TOTAL_TIME if totals[totals.size-1]<MIN_TOTAL_TIME percents[what]=((adj.real+adj.total)*100.0)/totals[totals.size-2] end # Header rep << format_header(:title => "measure", :max_title => max_title, :percent => "percent", :count => "count", :max_count => max_count, :time => Benchmark::Tms::CAPTION, :accuracy => "accuracy", :max_accuracy => MAX_ACCURACY_SIZE, :options => ) # Root # Split of keys keys_in_order.each do |what| next if [:filter_below_percent] && percents[what]<[:filter_below_percent] m=perf.measurements[what] accuracy = perf.accuracy(m.path) next if [:filter_below_accuracy] && accuracy<[:filter_below_accuracy] title = format_title(what,) rep << format_measure(:title => title, :max_title => max_title, :percent => percents[what]||0.0, :count => m.count, :max_count => max_count, :time => perf.adjusted_time(m), :accuracy => format_accuracy(accuracy), :max_accuracy => MAX_ACCURACY_SIZE, :options => ) end rep << () rep end |
#format_accuracy(accuracy) ⇒ Object
Format the accuracy See Perf::Meter#accuracy for more information
156 157 158 |
# File 'lib/perf/report_format.rb', line 156 def format_accuracy(accuracy) ACCURACY_DESCRIPTION[ACCURACY_DESCRIPTION.keys.sort.find{|a| a>=accuracy}] end |
#format_footer(options) ⇒ Object
Override to format the output of the footer of the data.
See format_measure
149 150 151 |
# File 'lib/perf/report_format.rb', line 149 def () "" end |
#format_header(v) ⇒ Object
Override to format the output of the header of the data.
See format_measure
133 134 135 |
# File 'lib/perf/report_format.rb', line 133 def format_header(v) format_measure(v) end |
#format_measure(v) ⇒ Object
Override to format the output of a single measure. Returns the measure in whatever format the output needs to be.
Options
-
v
: Hash containing the following keys:+title+ : Title - or path - of the block/method/expression (\root\a\b\c\d\something)) +max_title+ : Longest title in the report +percent+ : Percentage of time spent in this measure compared to the containing block. +count+ : How many times the block/method/exression was executed +time+ : Execution time expressed as a Benchmark::Tms value; For titles this is Benchmark::Tms::CAPTION +options+ : Formatting options, as passed by the framework or the user.
125 126 127 |
# File 'lib/perf/report_format.rb', line 125 def format_measure(v) v end |
#format_title(what, options) ⇒ Object
Override to format the output of the header of the data.
See format_measure
141 142 143 |
# File 'lib/perf/report_format.rb', line 141 def format_title(what,) what end |