Parent

Rcov::DifferentialAnalyzer

Public Class Methods

new(install_hook_meth, remove_hook_meth, reset_meth) click to toggle source
    # File lib/rcov/differential_analyzer.rb, line 6
 6:     def initialize(install_hook_meth, remove_hook_meth, reset_meth)
 7:       @cache_state = :wait
 8:       @start_raw_data = data_default
 9:       @end_raw_data = data_default
10:       @aggregated_data = data_default
11:       @install_hook_meth = install_hook_meth
12:       @remove_hook_meth= remove_hook_meth
13:       @reset_meth= reset_meth
14:     end

Protected Class Methods

hook_level() click to toggle source
    # File lib/rcov/differential_analyzer.rb, line 80
80:     def self.hook_level
81:       raise "must be implemented by the subclass"
82:     end

Public Instance Methods

install_hook() click to toggle source

Start monitoring execution to gather information. Such data will be collected until # is called.

Use # instead if possible.

    # File lib/rcov/differential_analyzer.rb, line 29
29:     def install_hook
30:       @start_raw_data = raw_data_absolute
31:       Rcov::RCOV__.send(@install_hook_meth)
32:       @cache_state = :hooked
33:       @@mutex.synchronize{ self.class.hook_level += 1 }
34:     end
remove_hook() click to toggle source

Stop collecting information. # will also stop collecting info if it is run inside a # block.

    # File lib/rcov/differential_analyzer.rb, line 39
39:     def remove_hook
40:       @@mutex.synchronize do 
41:         self.class.hook_level -= 1
42:         Rcov::RCOV__.send(@remove_hook_meth) if self.class.hook_level == 0
43:       end
44:       @end_raw_data = raw_data_absolute
45:       @cache_state = :done
46:       # force computation of the stats for the traced code in this run;
47:       # we cannot simply let it be if self.class.hook_level == 0 because 
48:       # some other analyzer could install a hook, causing the raw_data_absolute
49:       # to change again.
50:       # TODO: lazy computation of raw_data_relative, only when the hook gets
51:       # activated again.
52:       raw_data_relative
53:     end
reset() click to toggle source

Remove the data collected so far. Further collection will start from scratch.

    # File lib/rcov/differential_analyzer.rb, line 57
57:     def reset
58:       @@mutex.synchronize do
59:         if self.class.hook_level == 0
60:           # Unfortunately there's no way to report this as covered with rcov:
61:           # if we run the tests under rcov self.class.hook_level will be >= 1 !
62:           # It is however executed when we run the tests normally.
63:           Rcov::RCOV__.send(@reset_meth)
64:           @start_raw_data = data_default
65:           @end_raw_data = data_default
66:         else
67:           @start_raw_data = @end_raw_data = raw_data_absolute
68:         end
69:         @raw_data_relative = data_default
70:         @aggregated_data = data_default
71:       end
72:     end
run_hooked() click to toggle source

Execute the code in the given block, monitoring it in order to gather information about which code was executed.

    # File lib/rcov/differential_analyzer.rb, line 18
18:     def run_hooked
19:       install_hook
20:       yield
21:     ensure
22:       remove_hook
23:     end

Protected Instance Methods

aggregate_data(aggregated_data, delta) click to toggle source
    # File lib/rcov/differential_analyzer.rb, line 88
88:     def aggregate_data(aggregated_data, delta)
89:       raise "must be implemented by the subclass"
90:     end
compute_raw_data_difference(first, last) click to toggle source
    # File lib/rcov/differential_analyzer.rb, line 92
92:     def compute_raw_data_difference(first, last)
93:       raise "must be implemented by the subclass"
94:     end
data_default() click to toggle source
    # File lib/rcov/differential_analyzer.rb, line 76
76:     def data_default
77:       raise "must be implemented by the subclass"
78:     end
raw_data_absolute() click to toggle source
    # File lib/rcov/differential_analyzer.rb, line 84
84:     def raw_data_absolute
85:       raise "must be implemented by the subclass"
86:     end

Private Instance Methods

raw_data_relative() click to toggle source
     # File lib/rcov/differential_analyzer.rb, line 98
 98:     def raw_data_relative
 99:       case @cache_state
100:       when :wait
101:         return @aggregated_data
102:       when :hooked
103:         new_start = raw_data_absolute
104:         new_diff = compute_raw_data_difference(@start_raw_data, new_start)
105:         @start_raw_data = new_start
106:       when :done
107:         @cache_state = :wait
108:         new_diff = compute_raw_data_difference(@start_raw_data, 
109:                                                @end_raw_data)
110:       end
111: 
112:       aggregate_data(@aggregated_data, new_diff)
113:       @aggregated_data
114:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.