Show stats for generic mutator below config runner stats

This will help us to track down the most important generically handled
nodes.
This commit is contained in:
Markus Schirp 2013-07-21 20:32:07 +02:00
parent 6981920931
commit 3a579a81c5
3 changed files with 81 additions and 1 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 16
total_score: 704
total_score: 719

View file

@ -47,6 +47,7 @@ NestedIterators:
exclude:
- Mutant#self.singleton_subclass_instance
- Mutant::Mutator::Util::Array::Element#dispatch
- Mutant::Reporter::CLI::Printer::Config::Runner#generic_stats
- Mutant::CLI#parse
max_allowed_nesting: 1
ignore_iterators: []

View file

@ -45,6 +45,7 @@ module Mutant
info 'Overhead: %0.2f%%', overhead
status 'Coverage: %0.2f%%', coverage
status 'Alive: %s', amount_alive
print_generic_stats
self
end
@ -60,6 +61,84 @@ module Mutant
object.subjects
end
# Walker for all ast nodes
class Walker
# Run walkter
#
# @param [Parser::AST::Node] root
#
# @return [self]
#
# @api private
#
def self.run(root, &block)
new(root, block)
self
end
private_class_method :new
# Initialize and run walker
#
# @param [Parser::AST::Node] root
# @param [#call(node)] block
#
# @return [undefined]
#
# @api private
#
def initialize(root, block)
@root, @block = root, block
dispatch(root)
end
private
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch(node)
@block.call(node)
node.children.each do |child|
next unless child.kind_of?(Parser::AST::Node)
dispatch(child)
end
end
end
# Print generic stats
#
# @return [undefined]
#
# @api private
#
def print_generic_stats
stats = generic_stats.to_a.sort_by(&:last)
info('Nodes handled by genric mutator (type:occurances):')
stats.reverse_each do |type, amount|
info('%-10s: %d', type, amount)
end
end
# Return stats for nodes handled by generic mutator
#
# @return [Hash<Symbo, Fixnum>]
#
# @api private
#
def generic_stats
object.subjects.each_with_object(Hash.new(0)) do |runner, stats|
Walker.run(runner.subject.node) do |node|
next unless Mutator::Registry.lookup(node) == Mutator::Node::Generic
stats[node.type] += 1
end
end
end
# Return amount of subjects
#
# @return [Fixnum]