Class: FocalPoint
Instance Attribute Summary collapse
-
#timer ⇒ Object
Returns the value of attribute timer.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(target) ⇒ FocalPoint
constructor
A new instance of FocalPoint.
- #source ⇒ Object
Methods included from Multiton
Constructor Details
#initialize(target) ⇒ FocalPoint
Returns a new instance of FocalPoint.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/focal_point.rb', line 16 def initialize(target) @target = String(target) @timer = Hitimes::TimedMetric.new(@target) if @target =~ /^([^#.]+)(#|\.)(.*)$/ @method, @scope = case $2 when '#' ## we're instrumenting an instance method [$3, eval($1)] when '.' ## we're instrumenting a module method [$3, (class << eval($1); self; end)] end else $stdout.puts "FocalPoint::Error: Not sure how to instrument #{@target}" end unless @scope.instance_methods.include?(@method) && false # did you mean?? end @scope.module_eval(source) end |
Instance Attribute Details
#timer ⇒ Object
Returns the value of attribute timer.
10 11 12 |
# File 'lib/focal_point.rb', line 10 def timer @timer end |
Class Method Details
.[](target) ⇒ Object
12 13 14 |
# File 'lib/focal_point.rb', line 12 def self.[] target new(target) end |
.print_timers ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/focal_point.rb', line 50 def self.print_timers timers = [] ObjectSpace.each_object(FocalPoint) { |fp| timers << fp.timer } timers.compact.sort_by(&:sum).each do |timer| puts '-'*80 pp timer.to_hash puts end end |
Instance Method Details
#source ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/focal_point.rb', line 38 def source <<-CODE alias :real_#{@method} :#{@method} def #{@method}(*args, &block) FocalPoint[#{@target.inspect}].timer.measure do real_#{@method}(*args, &block) end end CODE end |