Method: ANTLR3::Profile::Profile#generate_report

Defined in:
lib/antlr3/profile.rb

#generate_reportObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/antlr3/profile.rb', line 129

def generate_report
  report = '+' << '-' * 78 << "+\n"
  report << '| ' << "ANTLR Rule Profile".center( 76 ) << " |\n"
  report << '+' << '-' * 78 << "+\n"
  report << "| Generated at #{ Time.now }".ljust( 78 ) << " |\n"
  report << "| Profiled #{ parser_class.name }##{ top_rule }".ljust( 78 ) << " |\n"
  report << "| Rule source generated from grammar file #{ grammar_file }".ljust( 78 ) << " |\n"
  report << '+' << '-' * 78 << "+\n"
  
  report << '| ' << "Rule Invocations".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Total Invocations", rule_invocations ]
  report << "| %-66s | %7i |\n" % [ "``Guessing'' Invocations", guessing_rule_invocations ]
  report << "| %-66s | %7i |\n" % [ "Deepest Level of Invocation", rule_invocation_depth ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  report << '| ' << "Execution Events".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Semantic Predicates Evaluated", semantic_predicates ]
  report << "| %-66s | %7i |\n" % [ "Syntactic Predicates Evaluated", syntactic_predicates ]
  report << "| %-66s | %7i |\n" % [ "Errors Reported", reported_errors ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  report << '| ' << "Token and Character Data".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Tokens Consumed", tokens ]
  report << "| %-66s | %7i |\n" % [ "Hidden Tokens Consumed", hidden_tokens ]
  report << "| %-66s | %7i |\n" % [ "Characters Matched", characters_matched ]
  report << "| %-66s | %7i |\n" % [ "Hidden Characters Matched", hidden_characters_matched ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  report << '| ' << "Memoization".center( 76 ) << " |\n"
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  report << "| %-66s | %7i |\n" % [ "Cache Entries", memoization_cache_entries ]
  report << "| %-66s | %7i |\n" % [ "Cache Hits", memoization_cache_hits ]
  report << "| %-66s | %7i |\n" % [ "Cache Misses", memoization_cache_misses ]
  report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  
  [ 
    [ 'Fixed Lookahead (k)', fixed_looks ],
    [ 'Arbitrary Lookahead (k)', cyclic_looks ],
    [ 'Backtracking (Syntactic Predicate)', syntactic_predicate_looks ]
  ].each do |name, set|
    mean, stdev = '%4.2f' % set.average, '%4.2f' % set.standard_deviation
    report << '| ' << "#{ name } Decisions".center( 76 ) << " |\n"
    report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
    report << "| %-66s | %7i |\n" % [ "Count", set.length ]
    report << "| %-66s | %7i |\n" % [ "Minimum k", set.min ]
    report << "| %-66s | %7i |\n" % [ "Maximum k", set.max ]
    report << "| %-66s | %7s |\n" % [ "Average k", mean ]
    report << "| %-66s | %7s |\n" % [ "Standard Deviation of k", stdev ]
    report << '+' << '-' * 68 << '+' << '-' * 9 << "+\n"
  end
  return( report )
end