Class Rcov::CallSiteAnalyzer
In: lib/rcov.rb
Parent: DifferentialAnalyzer

A CallSiteAnalyzer can be used to obtain information about:

  • where a method is defined ("defsite")
  • where a method was called from ("callsite")

Example

example.rb:

 class X
   def f1; f2 end
   def f2; 1 + 1 end
   def f3; f1 end
 end

 analyzer = Rcov::CallSiteAnalyzer.new
 x = X.new
 analyzer.run_hooked do
   x.f1
 end
 # ....

 analyzer.run_hooked do
   x.f3
   # the information generated in this run is aggregated
   # to the previously recorded one
 end

 analyzer.analyzed_classes        # => ["X", ... ]
 analyzer.methods_for_class("X")  # => ["f1", "f2", "f3"]
 analyzer.defsite("X#f1")         # => DefSite object
 analyzer.callsites("X#f2")       # => hash with CallSite => count
                                  #    associations
 defsite = analyzer.defsite("X#f1")
 defsite.file                     # => "example.rb"
 defsite.line                     # => 2

You can have several CallSiteAnalyzer objects at a time, and it is possible to nest the run_hooked / install_hook/remove_hook blocks: each analyzer will manage its data separately. Note however that no special provision is taken to ignore code executed "inside" the CallSiteAnalyzer class.

defsite information is only available for methods that were called under the inspection of the CallSiteAnalyzer, i.o.w. you will only have defsite information for those methods for which callsite information is available.

Methods

Classes and Modules

Class Rcov::CallSiteAnalyzer::CallSite
Class Rcov::CallSiteAnalyzer::DefSite

Public Class methods

Public Instance methods

Classes whose methods have been called. Returns an array of strings describing the classes (just klass.to_s for each of them). Singleton classes are rendered as:

  #<Class:MyNamespace::MyClass>
analyzed_methods(classname)

Alias for methods_for_class

Returns a hash with CallSite => call count associations or nil Can be called in two ways:

  analyzer.callsites("Foo#f1")         # instance method
  analyzer.callsites("Foo.g1")         # singleton method of the class

or

  analyzer.callsites("Foo", "f1")
  analyzer.callsites("#<class:Foo>", "g1")

Returns a DefSite object corresponding to the given method Can be called in two ways:

  analyzer.defsite("Foo#f1")         # instance method
  analyzer.defsite("Foo.g1")         # singleton method of the class

or

  analyzer.defsite("Foo", "f1")
  analyzer.defsite("#<class:Foo>", "g1")

Methods that were called for the given class. See analyzed_classes for the notation used for singleton classes. Returns an array of strings or nil

[Validate]